diff --git a/src/apis.ts b/src/apis.ts index f81d5db..2bcfc6f 100644 --- a/src/apis.ts +++ b/src/apis.ts @@ -16,7 +16,6 @@ import { Deferred, getContainerXPath, toArray } from './utils'; let microApps: Array>> = []; -// eslint-disable-next-line import/no-mutable-exports export let frameworkConfiguration: FrameworkConfiguration = {}; let started = false; diff --git a/src/sandbox/patchers/dynamicAppend/forStrictSandbox.ts b/src/sandbox/patchers/dynamicAppend/forStrictSandbox.ts index fdb930f..b8a492c 100644 --- a/src/sandbox/patchers/dynamicAppend/forStrictSandbox.ts +++ b/src/sandbox/patchers/dynamicAppend/forStrictSandbox.ts @@ -32,9 +32,12 @@ const proxyAttachContainerConfigMap = nativeGlobal.__proxyAttachContainerConfigM const elementAttachContainerConfigMap = new WeakMap(); -const rawDocumentCreateElement = Document.prototype.createElement; +const docCreatePatchedMap = new WeakMap(); function patchDocumentCreateElement() { - if (Document.prototype.createElement === rawDocumentCreateElement) { + const docCreateElementFnBeforeOverwrite = docCreatePatchedMap.get(document.createElement); + + if (!docCreateElementFnBeforeOverwrite) { + const rawDocumentCreateElement = document.createElement; Document.prototype.createElement = function createElement( this: Document, tagName: K, @@ -53,10 +56,20 @@ function patchDocumentCreateElement() { return element; }; + + // It means it have been overwritten while createElement is an own property of document + if (document.hasOwnProperty('createElement')) { + document.createElement = Document.prototype.createElement; + } + + docCreatePatchedMap.set(Document.prototype.createElement, rawDocumentCreateElement); } return function unpatch() { - Document.prototype.createElement = rawDocumentCreateElement; + if (docCreateElementFnBeforeOverwrite) { + Document.prototype.createElement = docCreateElementFnBeforeOverwrite; + document.createElement = docCreateElementFnBeforeOverwrite; + } }; }