✨ compatible with who have overwrite document.createElement function before (#1733)
This commit is contained in:
parent
cbad8c8d7d
commit
238a5f5ea5
|
|
@ -16,7 +16,6 @@ import { Deferred, getContainerXPath, toArray } from './utils';
|
||||||
|
|
||||||
let microApps: Array<RegistrableApp<Record<string, unknown>>> = [];
|
let microApps: Array<RegistrableApp<Record<string, unknown>>> = [];
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-mutable-exports
|
|
||||||
export let frameworkConfiguration: FrameworkConfiguration = {};
|
export let frameworkConfiguration: FrameworkConfiguration = {};
|
||||||
|
|
||||||
let started = false;
|
let started = false;
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,12 @@ const proxyAttachContainerConfigMap = nativeGlobal.__proxyAttachContainerConfigM
|
||||||
|
|
||||||
const elementAttachContainerConfigMap = new WeakMap<HTMLElement, ContainerConfig>();
|
const elementAttachContainerConfigMap = new WeakMap<HTMLElement, ContainerConfig>();
|
||||||
|
|
||||||
const rawDocumentCreateElement = Document.prototype.createElement;
|
const docCreatePatchedMap = new WeakMap<typeof document.createElement, typeof document.createElement>();
|
||||||
function patchDocumentCreateElement() {
|
function patchDocumentCreateElement() {
|
||||||
if (Document.prototype.createElement === rawDocumentCreateElement) {
|
const docCreateElementFnBeforeOverwrite = docCreatePatchedMap.get(document.createElement);
|
||||||
|
|
||||||
|
if (!docCreateElementFnBeforeOverwrite) {
|
||||||
|
const rawDocumentCreateElement = document.createElement;
|
||||||
Document.prototype.createElement = function createElement<K extends keyof HTMLElementTagNameMap>(
|
Document.prototype.createElement = function createElement<K extends keyof HTMLElementTagNameMap>(
|
||||||
this: Document,
|
this: Document,
|
||||||
tagName: K,
|
tagName: K,
|
||||||
|
|
@ -53,10 +56,20 @@ function patchDocumentCreateElement() {
|
||||||
|
|
||||||
return element;
|
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() {
|
return function unpatch() {
|
||||||
Document.prototype.createElement = rawDocumentCreateElement;
|
if (docCreateElementFnBeforeOverwrite) {
|
||||||
|
Document.prototype.createElement = docCreateElementFnBeforeOverwrite;
|
||||||
|
document.createElement = docCreateElementFnBeforeOverwrite;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user