Skip to content

Commit 6e96a65

Browse files
committed
adjust component destroy logic (really fix #3882)
1 parent 6ab10c0 commit 6e96a65

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/core/instance/lifecycle.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export function lifecycleMixin (Vue: Class<Component>) {
187187
if (vm.$el) {
188188
vm.$el.__vue__ = null
189189
}
190+
// invoke destroy hooks on current rendered tree
191+
vm.__patch__(vm._vnode, null)
190192
}
191193
}
192194

src/core/vdom/patch.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ export function createPatchFunction (backend) {
202202
if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode)
203203
for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode)
204204
}
205-
if (isDef(i = vnode.child) && (
206-
!data.keepAlive ||
207-
vnode.context._isBeingDestroyed
208-
)) {
209-
invokeDestroyHook(i._vnode)
210-
}
211205
if (isDef(i = vnode.children)) {
212206
for (j = 0; j < vnode.children.length; ++j) {
213207
invokeDestroyHook(vnode.children[j])
@@ -457,6 +451,11 @@ export function createPatchFunction (backend) {
457451
}
458452

459453
return function patch (oldVnode, vnode, hydrating, removeOnly) {
454+
if (!vnode) {
455+
if (oldVnode) invokeDestroyHook(oldVnode)
456+
return
457+
}
458+
460459
let elm, parent
461460
let isInitialPatch = false
462461
const insertedVnodeQueue = []

0 commit comments

Comments
 (0)