🐛 invoking nextTick will trigger infinite angular change detection (#2439)

This commit is contained in:
whg4 2023-03-16 22:39:47 +08:00 committed by GitHub
parent 0b56bcb8a7
commit bb40e63089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -12,6 +12,7 @@ declare global {
__INJECTED_PUBLIC_PATH_BY_QIANKUN__?: string; __INJECTED_PUBLIC_PATH_BY_QIANKUN__?: string;
__QIANKUN_DEVELOPMENT__?: boolean; __QIANKUN_DEVELOPMENT__?: boolean;
Zone?: CallableFunction; Zone?: CallableFunction;
__zone_symbol__setTimeout?: Window['setTimeout'];
} }
} }

View File

@ -16,8 +16,11 @@ export function sleep(ms: number) {
} }
// Promise.then might be synchronized in Zone.js context, we need to use setTimeout instead to mock next tick. // Promise.then might be synchronized in Zone.js context, we need to use setTimeout instead to mock next tick.
// Since zone.js will hijack the setTimeout callback, and notify angular to do change detection, so we need to use the __zone_symbol__setTimeout to avoid this, see https://github.com/umijs/qiankun/issues/2384
const nextTick: (cb: () => void) => void = const nextTick: (cb: () => void) => void =
typeof window.Zone === 'function' ? setTimeout : (cb) => Promise.resolve().then(cb); typeof window.__zone_symbol__setTimeout === 'function'
? window.__zone_symbol__setTimeout
: (cb) => Promise.resolve().then(cb);
let globalTaskPending = false; let globalTaskPending = false;