diff --git a/packages/runtime-core/__tests__/scheduler.spec.ts b/packages/runtime-core/__tests__/scheduler.spec.ts index 3d95be5e..953f9281 100644 --- a/packages/runtime-core/__tests__/scheduler.spec.ts +++ b/packages/runtime-core/__tests__/scheduler.spec.ts @@ -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', () => { diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 8ab5a231..5729afbb 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -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) } }