Skip to content

Conversation

@EvanReinstein
Copy link
Contributor

@EvanReinstein EvanReinstein commented Oct 29, 2025

The provider had a few todos/code smells that were not taken up during the first pass. This updates the following:

  • Flattens scriptOptions prop to its 2 keys.
  • Removes deep comparison of all props and targets the components array specfically.
  • Removes usage of dequal package from dependencies and replaces with a custom components specific isEqual variation.
  • Splits out load core script and create instance functionality.
  • Removes/Replaces reset state useEffect
  • Updates tests to reflect new logic/provider intention.

Takes some of the ideas that were put together in this PR

@EvanReinstein EvanReinstein requested a review from a team as a code owner October 29, 2025 16:01
@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2025

⚠️ No Changeset found

Latest commit: c333d0e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

});
}
}, [state.loadingStatus]); // Run when loadingStatus changes, but only act once
let isSubscribed = true;
Copy link
Contributor Author

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.

Copy link

@kand kand left a 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({
Copy link

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?

Copy link
Contributor Author

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 {
Copy link

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?

Copy link
Contributor Author

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.

@EvanReinstein EvanReinstein force-pushed the feature/DTPPCPSDK-3933-update-react-provider branch from 9ce7952 to 574257b Compare October 30, 2025 14:28
@EvanReinstein EvanReinstein force-pushed the feature/DTPPCPSDK-3933-update-react-provider branch from 574257b to c333d0e Compare October 30, 2025 14:30
@EvanReinstein EvanReinstein merged commit d79a638 into feature/react-paypal-js-v6 Oct 30, 2025
2 checks passed
@EvanReinstein EvanReinstein deleted the feature/DTPPCPSDK-3933-update-react-provider branch October 30, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants