Browse Source

fix deeply nested keep-alive components not being destroyed (fix #3882)

dev
Evan You 8 years ago
parent
commit
864ef21a7d
  1. 5
      src/core/vdom/patch.js
  2. 25
      test/unit/features/component/component-keep-alive.spec.js

5
src/core/vdom/patch.js

@ -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)) {

25
test/unit/features/component/component-keep-alive.spec.js

@ -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

Loading…
Cancel
Save