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

Wraps component destructor in a trycatch #409

Merged
merged 3 commits into from
Jun 16, 2023
Merged

Conversation

jima-stripe
Copy link
Contributor

Summary & motivation

When the Payment Element destroys itself, React doesn't always know about it. So when React attempts to unmount the a destroyed PE, an integration error is thrown and the application crashes.

One reproducible scenario of this is when creating a PE with an amount that is too small. The call to elements/session returns an error like this:

No valid payment method types for this configuration. Please ensure that you have activated payment methods compatible with your chosen currency in your dashboard (https://dashboard.stripe.com/settings/payment_methods) and that the `amount` (30) is not lower than the `currency` (usd) minimum: https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts

Then the loaderror event is triggered. (I believe the component self-destructs in stripe-js, but React still has a reference to it.) So if the merchant attempts to unmount the PE or a wrapper around the PE, the app crashes because it tries to call destroy() on a component that isn't there.

The solution (at least for now)
Wrap the destroy() call in a trycatch, so that it doesn't crash the app.

Testing & documentation

Manually validated the change. Existing tests continue to pass.

@jima-stripe
Copy link
Contributor Author

FYI @bmathews-stripe and @jackieosborn-stripe

Copy link
Contributor

@fruchtose-stripe fruchtose-stripe left a comment

Choose a reason for hiding this comment

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

Looks good. I have one point of feedback.

src/components/createElementComponent.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@fruchtose-stripe fruchtose-stripe left a comment

Choose a reason for hiding this comment

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

:shipit:

@jima-stripe jima-stripe merged commit 8a39104 into master Jun 16, 2023
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.

4 participants