From 43e2a72900b96870fe6f16248ecec50ff58278df Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 22 Jun 2021 04:58:43 +0800 Subject: [PATCH] fix(Suspense): fallback should work with transition (#3968) fix #3963 --- .../runtime-core/src/components/Suspense.ts | 3 +- packages/vue/__tests__/Transition.spec.ts | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/components/Suspense.ts b/packages/runtime-core/src/components/Suspense.ts index d5d544469f3..57ba92c6fcd 100644 --- a/packages/runtime-core/src/components/Suspense.ts +++ b/packages/runtime-core/src/components/Suspense.ts @@ -551,6 +551,8 @@ function createSuspenseBoundary( if (delayEnter) { activeBranch!.transition!.afterLeave = mountFallback } + suspense.isInFallback = true + // unmount current active branch unmount( activeBranch!, @@ -559,7 +561,6 @@ function createSuspenseBoundary( true // shouldRemove ) - suspense.isInFallback = true if (!delayEnter) { mountFallback() } diff --git a/packages/vue/__tests__/Transition.spec.ts b/packages/vue/__tests__/Transition.spec.ts index eb56c4fd39b..1465f9c9ece 100644 --- a/packages/vue/__tests__/Transition.spec.ts +++ b/packages/vue/__tests__/Transition.spec.ts @@ -1325,6 +1325,69 @@ describe('e2e: Transition', () => { }, E2E_TIMEOUT ) + + // #3963 + test( + 'Suspense fallback should work with transition', + async () => { + await page().evaluate(() => { + const { createApp, shallowRef, h } = (window as any).Vue + + const One = { + template: `
{{ msg }}
`, + setup() { + return new Promise(_resolve => { + // @ts-ignore + window.resolve = () => + _resolve({ + msg: 'success' + }) + }) + } + } + + createApp({ + template: ` +
+ + + + + + +
+ + `, + setup: () => { + const view = shallowRef(null) + const click = () => { + view.value = view.value ? null : h(One) + } + return { view, click } + } + }).mount('#app') + }) + + expect(await html('#container')).toBe('') + + await click('#toggleBtn') + await nextFrame() + expect(await html('#container')).toBe('
Loading...
') + + await page().evaluate(() => { + // @ts-ignore + window.resolve() + }) + + await transitionFinish(duration * 2) + expect(await html('#container')).toBe('
success
') + }, + E2E_TIMEOUT + ) }) describe('transition with v-show', () => {