Skip to content

Commit

Permalink
Revert "fix(sandbox): non-hijacking elements should be appended to gl…
Browse files Browse the repository at this point in the history
…obal document (#2861)" (#2862)

This reverts commit 6204853.
  • Loading branch information
kuitos authored Dec 26, 2023
1 parent 3989b81 commit 57a4b49
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
5 changes: 0 additions & 5 deletions .changeset/yellow-frogs-marry.md

This file was deleted.

9 changes: 3 additions & 6 deletions packages/sandbox/src/patchers/dynamicAppend/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<T extends Node>(this: HTMLHeadElement | HTMLBodyElement, child: T): T {
const removeChild = nativeFn;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 57a4b49

Please sign in to comment.