From: Evan You Date: Thu, 8 Sep 2022 01:59:51 +0000 (+0800) Subject: fix(runtime-core): avoid double firing when mounting inside a watcher callback X-Git-Tag: v3.2.39~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6aaf8efefffdb0d4b93f178b2bb36cd3c6bc31b8;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): avoid double firing when mounting inside a watcher callback fix #6614 --- diff --git a/packages/runtime-core/__tests__/scheduler.spec.ts b/packages/runtime-core/__tests__/scheduler.spec.ts index 1f7199f6ed..dc9bace9c9 100644 --- a/packages/runtime-core/__tests__/scheduler.spec.ts +++ b/packages/runtime-core/__tests__/scheduler.spec.ts @@ -534,4 +534,16 @@ describe('scheduler', () => { // should not be called expect(spy).toHaveBeenCalledTimes(0) }) + + it('flushPreFlushCbs inside a pre job', async () => { + const spy = jest.fn() + const job = () => { + spy() + flushPreFlushCbs() + } + job.pre = true + queueJob(job) + await nextTick() + expect(spy).toHaveBeenCalledTimes(1) + }) }) diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 109541d280..923f3ec825 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -133,7 +133,11 @@ export function queuePostFlushCb(cb: SchedulerJobs) { queueFlush() } -export function flushPreFlushCbs(seen?: CountMap, i = flushIndex) { +export function flushPreFlushCbs( + seen?: CountMap, + // if currently flushing, skip the current job itself + i = isFlushing ? flushIndex + 1 : 0 +) { if (__DEV__) { seen = seen || new Map() }