From 8a2dbf50105ea729125a42fecfe2c2f0371d7836 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 5 Dec 2018 17:33:39 -0500 Subject: [PATCH] fix(transition-group): fix activeInstance regression fix #9151 --- src/core/instance/lifecycle.js | 13 ++++++++++--- .../web/runtime/components/transition-group.js | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/instance/lifecycle.js b/src/core/instance/lifecycle.js index 5521e03ed35..8d687b15725 100644 --- a/src/core/instance/lifecycle.js +++ b/src/core/instance/lifecycle.js @@ -21,6 +21,14 @@ import { export let activeInstance: any = null export let isUpdatingChildComponent: boolean = false +export function setActiveInstance(vm: Component) { + const prevActiveInstance = activeInstance + activeInstance = vm + return () => { + activeInstance = prevActiveInstance + } +} + export function initLifecycle (vm: Component) { const options = vm.$options @@ -52,8 +60,7 @@ export function lifecycleMixin (Vue: Class) { const vm: Component = this const prevEl = vm.$el const prevVnode = vm._vnode - const prevActiveInstance = activeInstance - activeInstance = vm + const restoreActiveInstance = setActiveInstance(vm) vm._vnode = vnode // Vue.prototype.__patch__ is injected in entry points // based on the rendering backend used. @@ -64,7 +71,7 @@ export function lifecycleMixin (Vue: Class) { // updates vm.$el = vm.__patch__(prevVnode, vnode) } - activeInstance = prevActiveInstance + restoreActiveInstance() // update __vue__ reference if (prevEl) { prevEl.__vue__ = null diff --git a/src/platforms/web/runtime/components/transition-group.js b/src/platforms/web/runtime/components/transition-group.js index 1d960a208be..084f394cd0d 100644 --- a/src/platforms/web/runtime/components/transition-group.js +++ b/src/platforms/web/runtime/components/transition-group.js @@ -14,6 +14,7 @@ import { warn, extend } from 'core/util/index' import { addClass, removeClass } from '../class-util' import { transitionProps, extractTransitionData } from './transition' +import { setActiveInstance } from 'core/instance/lifecycle' import { hasTransition, @@ -36,6 +37,7 @@ export default { beforeMount () { const update = this._update this._update = (vnode, hydrating) => { + const restoreActiveInstance = setActiveInstance(this) // force removing pass this.__patch__( this._vnode, @@ -44,6 +46,7 @@ export default { true // removeOnly (!important, avoids unnecessary moves) ) this._vnode = this.kept + restoreActiveInstance() update.call(this, vnode, hydrating) } },