From c9dff6fe42a132c2d7e7cfccfa86a083c9c75b2b Mon Sep 17 00:00:00 2001 From: kiloc Date: Fri, 10 Mar 2023 16:57:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20should=20invoke=20removeChild=20?= =?UTF-8?q?on=20original=20node=20while=20it=20not=20calling=20by=20micro?= =?UTF-8?q?=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/patchers/dynamicAppend/common.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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() {