From 864ef21a7d679697b5e135d2b81aa71b495b2656 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 11 Oct 2016 23:58:53 -0400 Subject: [PATCH] fix deeply nested keep-alive components not being destroyed (fix #3882) --- src/core/vdom/patch.js | 5 +++- .../component/component-keep-alive.spec.js | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index f655a7b4..6d6444b3 100644 --- a/src/core/vdom/patch.js +++ b/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)) { diff --git a/test/unit/features/component/component-keep-alive.spec.js b/test/unit/features/component/component-keep-alive.spec.js index d140ecf4..ca830522 100644 --- a/test/unit/features/component/component-keep-alive.spec.js +++ b/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 = `
` + one.components = { two } + const vm = new Vue({ + template: `
`, + data: { ok: true }, + components: { + parent: { + template: `
`, + 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