Remove Stripe iFrame when StripeProvider unmounts #99
Description
Every time the StripeProvider
component is constructed it creates a new iFrame in the DOM that is not removed when the component is unmounted (the iFrame appears to be asynchronously created after the Provider constructor executes due to window.Stripe()
being called). After transitioning between various different pages that may or may not contain stripe components I'm left with numerous iframes cluttering up the DOM.
I'm aware that I can avoid the problem by placing the StripeProvider
higher up the component tree, however I'm unwilling to force the user to download the Stripe.js lib unnecessarily if they're never going to see any Stripe components and therefore would rather keep it inside the pages concerned.
I couldn't see any nice API on the object that comes back from window.Stripe()
to remove the iFrame/destroy the instance, however simply running: this._stripe._controller._controllerFrame._iframe.remove();
inside componentWillUnmount
on the Provider
achieves the desired effect (dirty though that is).
To me, it seems like the ideal solution would be to update Stripe.js to contain a more elegant unmount/destroy/unregister function and then trigger that in componentWillUnmount
on the Provider
.