-
Notifications
You must be signed in to change notification settings - Fork 212
W-21411273, W-21434212: Fix for Display SPMs at checkout due to caching issues and Fix for failing tests on feature branch #3710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,10 +64,14 @@ const SFPaymentsSheet = forwardRef((props, ref) => { | |||||||||
|
|
||||||||||
| const {data: basket} = useCurrentBasket() | ||||||||||
| const {isRegistered} = useCustomerType() | ||||||||||
| const {data: customer, isLoading: customerLoading} = useCurrentCustomer( | ||||||||||
| isRegistered ? ['paymentmethodreferences'] : undefined | ||||||||||
| ) | ||||||||||
| const isCustomerDataLoading = isRegistered && customerLoading | ||||||||||
| const { | ||||||||||
| data: customer, | ||||||||||
| isLoading: customerLoading, | ||||||||||
| isFetching: customerFetching | ||||||||||
| } = useCurrentCustomer(isRegistered ? ['paymentmethodreferences'] : undefined, { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought useCurrentCustomer only accepts 1 param, which is Array. It seems like you introduced a new param (refetchOnMount). The first argument ['paymentmethodreferences'] is fine since it's an array of strings matching the expected expand parameter. But the second argument { refetchOnMount: 'always' } has no corresponding parameter in the function signature to receive it. Code won't throw an error for extra arguments but I would think that its silently ignored. So what purpose will refetchOnMount serve then?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Too many changes on my working local. Missed pushing it. Let me clear up everything else and re-verify all the changes including failOrder. I've made changes to use-current-customer.js to accept optional query params, wehre we could pass React's own refetch query param
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||||||
| refetchOnMount: 'always' | ||||||||||
| }) | ||||||||||
| const isCustomerDataLoading = isRegistered && (customerLoading || customerFetching) | ||||||||||
|
|
||||||||||
| const isPickupOnly = | ||||||||||
| basket?.shipments?.length > 0 && | ||||||||||
|
|
@@ -523,9 +527,14 @@ const SFPaymentsSheet = forwardRef((props, ref) => { | |||||||||
| [customer, paymentConfig] | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| const [paymentStepReached, setPaymentStepReached] = useState(false) | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We typically use refs. Is there a reason why state is the right choice this time?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We needed a re-render on change in step. Update to refs do not cause a re-render of component. So used State. Seems like refs are stable objects in React. |
||||||||||
| useEffect(() => { | ||||||||||
| // Mount SFP only when all required data and DOM are ready; otherwise skip or wait for a later run. | ||||||||||
| if (step === STEPS.PAYMENT) setPaymentStepReached(true) | ||||||||||
| }, [step, STEPS]) | ||||||||||
|
|
||||||||||
| useEffect(() => { | ||||||||||
| // Mount SFP only when all required data and DOM are ready; otherwise skip or wait for a later run. | ||||||||||
| if (!paymentStepReached) return // Only run after user has reached payment step | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
returns early with You might not need two useEffect.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for directly not using step was that if we reach the payment step, but we change back to any other step like shipping on the checkout page, we wouldn't want a re-render of checkout again. |
||||||||||
| if (isCustomerDataLoading) return // Wait for savedPaymentMethods data to load for registered users | ||||||||||
| if (checkoutComponent.current) return // Skip if Componenet Already mounted | ||||||||||
| if (!sfp) return // Skip if SFP SDK not loaded yet | ||||||||||
|
|
@@ -589,13 +598,11 @@ const SFPaymentsSheet = forwardRef((props, ref) => { | |||||||||
| checkoutComponent.current?.destroy() | ||||||||||
| checkoutComponent.current = null | ||||||||||
| } | ||||||||||
| // Omit savedPaymentMethodsKey: init once with current SPM; re-initing when SPM list changes | ||||||||||
| // causes Stripe/Adyen to complain. | ||||||||||
| }, [ | ||||||||||
| paymentStepReached, | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and you might not need STEPS in dependency array since it is recreated on every render and this might make the useEffect run on every render.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think with paymentStepReached in the deps, the state change triggers the effect to re-run, it passes the guard, and SFP initializes correctly. If its step, then when user changes to shipping, this effect will run and can execute the destroy logic unmounting the SDK. But it can't remount again due to the other effect which exits early when in payment step
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, we might not need the paymentStepReached state variable
Suggested change
this should work. The effect runs only when you land on or leave the payment step |
||||||||||
| isCustomerDataLoading, | ||||||||||
| sfp, | ||||||||||
| metadata, | ||||||||||
| containerElementRef.current, | ||||||||||
| paymentConfig, | ||||||||||
| cardCaptureAutomatic | ||||||||||
| ]) | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this failing because gatewayProperties was there, and we actually just wanted setupFutureUsage to not be there? I ask because I think setupFutureUsage is the only property we ever send for Stripe. Is it that the SCAPI requires us to send gatewayProperties even if it's empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think with the setup_future_usage bug fix, I'd added the gatewayProperties for stripe even when it wasn't mandated by SCAPI for consistency. But removed and tested it. Including it even for guest and non-SPM probably would be overkill and not required. Updated.