Skip to content

Commit 354c2f4

Browse files
committed
fix keep-alive cache incorrectly pruned with transition mode="out-in" (fix #5346)
1 parent bbec076 commit 354c2f4

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

src/platforms/web/runtime/components/transition.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ export function extractTransitionData (comp: Component): Object {
5353
}
5454

5555
function placeholder (h: Function, rawChild: VNode): ?VNode {
56-
return /\d-keep-alive$/.test(rawChild.tag)
57-
? h('keep-alive')
58-
: null
56+
if (/\d-keep-alive$/.test(rawChild.tag)) {
57+
return h('keep-alive', {
58+
props: rawChild.componentOptions.propsData
59+
})
60+
}
5961
}
6062

6163
function hasParentTransition (vnode: VNode): ?boolean {

test/unit/features/component/component-keep-alive.spec.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,91 @@ describe('Component keep-alive', () => {
497497
}).then(done)
498498
})
499499

500+
it('with transition-mode out-in + include', done => {
501+
let next
502+
const vm = new Vue({
503+
template: `<div>
504+
<transition name="test" mode="out-in" @after-leave="afterLeave">
505+
<keep-alive include="one">
506+
<component :is="view" class="test"></component>
507+
</keep-alive>
508+
</transition>
509+
</div>`,
510+
data: {
511+
view: 'one'
512+
},
513+
components,
514+
methods: {
515+
afterLeave () {
516+
next()
517+
}
518+
}
519+
}).$mount(el)
520+
expect(vm.$el.textContent).toBe('one')
521+
assertHookCalls(one, [1, 1, 1, 0, 0])
522+
assertHookCalls(two, [0, 0, 0, 0, 0])
523+
vm.view = 'two'
524+
waitForUpdate(() => {
525+
expect(vm.$el.innerHTML).toBe(
526+
'<div class="test test-leave test-leave-active">one</div><!---->'
527+
)
528+
assertHookCalls(one, [1, 1, 1, 1, 0])
529+
assertHookCalls(two, [0, 0, 0, 0, 0])
530+
}).thenWaitFor(nextFrame).then(() => {
531+
expect(vm.$el.innerHTML).toBe(
532+
'<div class="test test-leave-active test-leave-to">one</div><!---->'
533+
)
534+
}).thenWaitFor(_next => { next = _next }).then(() => {
535+
expect(vm.$el.innerHTML).toBe('<!---->')
536+
}).thenWaitFor(nextFrame).then(() => {
537+
expect(vm.$el.innerHTML).toBe(
538+
'<div class="test test-enter test-enter-active">two</div>'
539+
)
540+
assertHookCalls(one, [1, 1, 1, 1, 0])
541+
assertHookCalls(two, [1, 1, 0, 0, 0])
542+
}).thenWaitFor(nextFrame).then(() => {
543+
expect(vm.$el.innerHTML).toBe(
544+
'<div class="test test-enter-active test-enter-to">two</div>'
545+
)
546+
}).thenWaitFor(duration + buffer).then(() => {
547+
expect(vm.$el.innerHTML).toBe(
548+
'<div class="test">two</div>'
549+
)
550+
assertHookCalls(one, [1, 1, 1, 1, 0])
551+
assertHookCalls(two, [1, 1, 0, 0, 0])
552+
}).then(() => {
553+
vm.view = 'one'
554+
}).then(() => {
555+
expect(vm.$el.innerHTML).toBe(
556+
'<div class="test test-leave test-leave-active">two</div><!---->'
557+
)
558+
assertHookCalls(one, [1, 1, 1, 1, 0])
559+
assertHookCalls(two, [1, 1, 0, 0, 1])
560+
}).thenWaitFor(nextFrame).then(() => {
561+
expect(vm.$el.innerHTML).toBe(
562+
'<div class="test test-leave-active test-leave-to">two</div><!---->'
563+
)
564+
}).thenWaitFor(_next => { next = _next }).then(() => {
565+
expect(vm.$el.innerHTML).toBe('<!---->')
566+
}).thenWaitFor(nextFrame).then(() => {
567+
expect(vm.$el.innerHTML).toBe(
568+
'<div class="test test-enter test-enter-active">one</div>'
569+
)
570+
assertHookCalls(one, [1, 1, 2, 1, 0])
571+
assertHookCalls(two, [1, 1, 0, 0, 1])
572+
}).thenWaitFor(nextFrame).then(() => {
573+
expect(vm.$el.innerHTML).toBe(
574+
'<div class="test test-enter-active test-enter-to">one</div>'
575+
)
576+
}).thenWaitFor(duration + buffer).then(() => {
577+
expect(vm.$el.innerHTML).toBe(
578+
'<div class="test">one</div>'
579+
)
580+
assertHookCalls(one, [1, 1, 2, 1, 0])
581+
assertHookCalls(two, [1, 1, 0, 0, 1])
582+
}).then(done)
583+
})
584+
500585
it('with transition-mode in-out', done => {
501586
let next
502587
const vm = new Vue({

0 commit comments

Comments
 (0)