diff --git a/frontend/src/scenes/billing/PaymentEntryModal.tsx b/frontend/src/scenes/billing/PaymentEntryModal.tsx index 52092c47d0e..38fc535191f 100644 --- a/frontend/src/scenes/billing/PaymentEntryModal.tsx +++ b/frontend/src/scenes/billing/PaymentEntryModal.tsx @@ -71,18 +71,22 @@ export const PaymentEntryModal = ({ const [stripePromise, setStripePromise] = useState(null) useEffect(() => { - // Load Stripe.js asynchronously - const loadStripeJs = async (): Promise => { - const { loadStripe } = await stripeJs() - const publicKey = window.STRIPE_PUBLIC_KEY! - setStripePromise(await loadStripe(publicKey)) + // Only load Stripe.js when the modal is opened + if (paymentEntryModalOpen && !stripePromise) { + const loadStripeJs = async (): Promise => { + const { loadStripe } = await stripeJs() + const publicKey = window.STRIPE_PUBLIC_KEY! + setStripePromise(await loadStripe(publicKey)) + } + void loadStripeJs() } - void loadStripeJs() - }, []) + }, [paymentEntryModalOpen, stripePromise]) useEffect(() => { - initiateAuthorization(redirectPath) - }, [initiateAuthorization, redirectPath]) + if (paymentEntryModalOpen) { + initiateAuthorization(redirectPath) + } + }, [paymentEntryModalOpen, initiateAuthorization, redirectPath]) return (