Skip to content

Commit accf839

Browse files
authored
fix(Transition): re-fix #10620 (#10832)
revert #10632 re-fix #10620 close #10827
1 parent 09b4df8 commit accf839

File tree

5 files changed

+60
-40
lines changed

5 files changed

+60
-40
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/__tests__/hmr.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ describe('hot module replacement', () => {
356356
triggerEvent(root.children[1] as TestElement, 'click')
357357
await nextTick()
358358
await new Promise(r => setTimeout(r, 0))
359-
expect(serializeInner(root)).toBe(`<button></button><!---->`)
359+
expect(serializeInner(root)).toBe(`<button></button><!--v-if-->`)
360360
expect(unmountSpy).toHaveBeenCalledTimes(1)
361361
expect(mountSpy).toHaveBeenCalledTimes(1)
362362
expect(activeSpy).toHaveBeenCalledTimes(1)

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

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

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

0 commit comments

Comments
 (0)