Skip to content

Commit 909add3

Browse files
Fix issue with ignored appearance changes. (#589)
1 parent f9fa371 commit 909add3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/components/CheckoutProvider.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,24 @@ export const CheckoutProvider: FunctionComponent<PropsWithChildren<
172172

173173
// Apply updates to elements when options prop has relevant changes
174174
const prevOptions = usePrevious(options);
175+
const prevCheckoutSdk = usePrevious(ctx.checkoutSdk);
175176
React.useEffect(() => {
177+
// Ignore changes while checkout sdk is not initialized.
176178
if (!ctx.checkoutSdk) {
177179
return;
178180
}
179181

180182
const previousAppearance = prevOptions?.elementsOptions?.appearance;
181183
const currentAppearance = options?.elementsOptions?.appearance;
182-
if (currentAppearance && !isEqual(currentAppearance, previousAppearance)) {
184+
const hasAppearanceChanged = !isEqual(
185+
currentAppearance,
186+
previousAppearance
187+
);
188+
const hasSdkLoaded = !prevCheckoutSdk && ctx.checkoutSdk;
189+
if (currentAppearance && (hasAppearanceChanged || hasSdkLoaded)) {
183190
ctx.checkoutSdk.changeAppearance(currentAppearance);
184191
}
185-
}, [options, prevOptions, ctx.checkoutSdk]);
192+
}, [options, prevOptions, ctx.checkoutSdk, prevCheckoutSdk]);
186193

187194
// Attach react-stripe-js version to stripe.js instance
188195
React.useEffect(() => {

0 commit comments

Comments
 (0)