From a0f5d154e8965cd3f69ff85b7829a1a6ca0df9a1 Mon Sep 17 00:00:00 2001 From: Yang Mingshan Date: Tue, 4 Aug 2020 00:03:18 +0800 Subject: [PATCH] fix(runtime-core/scheduler): prevent duplicate queue --- packages/runtime-core/__tests__/scheduler.spec.ts | 12 ++++++++++++ packages/runtime-core/src/scheduler.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/scheduler.spec.ts b/packages/runtime-core/__tests__/scheduler.spec.ts index 80ba290eb64..cf83e169e78 100644 --- a/packages/runtime-core/__tests__/scheduler.spec.ts +++ b/packages/runtime-core/__tests__/scheduler.spec.ts @@ -353,4 +353,16 @@ describe('scheduler', () => { await nextTick() expect(count).toBe(5) }) + + test('should prevent duplicate queue', async () => { + let count = 0 + const job = () => { + count++ + } + job.cb = true + queueJob(job) + queueJob(job) + await nextTick() + expect(count).toBe(1) + }) }) diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index a6933bcccd5..a935a22fe48 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -44,7 +44,7 @@ export function queueJob(job: SchedulerJob) { // ensure it doesn't end up in an infinite loop. if ( !queue.length || - !queue.includes(job, job.cb ? flushIndex + 1 : flushIndex) + !queue.includes(job, isFlushing && job.cb ? flushIndex + 1 : flushIndex) ) { queue.push(job) queueFlush()