diff --git a/src/core/components/keep-alive.js b/src/core/components/keep-alive.js index d0ebe0a917..53dd264aaa 100644 --- a/src/core/components/keep-alive.js +++ b/src/core/components/keep-alive.js @@ -41,7 +41,7 @@ function pruneCacheEntry ( current?: VNode ) { const cached = cache[key] - if (cached && cached !== current) { + if (cached && (!current || cached.tag !== current.tag)) { cached.componentInstance.$destroy() } cache[key] = null diff --git a/test/unit/features/component/component-keep-alive.spec.js b/test/unit/features/component/component-keep-alive.spec.js index dbae84fe97..b89fbdc9d6 100644 --- a/test/unit/features/component/component-keep-alive.spec.js +++ b/test/unit/features/component/component-keep-alive.spec.js @@ -656,6 +656,34 @@ describe('Component keep-alive', () => { }).then(done) }) + // #7105 + it('should not destroy active instance when pruning cache', done => { + const Foo = { + template: `