Skip to content

Commit 43be5c6

Browse files
committed
fix(Transition): re-fix vuejs#10620
1 parent 47453f1 commit 43be5c6

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

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

-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
h,
88
nextTick,
99
nodeOps,
10-
onUnmounted,
1110
ref,
1211
render,
1312
serialize,
@@ -769,42 +768,6 @@ describe('BaseTransition', () => {
769768
test('w/ KeepAlive', async () => {
770769
await runTestWithKeepAlive(testOutIn)
771770
})
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-
})
808771
})
809772

810773
// #6835

packages/runtime-core/src/components/BaseTransition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const BaseTransitionImpl: ComponentOptions = {
224224
// update old tree's hooks in case of dynamic transition
225225
setTransitionHooks(oldInnerChild, leavingHooks)
226226
// switching between different views
227-
if (mode === 'out-in') {
227+
if (mode === 'out-in' && innerChild.type !== Comment) {
228228
state.isLeaving = true
229229
// return placeholder node and queue update when leave finishes
230230
leavingHooks.afterLeave = () => {

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 (current = null)
257+
return null
258258
}
259259

260260
const children = slots.default()

packages/vue/__tests__/e2e/Transition.spec.ts

+58
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
22
import path from 'node:path'
33
import { Transition, createApp, h, nextTick, ref } from 'vue'
4+
import { expect } from 'vitest'
45

56
describe('e2e: Transition', () => {
67
const { page, html, classList, isVisible, timeout, nextFrame, click } =
@@ -1214,6 +1215,63 @@ describe('e2e: Transition', () => {
12141215
},
12151216
E2E_TIMEOUT,
12161217
)
1218+
1219+
test(
1220+
'w/ KeepAlive + unmount innerChild',
1221+
async () => {
1222+
const unmountSpy = vi.fn()
1223+
await page().exposeFunction('unmountSpy', unmountSpy)
1224+
await page().evaluate(() => {
1225+
const { unmountSpy } = window as any
1226+
const { createApp, ref, h, onUnmounted } = (window as any).Vue
1227+
createApp({
1228+
template: `
1229+
<div id="container">
1230+
<transition mode="out-in">
1231+
<KeepAlive :include="includeRef">
1232+
<TrueBranch v-if="toggle"></TrueBranch>
1233+
</KeepAlive>
1234+
</transition>
1235+
</div>
1236+
<button id="toggleBtn" @click="click">button</button>
1237+
`,
1238+
components: {
1239+
TrueBranch: {
1240+
name: 'TrueBranch',
1241+
setup() {
1242+
onUnmounted(unmountSpy)
1243+
const count = ref(0)
1244+
return () => h('div', count.value)
1245+
},
1246+
},
1247+
},
1248+
setup: () => {
1249+
const includeRef = ref(['TrueBranch'])
1250+
const toggle = ref(true)
1251+
const click = () => {
1252+
toggle.value = !toggle.value
1253+
if (toggle.value) {
1254+
includeRef.value = ['TrueBranch']
1255+
} else {
1256+
includeRef.value = []
1257+
}
1258+
}
1259+
return { toggle, click, unmountSpy, includeRef }
1260+
},
1261+
}).mount('#app')
1262+
})
1263+
1264+
await transitionFinish()
1265+
expect(await html('#container')).toBe('<div>0</div>')
1266+
1267+
await click('#toggleBtn')
1268+
1269+
await transitionFinish()
1270+
expect(await html('#container')).toBe('<!--v-if-->')
1271+
expect(unmountSpy).toBeCalledTimes(1)
1272+
},
1273+
E2E_TIMEOUT,
1274+
)
12171275
})
12181276

12191277
describe('transition with Suspense', () => {

0 commit comments

Comments
 (0)