Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/components/keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default {
keys.push(key)
// prune oldest entry
if (this.max && keys.length > parseInt(this.max)) {
pruneCacheEntry(cache, keys[0], keys, this._vnode)
pruneCacheEntry(cache, keys[0], keys, vnode)
}
}

Expand Down
50 changes: 50 additions & 0 deletions test/unit/features/component/component-keep-alive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,56 @@ describe('Component keep-alive', () => {
}).then(done)
})

// #10015
it('prune cache on max set 1', done => {
const spyA = jasmine.createSpy()
const spyB = jasmine.createSpy()
const spyAD = jasmine.createSpy()
const spyBD = jasmine.createSpy()

function assertCount (calls) {
expect([
spyA.calls.count(),
spyAD.calls.count(),
spyB.calls.count(),
spyBD.calls.count(),
]).toEqual(calls)
}

const vm = new Vue({
template: `
<keep-alive max="1">
<component :is="n"></component>
</keep-alive>
`,
data: {
n: 'aa'
},
components: {
aa: {
template: '<div>a</div>',
created: spyA,
destroyed: spyAD
},
bb: {
template: '<div>bbb</div>',
created: spyB,
destroyed: spyBD
}
}
}).$mount()

assertCount([1, 0, 0, 0])
vm.n = 'bb'
waitForUpdate(() => {
// should prune A because max cache reached
assertCount([1, 1, 1, 0])
vm.n = 'aa'
}).then(() => {
assertCount([2, 1, 1, 1])
}).then(done)
})

it('should warn unknown component inside', () => {
new Vue({
template: `<keep-alive><foo/></keep-alive>`
Expand Down