From 65f3fe273127a8b68e1222fbb306d28d85f01757 Mon Sep 17 00:00:00 2001 From: edison Date: Mon, 4 Dec 2023 16:41:55 +0800 Subject: [PATCH] fix(runtime-core): Suspense get anchor properly in Transition (#9309) close #8105 --- .../runtime-core/src/components/Suspense.ts | 10 ++- packages/vue/__tests__/e2e/Transition.spec.ts | 66 +++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/components/Suspense.ts b/packages/runtime-core/src/components/Suspense.ts index ddf21dd2ed4..5e5521b09be 100644 --- a/packages/runtime-core/src/components/Suspense.ts +++ b/packages/runtime-core/src/components/Suspense.ts @@ -504,7 +504,12 @@ function createSuspenseBoundary( if (delayEnter) { activeBranch!.transition!.afterLeave = () => { if (pendingId === suspense.pendingId) { - move(pendingBranch!, container, anchor, MoveType.ENTER) + move( + pendingBranch!, + container, + next(activeBranch!), + MoveType.ENTER + ) queuePostFlushCb(effects) } } @@ -577,7 +582,6 @@ function createSuspenseBoundary( // invoke @fallback event triggerEvent(vnode, 'onFallback') - const anchor = next(activeBranch!) const mountFallback = () => { if (!suspense.isInFallback) { return @@ -587,7 +591,7 @@ function createSuspenseBoundary( null, fallbackVNode, container, - anchor, + next(activeBranch!), parentComponent, null, // fallback tree will not have suspense context isSVG, diff --git a/packages/vue/__tests__/e2e/Transition.spec.ts b/packages/vue/__tests__/e2e/Transition.spec.ts index 38fdf53cf4f..58797d82e73 100644 --- a/packages/vue/__tests__/e2e/Transition.spec.ts +++ b/packages/vue/__tests__/e2e/Transition.spec.ts @@ -1586,6 +1586,72 @@ describe('e2e: Transition', () => { expect(barMountSpy).toBeCalledTimes(1) expect(barMountSpy).toHaveBeenNthCalledWith(1, true, false, true) }) + + // #8105 + test( + 'trigger again when transition is not finished', + async () => { + await page().evaluate(duration => { + const { createApp, shallowRef, h } = (window as any).Vue + const One = { + async setup() { + return () => h('div', { class: 'test' }, 'one') + } + } + const Two = { + async setup() { + return () => h('div', { class: 'test' }, 'two') + } + } + createApp({ + template: ` +
+ + + + + +
+ + `, + setup: () => { + const view = shallowRef(One) + const click = () => { + view.value = view.value === One ? Two : One + } + return { view, click } + } + }).mount('#app') + }, duration) + + await nextFrame() + expect(await html('#container')).toBe( + '
one
' + ) + + await transitionFinish() + expect(await html('#container')).toBe('
one
') + + // trigger twice + classWhenTransitionStart() + classWhenTransitionStart() + await nextFrame() + expect(await html('#container')).toBe( + '
one
' + ) + + await transitionFinish() + await nextFrame() + expect(await html('#container')).toBe( + '
one
' + ) + + await transitionFinish() + await nextFrame() + expect(await html('#container')).toBe('
one
') + }, + E2E_TIMEOUT + ) }) describe('transition with v-show', () => {