Skip to content

Commit 5966549

Browse files
yyx990803aJean
authored andcommitted
fix(transition-group): fix activeInstance regression
fix vuejs#9151
1 parent 1f8be2e commit 5966549

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/core/instance/lifecycle.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ import {
2121
export let activeInstance: any = null
2222
export let isUpdatingChildComponent: boolean = false
2323

24+
export function setActiveInstance(vm: Component) {
25+
const prevActiveInstance = activeInstance
26+
activeInstance = vm
27+
return () => {
28+
activeInstance = prevActiveInstance
29+
}
30+
}
31+
2432
export function initLifecycle (vm: Component) {
2533
const options = vm.$options
2634

@@ -52,8 +60,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
5260
const vm: Component = this
5361
const prevEl = vm.$el
5462
const prevVnode = vm._vnode
55-
const prevActiveInstance = activeInstance
56-
activeInstance = vm
63+
const restoreActiveInstance = setActiveInstance(vm)
5764
vm._vnode = vnode
5865
// Vue.prototype.__patch__ is injected in entry points
5966
// based on the rendering backend used.
@@ -64,7 +71,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
6471
// updates
6572
vm.$el = vm.__patch__(prevVnode, vnode)
6673
}
67-
activeInstance = prevActiveInstance
74+
restoreActiveInstance()
6875
// update __vue__ reference
6976
if (prevEl) {
7077
prevEl.__vue__ = null

src/platforms/web/runtime/components/transition-group.js

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import { warn, extend } from 'core/util/index'
1515
import { addClass, removeClass } from '../class-util'
1616
import { transitionProps, extractTransitionData } from './transition'
17+
import { setActiveInstance } from 'core/instance/lifecycle'
1718

1819
import {
1920
hasTransition,
@@ -36,6 +37,7 @@ export default {
3637
beforeMount () {
3738
const update = this._update
3839
this._update = (vnode, hydrating) => {
40+
const restoreActiveInstance = setActiveInstance(this)
3941
// force removing pass
4042
this.__patch__(
4143
this._vnode,
@@ -44,6 +46,7 @@ export default {
4446
true // removeOnly (!important, avoids unnecessary moves)
4547
)
4648
this._vnode = this.kept
49+
restoreActiveInstance()
4750
update.call(this, vnode, hydrating)
4851
}
4952
},

0 commit comments

Comments
 (0)