@@ -106,6 +106,7 @@ interface StripeWrapperProps {
106106 amount : number ;
107107 currency : string ;
108108 cart : {
109+ id : string ;
109110 paymentInfo ?: {
110111 type :
111112 | Stripe . PaymentMethod . Type
@@ -133,6 +134,11 @@ export function StripeWrapper({
133134 const config = useContext ( ConfigContext ) ;
134135 const [ stripePromise ] = useState ( ( ) => loadStripe ( config . stripePublicApiKey ) ) ;
135136
137+ // Re-use initial session secret to prevent unnecessary Stripe Elements remounts
138+ const [ initialSessionSecret ] = useState (
139+ cart . paymentInfo ?. customerSessionClientSecret
140+ ) ;
141+
136142 const normalizedCurrency = currency . toLowerCase ( ) ;
137143 const minCharge = STRIPE_MINIMUM_CHARGE_AMOUNTS [ normalizedCurrency ] ;
138144 const isBelowMin = amount < minCharge ;
@@ -144,7 +150,7 @@ export function StripeWrapper({
144150 amount : isBelowMin ? undefined : amount ,
145151 currency : normalizedCurrency ,
146152 externalPaymentMethodTypes : [ 'external_paypal' ] ,
147- customerSessionClientSecret : cart . paymentInfo ?. customerSessionClientSecret ,
153+ customerSessionClientSecret : initialSessionSecret ,
148154 } ;
149155
150156 // Remove external_paypal if the customer has an active subscription
@@ -158,7 +164,7 @@ export function StripeWrapper({
158164 }
159165
160166 return (
161- < Elements stripe = { stripePromise } options = { options } >
167+ < Elements stripe = { stripePromise } options = { options } key = { cart . id } >
162168 { children }
163169 </ Elements >
164170 ) ;
0 commit comments