Skip to content

Commit

Permalink
🏁 fix clearInterval compatible bug in ie10 and ie11 (#1490)
Browse files Browse the repository at this point in the history
Co-authored-by: Kuitos <[email protected]>
  • Loading branch information
xinhailishi and kuitos authored Jun 16, 2021
1 parent 7ae60e3 commit 6de0ac9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
20 changes: 9 additions & 11 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,13 @@ export async function loadApp<T extends ObjectType>(
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);

Expand All @@ -338,11 +339,8 @@ export async function loadApp<T extends ObjectType>(
sandboxContainer?.instance?.latestSetProp,
);

const {
onGlobalStateChange,
setGlobalState,
offGlobalStateChange,
}: Record<string, CallableFunction> = getMicroAppStateActions(appInstanceId);
const { onGlobalStateChange, setGlobalState, offGlobalStateChange }: Record<string, CallableFunction> =
getMicroAppStateActions(appInstanceId);

// FIXME temporary way
const syncAppWrapperElement2Sandbox = (element: HTMLElement | null) => (initialAppWrapperElement = element);
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/patchers/interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
3 changes: 2 additions & 1 deletion src/sandbox/snapshotSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 6de0ac9

Please sign in to comment.