Skip to content
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

(fix) proxy function props to prevent stale state in callbacks #604

Merged
merged 8 commits into from
Jan 15, 2025

Conversation

imbrian
Copy link
Contributor

@imbrian imbrian commented Jan 15, 2025

context

Callback props (e.g. createOrder, onApprove) are passed to paypal.Buttons in a useEffect, where the SDK Button component is then rendered. While the SDK provides a forceReRender prop to re-invoke the effect, which will update the callback functions passed to the SDK Button, this renders the SDK again (triggering animations, etc). The SDK Button otherwise never receives new functions as the parent component updates, creating stale closures.

change

This PR provides a stable object from which to read the callback functions without requiring an SDK re-render.

resolves #590

Copy link

changeset-bot bot commented Jan 15, 2025

🦋 Changeset detected

Latest commit: cf9ed5e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@paypal/react-paypal-js Minor

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

@gregjopa gregjopa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @imbrian! 💯 I tested the new storybook demo and I see the item quantity updating and it does not cause the buttons to re-render.
Screenshot 2025-01-15 at 3 49 56 PM

@imbrian imbrian marked this pull request as ready for review January 15, 2025 22:55
@imbrian imbrian requested a review from a team as a code owner January 15, 2025 22:55
@imbrian imbrian merged commit 471280d into main Jan 15, 2025
5 checks passed
@imbrian imbrian deleted the feature/proxy-props-closure branch January 15, 2025 22:58
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.

[Bug] PaypalButtons Event handlers hold stale state
3 participants