Skip to content

Commit

Permalink
fix(keep-alive): run prune after render for correct active component …
Browse files Browse the repository at this point in the history
…check

fix #7566
  • Loading branch information
yyx990803 committed Mar 12, 2018
1 parent 62d5768 commit 1049461
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/components/keep-alive.js
Expand Up @@ -71,13 +71,13 @@ export default {
}
},

watch: {
include (val: string | RegExp | Array<string>) {
mounted () {
this.$watch('include', val => {
pruneCache(this, name => matches(val, name))
},
exclude (val: string | RegExp | Array<string>) {
})
this.$watch('exclude', val => {
pruneCache(this, name => !matches(val, name))
}
})
},

render () {
Expand Down
29 changes: 29 additions & 0 deletions test/unit/features/component/component-keep-alive.spec.js
Expand Up @@ -393,6 +393,35 @@ describe('Component keep-alive', () => {
}).then(done)
})

it('prune cache on include/exclude change + view switch', done => {
const vm = new Vue({
template: `
<div>
<keep-alive :include="include">
<component :is="view"></component>
</keep-alive>
</div>
`,
data: {
view: 'one',
include: 'one,two'
},
components
}).$mount()

vm.view = 'two'
waitForUpdate(() => {
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
vm.include = 'one'
vm.view = 'one'
}).then(() => {
assertHookCalls(one, [1, 1, 2, 1, 0])
// two should be pruned
assertHookCalls(two, [1, 1, 1, 1, 1])
}).then(done)
})

it('should not prune currently active instance', done => {
const vm = new Vue({
template: `
Expand Down

0 comments on commit 1049461

Please sign in to comment.