]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(scheduler): handle preFlush cb queued inside postFlush cb
authorEvan You <yyx990803@gmail.com>
Wed, 26 May 2021 18:21:49 +0000 (14:21 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 26 May 2021 18:21:49 +0000 (14:21 -0400)
fix #3806

packages/runtime-core/__tests__/scheduler.spec.ts
packages/runtime-core/src/scheduler.ts

index 3d95be5edb3ff60a6924595864f6bc3b121035fd..953f928158db21a88270b948708679fa289e723a 100644 (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', () => {
index 8ab5a23108d993089ee15092d22afb92ce033c76..5729afbbec43025ac72fcedef560f41c8c2acd17 100644 (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)
     }
   }