Skip to content

Commit

Permalink
fix(keep-alive): should not destroy active instance when pruning cache
Browse files Browse the repository at this point in the history
fix #7105
  • Loading branch information
yyx990803 committed Nov 22, 2017
1 parent f93c158 commit 3932a45
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/components/keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/component/component-keep-alive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,34 @@ describe('Component keep-alive', () => {
}).then(done)
})

// #7105
it('should not destroy active instance when pruning cache', done => {
const Foo = {
template: `<div>foo</div>`,
destroyed: jasmine.createSpy('destroyed')
}
const vm = new Vue({
template: `
<div>
<keep-alive :include="include">
<foo/>
</keep-alive>
</div>
`,
data: {
include: ['foo']
},
components: { Foo }
}).$mount()
// condition: a render where a previous component is reused
vm.include = ['foo']
waitForUpdate(() => {
vm.include = ['']
}).then(() => {
expect(Foo.destroyed).not.toHaveBeenCalled()
}).then(done)
})

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

0 comments on commit 3932a45

Please sign in to comment.