diff --git a/src/core/observer/scheduler.js b/src/core/observer/scheduler.js index 08182e1b..04d03488 100644 --- a/src/core/observer/scheduler.js +++ b/src/core/observer/scheduler.js @@ -69,10 +69,14 @@ function flushSchedulerQueue () { } } + // reset scheduler before updated hook called + const oldQueue = queue.slice() + resetSchedulerState() + // call updated hooks - index = queue.length + index = oldQueue.length while (index--) { - watcher = queue[index] + watcher = oldQueue[index] vm = watcher.vm if (vm._watcher === watcher && vm._isMounted) { callHook(vm, 'updated') @@ -84,8 +88,6 @@ function flushSchedulerQueue () { if (devtools && config.devtools) { devtools.emit('flush') } - - resetSchedulerState() } /** diff --git a/test/unit/modules/observer/scheduler.spec.js b/test/unit/modules/observer/scheduler.spec.js index b17aaf3d..14219793 100644 --- a/test/unit/modules/observer/scheduler.spec.js +++ b/test/unit/modules/observer/scheduler.spec.js @@ -144,4 +144,35 @@ describe('Scheduler', () => { expect(callOrder).toEqual([1, 2, 3]) }).then(done) }) + + // Github issue #5191 + it('emit should work when updated hook called', done => { + const el = document.createElement('div') + const vm = new Vue({ + template: `