⚡️ fix the performance issue in sandbox (#1626)
This commit is contained in:
parent
6359409893
commit
44ccad92de
|
|
@ -5,13 +5,23 @@
|
||||||
|
|
||||||
import { isBoundedFunction, isCallable, isConstructable } from '../utils';
|
import { isBoundedFunction, isCallable, isConstructable } from '../utils';
|
||||||
|
|
||||||
let currentRunningSandboxProxy: WindowProxy | null = null;
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
__currentRunningSandboxProxy__: WindowProxy | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get native global window with a sandbox disgusted way, thus we could share it between qiankun instances🤪
|
||||||
|
// eslint-disable-next-line no-new-func
|
||||||
|
const nativeGlobal: Window = new Function('return this')();
|
||||||
|
Object.defineProperty(nativeGlobal, '__currentRunningSandboxProxy__', { enumerable: false, writable: true });
|
||||||
export function getCurrentRunningSandboxProxy() {
|
export function getCurrentRunningSandboxProxy() {
|
||||||
return currentRunningSandboxProxy;
|
return nativeGlobal.__currentRunningSandboxProxy__;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setCurrentRunningSandboxProxy(proxy: WindowProxy | null) {
|
export function setCurrentRunningSandboxProxy(proxy: WindowProxy | null) {
|
||||||
currentRunningSandboxProxy = proxy;
|
// set currentRunningSandboxProxy to global window, as its only use case is for document.createElement from now on, which hijacked by a global way
|
||||||
|
nativeGlobal.__currentRunningSandboxProxy__ = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
const functionBoundedValueMap = new WeakMap<CallableFunction, CallableFunction>();
|
const functionBoundedValueMap = new WeakMap<CallableFunction, CallableFunction>();
|
||||||
|
|
|
||||||
|
|
@ -215,14 +215,14 @@ export default class ProxySandbox implements SandBox {
|
||||||
},
|
},
|
||||||
|
|
||||||
get(target: FakeWindow, p: PropertyKey): any {
|
get(target: FakeWindow, p: PropertyKey): any {
|
||||||
|
if (p === Symbol.unscopables) return unscopables;
|
||||||
|
|
||||||
setCurrentRunningSandboxProxy(proxy);
|
setCurrentRunningSandboxProxy(proxy);
|
||||||
// FIXME if you have any other good ideas
|
// FIXME if you have any other good ideas
|
||||||
// remove the mark in next tick, thus we can identify whether it in micro app or not
|
// remove the mark in next tick, thus we can identify whether it in micro app or not
|
||||||
// this approach is just a workaround, it could not cover all complex cases, such as the micro app runs in the same task context with master in some case
|
// this approach is just a workaround, it could not cover all complex cases, such as the micro app runs in the same task context with master in some case
|
||||||
nextTick(() => setCurrentRunningSandboxProxy(null));
|
nextTick(() => setCurrentRunningSandboxProxy(null));
|
||||||
|
|
||||||
if (p === Symbol.unscopables) return unscopables;
|
|
||||||
|
|
||||||
// avoid who using window.window or window.self to escape the sandbox environment to touch the really window
|
// avoid who using window.window or window.self to escape the sandbox environment to touch the really window
|
||||||
// see https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js#L13
|
// see https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js#L13
|
||||||
if (p === 'window' || p === 'self') {
|
if (p === 'window' || p === 'self') {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user