Skip to content

Commit

Permalink
fix(transition-group): fix activeInstance regression
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 5, 2018
1 parent 0ed0aad commit 8a2dbf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/instance/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -52,8 +60,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
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.
Expand All @@ -64,7 +71,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
// updates
vm.$el = vm.__patch__(prevVnode, vnode)
}
activeInstance = prevActiveInstance
restoreActiveInstance()
// update __vue__ reference
if (prevEl) {
prevEl.__vue__ = null
Expand Down
3 changes: 3 additions & 0 deletions src/platforms/web/runtime/components/transition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -44,6 +46,7 @@ export default {
true // removeOnly (!important, avoids unnecessary moves)
)
this._vnode = this.kept
restoreActiveInstance()
update.call(this, vnode, hydrating)
}
},
Expand Down

0 comments on commit 8a2dbf5

Please sign in to comment.