From 6de0ac97210822e44b2a753120471038585f5193 Mon Sep 17 00:00:00 2001 From: xinhailishi <34566965+xinhailishi@users.noreply.github.com> Date: Wed, 16 Jun 2021 12:28:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=81=20fix=20clearInterval=20compatible?= =?UTF-8?q?=20bug=20in=20ie10=20and=20ie11=20(#1490)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kuitos --- src/loader.ts | 20 +++++++++----------- src/sandbox/patchers/interval.ts | 2 +- src/sandbox/snapshotSandbox.ts | 3 ++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index 66acfc7a9..6a56e5f7f 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -320,12 +320,13 @@ export async function loadApp( unmountSandbox = sandboxContainer.unmount; } - const { beforeUnmount = [], afterUnmount = [], afterMount = [], beforeMount = [], beforeLoad = [] } = mergeWith( - {}, - getAddOns(global, assetPublicPath), - lifeCycles, - (v1, v2) => concat(v1 ?? [], v2 ?? []), - ); + const { + beforeUnmount = [], + afterUnmount = [], + afterMount = [], + beforeMount = [], + beforeLoad = [], + } = mergeWith({}, getAddOns(global, assetPublicPath), lifeCycles, (v1, v2) => concat(v1 ?? [], v2 ?? [])); await execHooksChain(toArray(beforeLoad), app, global); @@ -338,11 +339,8 @@ export async function loadApp( sandboxContainer?.instance?.latestSetProp, ); - const { - onGlobalStateChange, - setGlobalState, - offGlobalStateChange, - }: Record = getMicroAppStateActions(appInstanceId); + const { onGlobalStateChange, setGlobalState, offGlobalStateChange }: Record = + getMicroAppStateActions(appInstanceId); // FIXME temporary way const syncAppWrapperElement2Sandbox = (element: HTMLElement | null) => (initialAppWrapperElement = element); diff --git a/src/sandbox/patchers/interval.ts b/src/sandbox/patchers/interval.ts index 3d63fc0eb..de8eb626c 100644 --- a/src/sandbox/patchers/interval.ts +++ b/src/sandbox/patchers/interval.ts @@ -14,7 +14,7 @@ export default function patch(global: Window) { global.clearInterval = (intervalId: number) => { intervals = intervals.filter((id) => id !== intervalId); - return rawWindowClearInterval(intervalId); + return rawWindowClearInterval.call(window, intervalId as any); }; global.setInterval = (handler: CallableFunction, timeout?: number, ...args: any[]) => { diff --git a/src/sandbox/snapshotSandbox.ts b/src/sandbox/snapshotSandbox.ts index 9774b36e9..3d2205541 100644 --- a/src/sandbox/snapshotSandbox.ts +++ b/src/sandbox/snapshotSandbox.ts @@ -8,7 +8,8 @@ import { SandBoxType } from '../interfaces'; function iter(obj: typeof window, callbackFn: (prop: any) => void) { // eslint-disable-next-line guard-for-in, no-restricted-syntax for (const prop in obj) { - if (obj.hasOwnProperty(prop)) { + // patch for clearInterval for compatible reason, see #1490 + if (obj.hasOwnProperty(prop) || prop === 'clearInterval') { callbackFn(prop); } }