fix(scheduler): handle preFlush cb queued inside postFlush cb

fix #3806
This commit is contained in:
Evan You 2021-05-26 14:21:49 -04:00
parent e8ddf86080
commit b57e995edd
2 changed files with 15 additions and 1 deletions

View File

@ -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', () => {

View File

@ -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)
}
}