Skip to content

Commit

Permalink
fix(runtime-core): avoid double firing when mounting inside a watcher…
Browse files Browse the repository at this point in the history
… callback

fix #6614
  • Loading branch information
yyx990803 committed Sep 8, 2022
1 parent 6493da5 commit 6aaf8ef
Show file tree
Hide file tree
Showing 2 changed files with 17 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 @@ -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)
})
})
6 changes: 5 additions & 1 deletion packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 6aaf8ef

Please sign in to comment.