-
Notifications
You must be signed in to change notification settings - Fork 42
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 when mounting/unmounting Payment Elements #122
Comments
By forcing
|
Tentative PR here: #123 |
Hey @joshnuss did you have any chance to look into this, or find a better fix? Thanks |
Hi @frederichoule! I'm wondering, what's different in your repo vs this one? Did you change anything? Because when I try it with the live Svelte PaymentElement example it seems to work OK |
Did you try my repo? There's a new button in the Svelte PaymentElement example page that says "Hide/Show" and replicates the bug. The only change to the actual payment element is there: Line 71: |
Hey @joshnuss, the example wasn't in the repo, sorry it's my fault. It is now. Example: https://github.com/frederichoule/svelte-stripe |
Any update @joshnuss ? |
I am getting the same error when I use Elements in a multi-step form where the user advances to the payment element step, but goes back and then again to the step with the payment element, then an error is thrown and the app stops working:
The error stems from calling getContext in an element that returns an undefined value. I rectified the bug by simply adding to the Elements.svelte a onDestroy lifecycle function. When unmounting the Elements component, the elements objects and its contents gets garbage collected.
|
Getting ready for production in the next few days, and no update from @joshnuss - so here's what I did to fix it without forking the whole library:
Basically, as soon as the div surrounding the Elements is destroyed, we just clear the binded reference to it and then everything works again the next time you mount it in the same payment flow. Thanks @TheRealThor for pointing me in the right direction! |
@frederichoule apologies for the delay. I will take a look this week. |
Describe the bug
When creating, destroying and recreating the Payment Element, we get an error related to getContext() in Payment Elements.
Reproduction
https://localhost:5174/examples/payment-element
show/hide
buttonSeverity
blocking all usage
Additional Information
No response
The text was updated successfully, but these errors were encountered: