🐛 compatible with MutationObserver as document had been wrapped as a proxy (#2407)
This commit is contained in:
parent
370238d2bb
commit
42dbcaeabe
|
|
@ -3,9 +3,8 @@
|
||||||
* @since 2020-10-13
|
* @since 2020-10-13
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { noop } from 'lodash';
|
|
||||||
import type { Freer, SandBox } from '../../../interfaces';
|
import type { Freer, SandBox } from '../../../interfaces';
|
||||||
import { nativeGlobal } from '../../../utils';
|
import { nativeDocument, nativeGlobal } from '../../../utils';
|
||||||
import { getCurrentRunningApp } from '../../common';
|
import { getCurrentRunningApp } from '../../common';
|
||||||
import type { ContainerConfig } from './common';
|
import type { ContainerConfig } from './common';
|
||||||
import {
|
import {
|
||||||
|
|
@ -70,7 +69,21 @@ function patchDocument(cfg: { sandbox: SandBox; speedy: boolean }) {
|
||||||
|
|
||||||
sandbox.patchDocument(proxyDocument);
|
sandbox.patchDocument(proxyDocument);
|
||||||
|
|
||||||
return noop;
|
// patch MutationObserver.prototype.observe to avoid type error
|
||||||
|
// https://github.com/umijs/qiankun/issues/2406
|
||||||
|
const nativeMutationObserverObserveFn = MutationObserver.prototype.observe;
|
||||||
|
MutationObserver.prototype.observe = function observe(
|
||||||
|
this: MutationObserver,
|
||||||
|
target: Node,
|
||||||
|
options: MutationObserverInit,
|
||||||
|
) {
|
||||||
|
const realTarget = target instanceof Document ? nativeDocument : target;
|
||||||
|
return nativeMutationObserverObserveFn.call(this, realTarget, options);
|
||||||
|
};
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
MutationObserver.prototype.observe = nativeMutationObserverObserveFn;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const docCreateElementFnBeforeOverwrite = docCreatePatchedMap.get(document.createElement);
|
const docCreateElementFnBeforeOverwrite = docCreatePatchedMap.get(document.createElement);
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,8 @@ export function getWrapperId(name: string) {
|
||||||
|
|
||||||
export const nativeGlobal = new Function('return this')();
|
export const nativeGlobal = new Function('return this')();
|
||||||
|
|
||||||
|
export const nativeDocument = new Function('return document')();
|
||||||
|
|
||||||
const getGlobalAppInstanceMap = once<() => Record<string, number>>(() => {
|
const getGlobalAppInstanceMap = once<() => Record<string, number>>(() => {
|
||||||
if (!nativeGlobal.hasOwnProperty('__app_instance_name_map__')) {
|
if (!nativeGlobal.hasOwnProperty('__app_instance_name_map__')) {
|
||||||
Object.defineProperty(nativeGlobal, '__app_instance_name_map__', {
|
Object.defineProperty(nativeGlobal, '__app_instance_name_map__', {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user