Skip to content

Commit e296646

Browse files
committed
ensure batcher depletes all queues (fix #2821)
1 parent 4ab3c48 commit e296646

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/batcher.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ function resetBatcherState () {
3636

3737
function flushBatcherQueue () {
3838
runBatcherQueue(queue)
39-
queue.length = 0
4039
runBatcherQueue(userQueue)
41-
// user watchers triggered more internal watchers
40+
// user watchers triggered more watchers,
41+
// keep flushing until it depletes
4242
if (queue.length) {
43-
runBatcherQueue(queue)
43+
return flushBatcherQueue()
4444
}
4545
// dev tool hook
4646
/* istanbul ignore if */
@@ -77,6 +77,7 @@ function runBatcherQueue (queue) {
7777
}
7878
}
7979
}
80+
queue.length = 0
8081
}
8182

8283
/**

test/unit/specs/misc_spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,35 @@ describe('Misc', function () {
546546
})
547547
expect(vm.$el.textContent).toBe('135')
548548
})
549+
550+
// #2821
551+
it('batcher should keep flushing until all queues are depleted', done => {
552+
var spy = jasmine.createSpy()
553+
var vm = new Vue({
554+
el: document.createElement('div'),
555+
template: '<test :prop="model"></test>',
556+
data: {
557+
model: 0,
558+
count: 0
559+
},
560+
watch: {
561+
count: function () {
562+
this.model++
563+
}
564+
},
565+
components: {
566+
test: {
567+
props: ['prop'],
568+
watch: {
569+
prop: spy
570+
}
571+
}
572+
}
573+
})
574+
vm.count++
575+
Vue.nextTick(function () {
576+
expect(spy).toHaveBeenCalled()
577+
done()
578+
})
579+
})
549580
})

0 commit comments

Comments
 (0)