Skip to content

Commit 65f3fe2

Browse files
authored
fix(runtime-core): Suspense get anchor properly in Transition (#9309)
close #8105
1 parent f12db7f commit 65f3fe2

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,12 @@ function createSuspenseBoundary(
504504
if (delayEnter) {
505505
activeBranch!.transition!.afterLeave = () => {
506506
if (pendingId === suspense.pendingId) {
507-
move(pendingBranch!, container, anchor, MoveType.ENTER)
507+
move(
508+
pendingBranch!,
509+
container,
510+
next(activeBranch!),
511+
MoveType.ENTER
512+
)
508513
queuePostFlushCb(effects)
509514
}
510515
}
@@ -577,7 +582,6 @@ function createSuspenseBoundary(
577582
// invoke @fallback event
578583
triggerEvent(vnode, 'onFallback')
579584

580-
const anchor = next(activeBranch!)
581585
const mountFallback = () => {
582586
if (!suspense.isInFallback) {
583587
return
@@ -587,7 +591,7 @@ function createSuspenseBoundary(
587591
null,
588592
fallbackVNode,
589593
container,
590-
anchor,
594+
next(activeBranch!),
591595
parentComponent,
592596
null, // fallback tree will not have suspense context
593597
isSVG,

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,72 @@ describe('e2e: Transition', () => {
15861586
expect(barMountSpy).toBeCalledTimes(1)
15871587
expect(barMountSpy).toHaveBeenNthCalledWith(1, true, false, true)
15881588
})
1589+
1590+
// #8105
1591+
test(
1592+
'trigger again when transition is not finished',
1593+
async () => {
1594+
await page().evaluate(duration => {
1595+
const { createApp, shallowRef, h } = (window as any).Vue
1596+
const One = {
1597+
async setup() {
1598+
return () => h('div', { class: 'test' }, 'one')
1599+
}
1600+
}
1601+
const Two = {
1602+
async setup() {
1603+
return () => h('div', { class: 'test' }, 'two')
1604+
}
1605+
}
1606+
createApp({
1607+
template: `
1608+
<div id="container">
1609+
<transition name="test" mode="out-in" duration="${duration}">
1610+
<Suspense>
1611+
<component :is="view"/>
1612+
</Suspense>
1613+
</transition>
1614+
</div>
1615+
<button id="toggleBtn" @click="click">button</button>
1616+
`,
1617+
setup: () => {
1618+
const view = shallowRef(One)
1619+
const click = () => {
1620+
view.value = view.value === One ? Two : One
1621+
}
1622+
return { view, click }
1623+
}
1624+
}).mount('#app')
1625+
}, duration)
1626+
1627+
await nextFrame()
1628+
expect(await html('#container')).toBe(
1629+
'<div class="test test-enter-active test-enter-to">one</div>'
1630+
)
1631+
1632+
await transitionFinish()
1633+
expect(await html('#container')).toBe('<div class="test">one</div>')
1634+
1635+
// trigger twice
1636+
classWhenTransitionStart()
1637+
classWhenTransitionStart()
1638+
await nextFrame()
1639+
expect(await html('#container')).toBe(
1640+
'<div class="test test-leave-active test-leave-to">one</div>'
1641+
)
1642+
1643+
await transitionFinish()
1644+
await nextFrame()
1645+
expect(await html('#container')).toBe(
1646+
'<div class="test test-enter-active test-enter-to">one</div>'
1647+
)
1648+
1649+
await transitionFinish()
1650+
await nextFrame()
1651+
expect(await html('#container')).toBe('<div class="test">one</div>')
1652+
},
1653+
E2E_TIMEOUT
1654+
)
15891655
})
15901656

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy