From 57a4b4925dfcefbb003d57ba37e41bd982cc69b9 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Tue, 26 Dec 2023 17:46:14 +0800 Subject: [PATCH] Revert "fix(sandbox): non-hijacking elements should be appended to global document (#2861)" (#2862) This reverts commit 62048537f855ebaf6bc5a1d364632712ff17428b. --- .changeset/yellow-frogs-marry.md | 5 ----- packages/sandbox/src/patchers/dynamicAppend/common.ts | 9 +++------ .../src/patchers/dynamicAppend/forStandardSandbox.ts | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 .changeset/yellow-frogs-marry.md diff --git a/.changeset/yellow-frogs-marry.md b/.changeset/yellow-frogs-marry.md deleted file mode 100644 index 47b6c20e4..000000000 --- a/.changeset/yellow-frogs-marry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@qiankunjs/sandbox": patch ---- - -fix(sandbox): non-hijacking elements should be appended to global document diff --git a/packages/sandbox/src/patchers/dynamicAppend/common.ts b/packages/sandbox/src/patchers/dynamicAppend/common.ts index 0ac725769..115d30936 100644 --- a/packages/sandbox/src/patchers/dynamicAppend/common.ts +++ b/packages/sandbox/src/patchers/dynamicAppend/common.ts @@ -134,11 +134,9 @@ export function getOverwrittenAppendChildOrInsertBefore( const element = newChild as unknown as HTMLElement; const sandboxConfig = getSandboxConfig(element); - // without attached sandbox config means the element is not created from the sandbox environment - // these elements and non-hijacking elements should be appended to global document rather than micro app container - // TODO We can provide a configuration for situations where you expect all of the dom to be inserted into a micro aoo container, especially if the component library does not have the ability to set a popup container + // no attached sandbox config means the element is not created from the sandbox environment if (!isHijackingTag(element.tagName) || !sandboxConfig) { - return appendChild.call(document[target], element, refChild) as T; + return appendChild.call(this, element, refChild) as T; } if (element.tagName) { @@ -259,7 +257,6 @@ export function getOverwrittenAppendChildOrInsertBefore( export function getNewRemoveChild( nativeFn: typeof HTMLElement.prototype.removeChild, containerConfigGetter: (element: HTMLElement) => SandboxConfig | undefined, - target: DynamicDomMutationTarget = 'body', ) { function removeChildInSandbox(this: HTMLHeadElement | HTMLBodyElement, child: T): T { const removeChild = nativeFn; @@ -269,7 +266,7 @@ export function getNewRemoveChild( const containerConfig = containerConfigGetter(childElement); if (!isHijackingTag(tagName) || !containerConfig) { - return removeChild.call(document[target], childElement) as T; + return removeChild.call(this, childElement) as T; } try { diff --git a/packages/sandbox/src/patchers/dynamicAppend/forStandardSandbox.ts b/packages/sandbox/src/patchers/dynamicAppend/forStandardSandbox.ts index 8b1b10b88..4175c8c67 100644 --- a/packages/sandbox/src/patchers/dynamicAppend/forStandardSandbox.ts +++ b/packages/sandbox/src/patchers/dynamicAppend/forStandardSandbox.ts @@ -189,7 +189,7 @@ function patchDocumentHeadAndBodyMethods(container: HTMLElement): typeof noop { getSandboxConfig, 'head', ); - headElement.removeChild = getNewRemoveChild(document.head.removeChild, getSandboxConfig, 'head'); + headElement.removeChild = getNewRemoveChild(document.head.removeChild, getSandboxConfig); }; let containerHeadElement = getContainerHeadElement(container); if (!containerHeadElement) { @@ -217,7 +217,7 @@ function patchDocumentHeadAndBodyMethods(container: HTMLElement): typeof noop { getSandboxConfig, 'body', ); - containerBodyElement.removeChild = getNewRemoveChild(document.body.removeChild, getSandboxConfig, 'body'); + containerBodyElement.removeChild = getNewRemoveChild(document.body.removeChild, getSandboxConfig); return () => { if (containerHeadElement) {