From bb40e630893a7236d13f3145de00ef7539a53687 Mon Sep 17 00:00:00 2001 From: whg4 <37855991+whg4@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20invoking=20nextTick=20will=20tri?= =?UTF-8?q?gger=20infinite=20angular=20change=20detection=20(#2439)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces.ts | 1 + src/utils.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index da94291..452c7fa 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -12,6 +12,7 @@ declare global { __INJECTED_PUBLIC_PATH_BY_QIANKUN__?: string; __QIANKUN_DEVELOPMENT__?: boolean; Zone?: CallableFunction; + __zone_symbol__setTimeout?: Window['setTimeout']; } } diff --git a/src/utils.ts b/src/utils.ts index d9ae5a0..a8da78c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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. +// 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 = - 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;