🩹 should invoke removeChild on original node while it not calling by micro app

This commit is contained in:
kiloc 2023-03-10 16:57:21 +08:00 committed by GitHub
parent 385dc8c53a
commit c9dff6fe42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -346,10 +346,12 @@ function getNewRemoveChild(
headOrBodyRemoveChild: typeof HTMLElement.prototype.removeChild, headOrBodyRemoveChild: typeof HTMLElement.prototype.removeChild,
containerConfigGetter: (element: HTMLElement) => ContainerConfig, containerConfigGetter: (element: HTMLElement) => ContainerConfig,
target: DynamicDomMutationTarget, target: DynamicDomMutationTarget,
isInvokedByMicroApp: (element: HTMLElement) => boolean,
) { ) {
return function removeChild<T extends Node>(this: HTMLHeadElement | HTMLBodyElement, child: T) { return function removeChild<T extends Node>(this: HTMLHeadElement | HTMLBodyElement, child: T) {
const { tagName } = child as any; 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 { try {
let attachedElement: Node; let attachedElement: Node;
@ -429,8 +431,18 @@ export function patchHTMLDynamicAppendPrototypeFunctions(
HTMLHeadElement.prototype.removeChild === rawHeadRemoveChild && HTMLHeadElement.prototype.removeChild === rawHeadRemoveChild &&
HTMLBodyElement.prototype.removeChild === rawBodyRemoveChild HTMLBodyElement.prototype.removeChild === rawBodyRemoveChild
) { ) {
HTMLHeadElement.prototype.removeChild = getNewRemoveChild(rawHeadRemoveChild, containerConfigGetter, 'head'); HTMLHeadElement.prototype.removeChild = getNewRemoveChild(
HTMLBodyElement.prototype.removeChild = getNewRemoveChild(rawBodyRemoveChild, containerConfigGetter, 'body'); rawHeadRemoveChild,
containerConfigGetter,
'head',
isInvokedByMicroApp,
);
HTMLBodyElement.prototype.removeChild = getNewRemoveChild(
rawBodyRemoveChild,
containerConfigGetter,
'body',
isInvokedByMicroApp,
);
} }
return function unpatch() { return function unpatch() {