diff --git a/src/sandbox/patchers/dynamicAppend/common.ts b/src/sandbox/patchers/dynamicAppend/common.ts index 144f0af..ffb2f9a 100644 --- a/src/sandbox/patchers/dynamicAppend/common.ts +++ b/src/sandbox/patchers/dynamicAppend/common.ts @@ -346,10 +346,12 @@ function getNewRemoveChild( headOrBodyRemoveChild: typeof HTMLElement.prototype.removeChild, containerConfigGetter: (element: HTMLElement) => ContainerConfig, target: DynamicDomMutationTarget, + isInvokedByMicroApp: (element: HTMLElement) => boolean, ) { return function removeChild(this: HTMLHeadElement | HTMLBodyElement, child: T) { const { tagName } = child as any; - if (!isHijackingTag(tagName)) return headOrBodyRemoveChild.call(this, child) as T; + if (!isHijackingTag(tagName) || !isInvokedByMicroApp(child as any)) + return headOrBodyRemoveChild.call(this, child) as T; try { let attachedElement: Node; @@ -429,8 +431,18 @@ export function patchHTMLDynamicAppendPrototypeFunctions( HTMLHeadElement.prototype.removeChild === rawHeadRemoveChild && HTMLBodyElement.prototype.removeChild === rawBodyRemoveChild ) { - HTMLHeadElement.prototype.removeChild = getNewRemoveChild(rawHeadRemoveChild, containerConfigGetter, 'head'); - HTMLBodyElement.prototype.removeChild = getNewRemoveChild(rawBodyRemoveChild, containerConfigGetter, 'body'); + HTMLHeadElement.prototype.removeChild = getNewRemoveChild( + rawHeadRemoveChild, + containerConfigGetter, + 'head', + isInvokedByMicroApp, + ); + HTMLBodyElement.prototype.removeChild = getNewRemoveChild( + rawBodyRemoveChild, + containerConfigGetter, + 'body', + isInvokedByMicroApp, + ); } return function unpatch() {