22
33import { OPTIONS , options } from './options.mjs' ;
44import {
5- Error , map , at ,
5+ Error , map , at , push ,
66 defineProperties ,
77 from , stringify ,
88 createElement ,
99 appendChild ,
1010 replaceChildren ,
1111 textContentSet ,
1212 ownerDocument ,
13- navigation ,
13+ navigation , Array ,
1414 url , destination , includes ,
1515 preventDefault , stopPropagation ,
1616} from './native.mjs' ;
1717import { distraction , loadable , hardened } from './element.mjs' ;
1818import { getShadow } from './shadow.mjs' ;
1919
20+ const teardowns = Array ( ) ;
21+
2022// text-fragments links can be abused to leak shadow internals - block in-app redirection to them
2123navigation . addEventListener ( 'navigate' , event => {
2224 const dest = url ( destination ( event ) ) ;
@@ -26,6 +28,7 @@ navigation.addEventListener('navigate', event => {
2628 throw new Error (
2729 `LavaDomeCore: in-app redirection to text-fragments links is blocked to ensure security` ) ;
2830 }
31+ map ( teardowns , teardown => teardown ( ) ) ;
2932} ) ;
3033
3134export function LavaDome ( host , opts ) {
@@ -38,11 +41,14 @@ export function LavaDome(host, opts) {
3841 const shadow = getShadow ( host , opts ) ;
3942 replaceChildren ( shadow ) ;
4043
44+ const teardown = ( ) => replaceChildren ( shadow ) ;
45+ push ( teardowns , teardown ) ;
46+
4147 // fire every time instance is reloaded and abort loading for non-top documents
4248 const attach = loadable ( element => {
4349 const ownerDoc = ownerDocument ( element ) ;
4450 if ( ownerDoc !== document ) {
45- replaceChildren ( shadow ) ;
51+ teardown ( ) ;
4652 throw new Error ( `LavaDomeCore: ` +
4753 `The document to which LavaDome was originally introduced ` +
4854 `must be the same as the one this instance is inserted to` ) ;
0 commit comments