Skip to content

Commit

Permalink
fix(runtime-core/scheduler): prevent duplicate queue (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangmingshan committed Aug 3, 2020
1 parent 86cdf66 commit b2a9142
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/runtime-core/__tests__/scheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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)
if ((job.id as number) < 0) hasPendingPreFlushJobs = true
Expand Down

0 comments on commit b2a9142

Please sign in to comment.