🐛 compatiable with react development for event rewrite scenarios (#2545)

This commit is contained in:
Kuitos 2023-07-05 15:15:56 +08:00 committed by GitHub
parent f0b63e7290
commit d9502f5795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,8 @@ const variableWhiteListInDev =
// for react hot reload // for react hot reload
// see https://github.com/facebook/create-react-app/blob/66bf7dfc43350249e2f09d138a20840dae8a0a4a/packages/react-error-overlay/src/index.js#L180 // see https://github.com/facebook/create-react-app/blob/66bf7dfc43350249e2f09d138a20840dae8a0a4a/packages/react-error-overlay/src/index.js#L180
'__REACT_ERROR_OVERLAY_GLOBAL_HOOK__', '__REACT_ERROR_OVERLAY_GLOBAL_HOOK__',
// for react development event issue, see https://github.com/umijs/qiankun/issues/2375
'event',
] ]
: []; : [];
// who could escape the sandbox // who could escape the sandbox
@ -209,6 +211,13 @@ export default class ProxySandbox implements SandBox {
set: (target: FakeWindow, p: PropertyKey, value: any): boolean => { set: (target: FakeWindow, p: PropertyKey, value: any): boolean => {
if (this.sandboxRunning) { if (this.sandboxRunning) {
this.registerRunningApp(name, proxy); this.registerRunningApp(name, proxy);
// sync the property to globalContext
if (typeof p === 'string' && globalVariableWhiteList.indexOf(p) !== -1) {
this.globalWhitelistPrevDescriptor[p] = Object.getOwnPropertyDescriptor(globalContext, p);
// @ts-ignore
globalContext[p] = value;
} else {
// We must keep its description while the property existed in globalContext before // We must keep its description while the property existed in globalContext before
if (!target.hasOwnProperty(p) && globalContext.hasOwnProperty(p)) { if (!target.hasOwnProperty(p) && globalContext.hasOwnProperty(p)) {
const descriptor = Object.getOwnPropertyDescriptor(globalContext, p); const descriptor = Object.getOwnPropertyDescriptor(globalContext, p);
@ -222,12 +231,6 @@ export default class ProxySandbox implements SandBox {
} else { } else {
target[p] = value; target[p] = value;
} }
// sync the property to globalContext
if (typeof p === 'string' && globalVariableWhiteList.indexOf(p) !== -1) {
this.globalWhitelistPrevDescriptor[p] = Object.getOwnPropertyDescriptor(globalContext, p);
// @ts-ignore
globalContext[p] = value;
} }
updatedValueSet.add(p); updatedValueSet.add(p);
@ -281,6 +284,11 @@ export default class ProxySandbox implements SandBox {
return eval; return eval;
} }
if (p === 'string' && globalVariableWhiteList.indexOf(p) !== -1) {
// @ts-ignore
return globalContext[p];
}
const actualTarget = propertiesWithGetter.has(p) ? globalContext : p in target ? target : globalContext; const actualTarget = propertiesWithGetter.has(p) ? globalContext : p in target ? target : globalContext;
const value = actualTarget[p]; const value = actualTarget[p];