Skip to content

Commit

Permalink
fix(scheduler): handle preFlush cb queued inside postFlush cb
Browse files Browse the repository at this point in the history
fix #3806
  • Loading branch information
yyx990803 committed May 26, 2021
1 parent e8ddf86 commit b57e995
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/runtime-core/__tests__/scheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ describe('scheduler', () => {
await nextTick()
expect(calls).toEqual(['cb1', 'cb2', 'job1'])
})

// #3806
it('queue preFlushCb inside postFlushCb', async () => {
const cb = jest.fn()
queuePostFlushCb(() => {
queuePreFlushCb(cb)
})
await nextTick()
expect(cb).toHaveBeenCalled()
})
})

describe('queuePostFlushCb', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ function flushJobs(seen?: CountMap) {
currentFlushPromise = null
// some postFlushCb queued jobs!
// keep flushing until it drains.
if (queue.length || pendingPostFlushCbs.length) {
if (
queue.length ||
pendingPreFlushCbs.length ||
pendingPostFlushCbs.length
) {
flushJobs(seen)
}
}
Expand Down

0 comments on commit b57e995

Please sign in to comment.