Browse Source

ensure batcher depletes all queues (fix #2821)

Evan You 10 years ago
parent
commit
e296646624
2 changed files with 35 additions and 3 deletions
  1. 4 3
      src/batcher.js
  2. 31 0
      test/unit/specs/misc_spec.js

+ 4 - 3
src/batcher.js

@@ -36,11 +36,11 @@ function resetBatcherState () {
 
 function flushBatcherQueue () {
   runBatcherQueue(queue)
-  queue.length = 0
   runBatcherQueue(userQueue)
-  // user watchers triggered more internal watchers
+  // user watchers triggered more watchers,
+  // keep flushing until it depletes
   if (queue.length) {
-    runBatcherQueue(queue)
+    return flushBatcherQueue()
   }
   // dev tool hook
   /* istanbul ignore if */
@@ -77,6 +77,7 @@ function runBatcherQueue (queue) {
       }
     }
   }
+  queue.length = 0
 }
 
 /**

+ 31 - 0
test/unit/specs/misc_spec.js

@@ -546,4 +546,35 @@ describe('Misc', function () {
     })
     expect(vm.$el.textContent).toBe('135')
   })
+
+  // #2821
+  it('batcher should keep flushing until all queues are depleted', done => {
+    var spy = jasmine.createSpy()
+    var vm = new Vue({
+      el: document.createElement('div'),
+      template: '<test :prop="model"></test>',
+      data: {
+        model: 0,
+        count: 0
+      },
+      watch: {
+        count: function () {
+          this.model++
+        }
+      },
+      components: {
+        test: {
+          props: ['prop'],
+          watch: {
+            prop: spy
+          }
+        }
+      }
+    })
+    vm.count++
+    Vue.nextTick(function () {
+      expect(spy).toHaveBeenCalled()
+      done()
+    })
+  })
 })