Skip to content

Commit

Permalink
fix:destroy stripe embedded checkout element when wrapper element is …
Browse files Browse the repository at this point in the history
…destroyed
  • Loading branch information
unruha authored and joshnuss committed Jan 8, 2024
1 parent 136e2ca commit 265c62c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/EmbeddedCheckout.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { onDestroy } from 'svelte'
import { register } from './util'
/** @type {import('@stripe/stripe-js').Stripe?} */
Expand All @@ -9,6 +10,8 @@
let wrapper
let checkoutElement
$: if (stripe) {
register(stripe)
}
Expand All @@ -17,9 +20,14 @@
stripe
.initEmbeddedCheckout({ clientSecret })
.then((element) => {
element.mount(wrapper)
checkoutElement = element
checkoutElement.mount(wrapper)
})
}
onDestroy(() => {
checkoutElement?.destroy()
});
</script>
{#if stripe && clientSecret}
Expand Down

1 comment on commit 265c62c

@vercel
Copy link

@vercel vercel bot commented on 265c62c Jan 8, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.