Skip to content

Commit

Permalink
fix deeply nested keep-alive components not being destroyed (fix vuej…
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 12, 2016
1 parent 03ea9f0 commit 864ef21
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ export function createPatchFunction (backend) {
if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode)
for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode)
}
if (isDef(i = vnode.child) && !data.keepAlive) {
if (isDef(i = vnode.child) && (
!data.keepAlive ||
vnode.context._isBeingDestroyed
)) {
invokeDestroyHook(i._vnode)
}
if (isDef(i = vnode.children)) {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/features/component/component-keep-alive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ describe('Component keep-alive', () => {
}).then(done)
})

// #3882
it('deeply nested keep-alive should be destroyed properly', done => {
one.template = `<div><keep-alive><two></two></keep-alive></div>`
one.components = { two }
const vm = new Vue({
template: `<div><parent v-if="ok"></parent></div>`,
data: { ok: true },
components: {
parent: {
template: `<div><keep-alive><one></one></keep-alive></div>`,
components: { one }
}
}
}).$mount()

assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])

vm.ok = false
waitForUpdate(() => {
assertHookCalls(one, [1, 1, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 1])
}).then(done)
})

if (!isIE9) {
it('with transition-mode out-in', done => {
let next
Expand Down

0 comments on commit 864ef21

Please sign in to comment.