Skip to content
Merged
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
20 changes: 19 additions & 1 deletion packages-private/vapor-e2e-test/__tests__/transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,25 @@ describe('vapor transition', () => {
)
})

describe.todo('transition with KeepAlive', () => {})
describe('transition with KeepAlive', () => {
test('unmount innerChild (out-in mode)', async () => {
const btnSelector = '.keep-alive > button'
const containerSelector = '.keep-alive > div'

await transitionFinish()
expect(await html(containerSelector)).toBe('<div>0</div>')

await click(btnSelector)

await transitionFinish()
expect(await html(containerSelector)).toBe('')
const calls = await page().evaluate(() => {
return (window as any).getCalls('unmount')
})
expect(calls).toStrictEqual(['TrueBranch'])
})
})

describe.todo('transition with Suspense', () => {})
describe.todo('transition with Teleport', () => {})

Expand Down
35 changes: 35 additions & 0 deletions packages-private/vapor-e2e-test/transition/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
VaporTransition,
createIf,
template,
onUnmounted,
} from 'vue'
const show = ref(true)
const toggle = ref(true)
Expand All @@ -28,6 +29,8 @@ let calls = {
showLeaveCancel: [],
showAppear: [],
notEnter: [],

unmount: [],
}
window.getCalls = key => calls[key]
window.resetCalls = key => (calls[key] = [])
Expand Down Expand Up @@ -90,6 +93,25 @@ const viewInOut = shallowRef(SimpleOne)
function changeViewInOut() {
viewInOut.value = viewInOut.value === SimpleOne ? Two : SimpleOne
}

const TrueBranch = defineVaporComponent({
name: 'TrueBranch',
setup() {
onUnmounted(() => {
calls.unmount.push('TrueBranch')
})
return template('<div>0</div>')()
},
})
const includeRef = ref(['TrueBranch'])
const click = () => {
toggle.value = !toggle.value
if (toggle.value) {
includeRef.value = ['TrueBranch']
} else {
includeRef.value = []
}
}
</script>

<template>
Expand Down Expand Up @@ -481,6 +503,19 @@ function changeViewInOut() {
</div>
<!-- mode end -->

<!-- with keep-alive -->
<div class="keep-alive">
<div>
<transition mode="out-in">
<KeepAlive :include="includeRef">
<TrueBranch v-if="toggle"></TrueBranch>
</KeepAlive>
</transition>
</div>
<button @click="click">button</button>
</div>
<!-- with keep-alive end -->

<!-- vdom interop -->
<div class="vdom">
<button @click="toggleVdom = !toggleVdom">toggle vdom component</button>
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-vapor/src/components/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const VaporKeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
}

keepAliveInstance.deactivate = instance => {
current = undefined
deactivate(instance, storageContainer)
}

Expand Down
Loading