From c6bbc4a75ec37c94a85716840583043b0532c4ac Mon Sep 17 00:00:00 2001 From: edison Date: Wed, 5 Nov 2025 11:11:46 +0800 Subject: [PATCH] feat(runtime-vapor): vapor transition work with vapor keep-alive (#14050) --- .../__tests__/transition.spec.ts | 20 ++++++++++- .../vapor-e2e-test/transition/App.vue | 35 +++++++++++++++++++ .../runtime-vapor/src/components/KeepAlive.ts | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages-private/vapor-e2e-test/__tests__/transition.spec.ts b/packages-private/vapor-e2e-test/__tests__/transition.spec.ts index 0bfc30598c..0babdd8b8d 100644 --- a/packages-private/vapor-e2e-test/__tests__/transition.spec.ts +++ b/packages-private/vapor-e2e-test/__tests__/transition.spec.ts @@ -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('
0
') + + 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', () => {}) diff --git a/packages-private/vapor-e2e-test/transition/App.vue b/packages-private/vapor-e2e-test/transition/App.vue index 4855098243..e437e07456 100644 --- a/packages-private/vapor-e2e-test/transition/App.vue +++ b/packages-private/vapor-e2e-test/transition/App.vue @@ -7,6 +7,7 @@ import { VaporTransition, createIf, template, + onUnmounted, } from 'vue' const show = ref(true) const toggle = ref(true) @@ -28,6 +29,8 @@ let calls = { showLeaveCancel: [], showAppear: [], notEnter: [], + + unmount: [], } window.getCalls = key => calls[key] window.resetCalls = key => (calls[key] = []) @@ -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('
0
')() + }, +}) +const includeRef = ref(['TrueBranch']) +const click = () => { + toggle.value = !toggle.value + if (toggle.value) { + includeRef.value = ['TrueBranch'] + } else { + includeRef.value = [] + } +}