Skip to content

Commit 43e2a72

Browse files
authored
fix(Suspense): fallback should work with transition (#3968)
fix #3963
1 parent 08e9322 commit 43e2a72

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ function createSuspenseBoundary(
551551
if (delayEnter) {
552552
activeBranch!.transition!.afterLeave = mountFallback
553553
}
554+
suspense.isInFallback = true
555+
554556
// unmount current active branch
555557
unmount(
556558
activeBranch!,
@@ -559,7 +561,6 @@ function createSuspenseBoundary(
559561
true // shouldRemove
560562
)
561563

562-
suspense.isInFallback = true
563564
if (!delayEnter) {
564565
mountFallback()
565566
}

packages/vue/__tests__/Transition.spec.ts

+63
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,69 @@ describe('e2e: Transition', () => {
13251325
},
13261326
E2E_TIMEOUT
13271327
)
1328+
1329+
// #3963
1330+
test(
1331+
'Suspense fallback should work with transition',
1332+
async () => {
1333+
await page().evaluate(() => {
1334+
const { createApp, shallowRef, h } = (window as any).Vue
1335+
1336+
const One = {
1337+
template: `<div>{{ msg }}</div>`,
1338+
setup() {
1339+
return new Promise(_resolve => {
1340+
// @ts-ignore
1341+
window.resolve = () =>
1342+
_resolve({
1343+
msg: 'success'
1344+
})
1345+
})
1346+
}
1347+
}
1348+
1349+
createApp({
1350+
template: `
1351+
<div id="container">
1352+
<transition mode="out-in">
1353+
<Suspense :timeout="0">
1354+
<template #default>
1355+
<component :is="view" />
1356+
</template>
1357+
<template #fallback>
1358+
<div>Loading...</div>
1359+
</template>
1360+
</Suspense>
1361+
</transition>
1362+
</div>
1363+
<button id="toggleBtn" @click="click">button</button>
1364+
`,
1365+
setup: () => {
1366+
const view = shallowRef(null)
1367+
const click = () => {
1368+
view.value = view.value ? null : h(One)
1369+
}
1370+
return { view, click }
1371+
}
1372+
}).mount('#app')
1373+
})
1374+
1375+
expect(await html('#container')).toBe('<!---->')
1376+
1377+
await click('#toggleBtn')
1378+
await nextFrame()
1379+
expect(await html('#container')).toBe('<div class="">Loading...</div>')
1380+
1381+
await page().evaluate(() => {
1382+
// @ts-ignore
1383+
window.resolve()
1384+
})
1385+
1386+
await transitionFinish(duration * 2)
1387+
expect(await html('#container')).toBe('<div class="">success</div>')
1388+
},
1389+
E2E_TIMEOUT
1390+
)
13281391
})
13291392

13301393
describe('transition with v-show', () => {

0 commit comments

Comments
 (0)