Skip to content

Commit 9b2bec6

Browse files
authored
fix: Stripe load error (#6632)
1 parent 2056307 commit 9b2bec6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

.changeset/weak-items-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Capture Stripe.js load error to avoid raising an unhandled error

packages/web/app/src/lib/billing/stripe.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FC, ReactNode, Suspense, useState } from 'react';
22
import { env } from '@/env/frontend';
3+
import { captureMessage } from '@sentry/react';
34
import { Elements as ElementsProvider } from '@stripe/react-stripe-js';
45
// Why not @stripe/stripe-js?
56
// `loadStrip` from the main entry loads Stripe.js before the function is called.
@@ -10,18 +11,27 @@ import { getStripePublicKey } from './stripe-public-key';
1011

1112
export const HiveStripeWrapper: FC<{ children: ReactNode }> = ({ children }) => {
1213
// eslint-disable-next-line react/hook-use-state -- we don't need setter
13-
const [stripe] = useState<ReturnType<typeof loadStripe> | void>(() => {
14+
const [stripe] = useState<ReturnType<typeof loadStripe> | void>(async () => {
1415
if (env.nodeEnv !== 'production') {
15-
return;
16+
return null;
1617
}
1718

1819
const stripePublicKey = getStripePublicKey();
1920

2021
if (!stripePublicKey) {
21-
return;
22+
return null;
2223
}
2324

24-
return loadStripe(stripePublicKey);
25+
try {
26+
return await loadStripe(stripePublicKey);
27+
} catch (e) {
28+
const message =
29+
e instanceof Error ? e.message : typeof e === 'string' ? e : 'Failed to load Stripe.js';
30+
captureMessage(message, {
31+
level: 'warning',
32+
});
33+
return null;
34+
}
2535
});
2636

2737
if (!stripe) {

0 commit comments

Comments
 (0)