Skip to content

Commit

Permalink
fix: prevent stripe.js from loading automatically (#6138)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Dec 18, 2024
1 parent b54521b commit 349a67d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-trees-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hive': patch
---

Prevent stripe.js from loading automatically
16 changes: 12 additions & 4 deletions packages/web/app/src/lib/billing/stripe.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { FC, ReactNode, Suspense, useState } from 'react';
import { env } from '@/env/frontend';
import { Elements as ElementsProvider } from '@stripe/react-stripe-js';
import { loadStripe } from '@stripe/stripe-js';
// Why not @stripe/stripe-js?
// `loadStrip` from the main entry loads Stripe.js before the function is called.
// Yes, you are as confused as I am.
// The `loadStrip` from `/pure` fixes this issue.
import { loadStripe } from '@stripe/stripe-js/pure';
import { getStripePublicKey } from './stripe-public-key';

export const HiveStripeWrapper: FC<{ children: ReactNode }> = ({ children }) => {
Expand All @@ -10,14 +14,18 @@ export const HiveStripeWrapper: FC<{ children: ReactNode }> = ({ children }) =>
if (env.nodeEnv !== 'production') {
return;
}

const stripePublicKey = getStripePublicKey();
if (stripePublicKey) {
return loadStripe(stripePublicKey);

if (!stripePublicKey) {
return;
}

return loadStripe(stripePublicKey);
});

if (!stripe) {
return children as any;
return children;
}

return (
Expand Down

0 comments on commit 349a67d

Please sign in to comment.