Skip to content

Commit fc99e4d

Browse files
authoredApr 15, 2024
fix(Transition): ensure the KeepAlive children unmount w/ out-in mode (#10632)
close #10620
1 parent 53d15d3 commit fc99e4d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
 

‎packages/runtime-core/__tests__/components/BaseTransition.spec.ts

+37
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
h,
88
nextTick,
99
nodeOps,
10+
onUnmounted,
1011
ref,
1112
render,
1213
serialize,
@@ -768,6 +769,42 @@ describe('BaseTransition', () => {
768769
test('w/ KeepAlive', async () => {
769770
await runTestWithKeepAlive(testOutIn)
770771
})
772+
773+
test('w/ KeepAlive + unmount innerChild', async () => {
774+
const unmountSpy = vi.fn()
775+
const includeRef = ref(['TrueBranch'])
776+
const trueComp = {
777+
name: 'TrueBranch',
778+
setup() {
779+
onUnmounted(unmountSpy)
780+
const count = ref(0)
781+
return () => h('div', count.value)
782+
},
783+
}
784+
785+
const toggle = ref(true)
786+
const { props } = mockProps({ mode: 'out-in' }, true /*withKeepAlive*/)
787+
const root = nodeOps.createElement('div')
788+
const App = {
789+
render() {
790+
return h(BaseTransition, props, () => {
791+
return h(
792+
KeepAlive,
793+
{ include: includeRef.value },
794+
toggle.value ? h(trueComp) : h('div'),
795+
)
796+
})
797+
},
798+
}
799+
render(h(App), root)
800+
801+
// trigger toggle
802+
toggle.value = false
803+
includeRef.value = []
804+
805+
await nextTick()
806+
expect(unmountSpy).toHaveBeenCalledTimes(1)
807+
})
771808
})
772809

773810
// #6835

‎packages/runtime-core/src/components/KeepAlive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ const KeepAliveImpl: ComponentOptions = {
254254
pendingCacheKey = null
255255

256256
if (!slots.default) {
257-
return null
257+
return (current = null)
258258
}
259259

260260
const children = slots.default()

0 commit comments

Comments
 (0)
Please sign in to comment.