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

[BUG]: StripeEmbeddedCheckout.destroy cannot safely be called multiple times and no way to check a destroyed property #685

Open
davidbielik opened this issue Nov 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@davidbielik
Copy link

davidbielik commented Nov 19, 2024

What happened?

@stripe/stripe-js": "^3.0.3

My integration has two logical places where I destroy an embedded checkout instance (if a user goes to another page, or if a user clicks to go back to pricing plans and hide the embedded checkout).

I call instance.destroy() and create new instances which works as expected, but calling destroy twice results in an error message.

It would be great if you allowed calling destroy on an already destroyed instance. If not possible for some reason, it would be helpful to have access to the embeddedCheckout.isDestroyed property in the typescript definitions somehow.

I was able to find a workaround (not ideal passing more state around) but would have saved time if this worked more seamlessly.

const instance = await stripe?.initEmbeddedCheckout({clientSecret});
instance?.destroy();
instance?.destroy(); // throws an error 
{
    "message": "This Embedded Checkout instance has been destroyed and can't be used anymore. Please create a new one.",
    "name": "IntegrationError"
}

Environment

No response

Reproduction

No response

@davidbielik davidbielik added the bug Something isn't working label Nov 19, 2024
@brendanm-stripe
Copy link
Contributor

brendanm-stripe commented Nov 21, 2024

Hmm I can see how that would be convenient for your flow, though for how I've pictured your integration tracking the embedded Checkout state I think makes sense. Does it also work to wrap your call to destroy in a try/catch?

@davidbielik
Copy link
Author

Thanks, yes that works. Just wanted to pass along the (minor) feedback, as this was an area that caused confusion. I assumed I could safely call instance?.destroy() any time I wanted to call initEmbeddedCheckout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants