Skip to content

Commit

Permalink
fix(Transition): ensure the KeepAlive children unmount w/ out-in mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Apr 15, 2024
1 parent 53d15d3 commit fc99e4d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions packages/runtime-core/__tests__/components/BaseTransition.spec.ts
Expand Up @@ -7,6 +7,7 @@ import {
h,
nextTick,
nodeOps,
onUnmounted,
ref,
render,
serialize,
Expand Down Expand Up @@ -768,6 +769,42 @@ describe('BaseTransition', () => {
test('w/ KeepAlive', async () => {
await runTestWithKeepAlive(testOutIn)
})

test('w/ KeepAlive + unmount innerChild', async () => {
const unmountSpy = vi.fn()
const includeRef = ref(['TrueBranch'])
const trueComp = {
name: 'TrueBranch',
setup() {
onUnmounted(unmountSpy)
const count = ref(0)
return () => h('div', count.value)
},
}

const toggle = ref(true)
const { props } = mockProps({ mode: 'out-in' }, true /*withKeepAlive*/)
const root = nodeOps.createElement('div')
const App = {
render() {
return h(BaseTransition, props, () => {
return h(
KeepAlive,
{ include: includeRef.value },
toggle.value ? h(trueComp) : h('div'),
)
})
},
}
render(h(App), root)

// trigger toggle
toggle.value = false
includeRef.value = []

await nextTick()
expect(unmountSpy).toHaveBeenCalledTimes(1)
})
})

// #6835
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/KeepAlive.ts
Expand Up @@ -254,7 +254,7 @@ const KeepAliveImpl: ComponentOptions = {
pendingCacheKey = null

if (!slots.default) {
return null
return (current = null)
}

const children = slots.default()
Expand Down

0 comments on commit fc99e4d

Please sign in to comment.