-
Notifications
You must be signed in to change notification settings - Fork 123
Refactor PayPalProvider #714
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
Refactor PayPalProvider #714
Conversation
|
| }); | ||
| } | ||
| }, [state.loadingStatus]); // Run when loadingStatus changes, but only act once | ||
| let isSubscribed = true; |
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.
Initially this useEffect did not leverage the isSubscribed strategy, when running the unit tests I was seeing warnings related to not preventing state updates on unmounted components.
Without the isSubscribed strategy, technically this useEffect could run setPaypalNamespace on an unmounted component.
I know that there is some debate about whether we need the isSubscribed strategy, I fall on the side of we should prevent state updates or dispatches to unmounted components and avoid the subsequent console warnings (courtesy of React), until we can upgrade the React version to 18/19. Check out this React Working Group post on removing this warning from React 18.
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.
Looking good! A few questions I wanted to check on though before we merge.
| const instance = await paypalNamespace.createInstance( | ||
| memoizedCreateOptions, | ||
| ); | ||
| const instance = await paypalNamespace.createInstance({ |
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.
Do we need a !isSubscribed check before this line? Is it possible for the component to have unmounted between calling the parent useEffect and the start of the async function, before createInstance has been called?
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.
I don't think we need one. Everything in the useEffect runs synchronously and must complete before the clean up method can be called b/c of an unmounting. So createInstance will always be called before the clean up can be called, but the async operation may complete after both the useEffect completes AND the component has unmounted.
| let isSubscribed = true; | ||
|
|
||
| const loadSdk = async () => { | ||
| try { |
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.
Similarly, here, do we need an !isSubscribed check at the top of this async function?
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.
Same as above, I don't think we need to update here.
9ce7952 to
574257b
Compare
574257b to
c333d0e
Compare
The provider had a few todos/code smells that were not taken up during the first pass. This updates the following:
scriptOptionsprop to its 2 keys.componentsarray specfically.dequalpackage from dependencies and replaces with a customcomponentsspecificisEqualvariation.useEffectTakes some of the ideas that were put together in this PR