Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove unnecessary stripe iframes (#37428)
* fix: Remove stripe iframes when navigating away from /donate while still leaving two that may/may not be essential to Stripe * Moved MutationObserver code into Header component * fix: make MutationObserver remove old iframes Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
- Loading branch information
1 parent
3fb5a2c
commit a475ddc
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const stripeObserver = () => { | ||
const config = { attributes: false, childList: true, subtree: false }; | ||
|
||
const filterNodes = nl => | ||
Array.from(nl) | ||
.filter(b => b.nodeName === 'IFRAME') | ||
.filter(b => /__privateStripeController/.test(b.name)); | ||
|
||
const mutationCallback = a => { | ||
const controllerAdded = a.reduce( | ||
(acc, curr) => | ||
curr.type === 'childList' | ||
? [...acc, ...filterNodes(curr.addedNodes)] | ||
: acc, | ||
[] | ||
)[0]; | ||
if (controllerAdded) { | ||
const allControllers = filterNodes(document.body.childNodes); | ||
allControllers.forEach(controller => { | ||
if (controller.name !== controllerAdded.name) { | ||
controller.remove(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
return new MutationObserver(mutationCallback).observe(document.body, config); | ||
}; | ||
|
||
export default stripeObserver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters