Backtestsvuerun-20261005-155915#15332
Suspense timeout + Transition out-in: parent update during the fallback swap permanently drops the resolved branch
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches make the same core fix. In both `isInFallback` paths of `patchSuspense`, they skip `patch(activeBranch, newFallback)` and `setActiveBranch` while `isFallbackMountPending` is true. This is exactly the root cause the issue identifies: `activeBranch` is still the leaving content, and hijacking it makes `resolve()` hook onto an `afterLeave` that never fires. Both also update `mountFallback` to mount the latest fallback vnode, since the skipped patch would otherwise leave a stale fallback. A's form, `suspense.vnode !== vnode && suspense.vnode.ssFallback ? ... : fallbackVNode`, and B's unconditional `suspense.vnode.ssFallback!` behave the same in practice. B's is slightly simpler; A's is a bit more defensive. On correctness the two are essentially equal.
The tests separate them. A adds deterministic runtime-core unit tests that use `BaseTransition` with a manually controlled leave `done`, so event ordering is exact. They cover three scenarios:
- the leave finishes before the async branch resolves, including that the latest fallback ('fallback 1') is mounted;
- the async branch resolves before the leave finishes;
- the view switches to a third async branch while the leave is pending.
Each test also checks the mount/unmount call order, and these tests would fail before the fix. B adds e2e browser tests that rely on real timers and transition durations (`timeout(10 + buffer)`, `transitionFinish(300)` twice). They cover the main scenario and the stale-fallback case, but they are timing-dependent and miss the branch-switch scenario. A's tests are more thorough, more deterministic and more precise, so A wins on the second criterion while the two are roughly even elsewhere.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
12m 28s
Wall-clock time in the container
Full test suite
No new failures
3,701 passed · 6 skipped · 3,707 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
162vs 170 merged
Changed lines, ours vs merged
The issue
View on GitHubVersion
3.5.41
Reproduction link
Steps to reproduce
Open the playground with Vue 3.5.41 selected (the banner in the preview shows the actually running version). The repro is fully event-ordered (JS transition hooks hold the leave open), so it fails on the first run, every run:
- A keyed component inside
<Suspense :timeout="100">inside<Transition mode="out-in">navigates to a cold async component (defineAsyncComponent, chunk not loaded yet). timeoutelapses → Suspense starts the fallback swap; the old content's leave transition begins.- While the leave is in progress, the parent re-renders (in a real app: a ResizeObserver callback, a store update — anything).
- The async component resolves; the leave finishes.
What is expected?
The resolved page is mounted (with the fallback shown in between).
What is actually happening?
@resolve fires and the module is loaded, but the page is never inserted — the fallback stays on screen forever. No error, no warning. A later unrelated parent re-render "un-sticks" it, which is why this is so hard to catch in the wild.
Removing any one of the three ingredients — the timeout, mode="out-in", or the mid-swap parent re-render — makes it pass (all three controls verified).
The bug is deterministic: 3.5.30 passes, 3.5.31+ fails (bisected).
Root cause (bisected + traced)
Regression introduced by 908c6ad05 (#9392, first released in 3.5.31), which added isFallbackMountPending:
fallback()setsisFallbackMountPending = trueand defersmountFallbackto the leaving branch'safterLeave.- A parent re-render hits
patchSuspense'sisInFallbackpath, which patchesactiveBranch→newFallbackand callssetActiveBranch(suspense, newFallback)— mounting the fallback early without clearingisFallbackMountPending. resolve()then skipsunmount(activeBranch)because the flag is still true, yet hooks the content move ontoactiveBranch.transition.afterLeave— whereactiveBranchis now the fallback, which is never unmounted. TheafterLeavenever fires; the resolved branch is lost.
Before #9392, resolve() unconditionally unmounted the active branch, so the fallback left and its afterLeave inserted the content.
A guard in patchSuspense fixes it — while isFallbackMountPending is true, activeBranch is still the leaving content, so the patch(activeBranch, newFallback) + setActiveBranch(suspense, newFallback) calls in the isInFallback paths must be skipped. Happy to submit a PR with the fix and an e2e regression test (prepared and passing locally, including the #9392 test for #7966).
Real-world impact: in our production SPA (layout = RouterView → Transition out-in → Suspense timeout, per the documented pattern) roughly 1 in 10 cold first navigations ended on an infinite spinner — console clean, all network requests succeed.
<!-- generated by vue-issues. DO NOT REMOVE -->
The two patches
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..39dff2a4f 100644@@ -3,6 +3,7 @@ */ import {+ BaseTransition, type ComponentOptions, Fragment, KeepAlive,@@ -1461,6 +1462,148 @@ describe('Suspense', () => { expect(calls).toEqual([`one mounted`, `one unmounted`, `two mounted`]) }) + describe('timeout + out-in transition: parent update during fallback swap (#15332)', () => {+ const setup = () => {+ const calls: string[] = []+ const leaveDones: (() => void)[] = []+ const makeComp = (name: string, delay = 0) =>+ defineAsyncComponent(+ {+ setup() {+ onMounted(() => calls.push(`${name} mounted`))+ onUnmounted(() => calls.push(`${name} unmounted`))+ return () => h('div', [name])+ },+ },+ delay,+ )+ const One = makeComp('one')+ const view = shallowRef<any>(One)+ const count = ref(0)+ const Comp = {+ setup() {+ return () =>+ h(+ BaseTransition,+ {+ mode: 'out-in',+ onLeave(_el: any, done: () => void) {+ leaveDones.push(done)+ },+ },+ () =>+ h(+ Suspense,+ { timeout: 10 },+ {+ default: h(view.value),+ fallback: h('div', `fallback ${count.value}`),+ },+ ),+ )+ },+ }+ const root = nodeOps.createElement('div')+ render(h(Comp), root)+ return { calls, leaveDones, makeComp, view, count, root }+ }++ // resolve the initial mount: the initial fallback leaves (out-in) before+ // "one" is inserted+ const mountOne = async (root: any, leaveDones: (() => void)[]) => {+ expect(serializeInner(root)).toBe(`<div>fallback 0</div>`)+ await deps[0]+ await nextTick()+ expect(leaveDones.length).toBe(1)+ leaveDones.shift()!()+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>one</div>`)+ }++ const timeout = async () => {+ await new Promise(r => setTimeout(r, 10))+ await nextTick()+ }++ test('leave finishes before async branch resolves', async () => {+ const { calls, leaveDones, makeComp, view, count, root } = setup()+ await mountOne(root, leaveDones)++ view.value = makeComp('two', 30)+ await nextTick()+ await timeout()+ // fallback swap started, waiting for the leave of "one" to finish+ expect(leaveDones.length).toBe(1)++ // parent re-render while the leave is in progress+ count.value+++ await nextTick()++ // leave finishes -> latest fallback is mounted+ leaveDones[0]()+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>fallback 1</div>`)++ await deps[1]+ await nextTick()+ // fallback leaves (out-in), then the resolved branch is inserted+ expect(leaveDones.length).toBe(2)+ leaveDones[1]()+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>two</div>`)+ expect(calls).toEqual([`one mounted`, `one unmounted`, `two mounted`])+ })++ test('async branch resolves before leave finishes', async () => {+ const { calls, leaveDones, makeComp, view, count, root } = setup()+ await mountOne(root, leaveDones)++ view.value = makeComp('two', 20)+ await nextTick()+ await timeout()+ expect(leaveDones.length).toBe(1)++ count.value+++ await nextTick()++ await deps[1]+ await nextTick()+ // the resolved branch waits for the leave transition+ expect(calls).toEqual([`one mounted`, `one unmounted`])++ leaveDones[0]()+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>two</div>`)+ expect(calls).toEqual([`one mounted`, `one unmounted`, `two mounted`])+ })++ test('branch switched to a 3rd branch while leave is in progress', async () => {+ const { calls, leaveDones, makeComp, view, root } = setup()+ await mountOne(root, leaveDones)++ view.value = makeComp('two', 100)+ await nextTick()+ await timeout()+ expect(leaveDones.length).toBe(1)++ // toggle to another async branch while the leave is in progress+ view.value = makeComp('three', 30)+ await nextTick()++ leaveDones[0]()+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>fallback 0</div>`)++ await deps[2]+ await nextTick()+ expect(leaveDones.length).toBe(2)+ leaveDones[1]()+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>three</div>`)+ expect(calls).toEqual([`one mounted`, `one unmounted`, `three mounted`])+ })+ })+ test('mount the fallback content is in the correct position', async () => { const makeComp = (name: string, delay = 0) => defineAsyncComponent(packages/runtime-core/src/components/Suspense.tsindex 37e5067ff..4784ac785 100644@@ -266,7 +266,11 @@ function patchSuspense( // because we aren't actually showing a fallback content when // patchSuspense is called. In such case, patch of fallback content // should be no op- if (!isHydrating) {+ // #15332 likewise, if the fallback mount is still waiting for the+ // leaving content's transition to finish, activeBranch is the leaving+ // content rather than the fallback. The latest fallback vnode will be+ // mounted by mountFallback once the leave transition completes.+ if (!isHydrating && !suspense.isFallbackMountPending) { patch( activeBranch, newFallback,@@ -316,7 +320,8 @@ function patchSuspense( ) if (suspense.deps <= 0) { suspense.resolve()- } else {+ } else if (!suspense.isFallbackMountPending) {+ // #15332 skip if the fallback mount is still pending (see above) patch( activeBranch, newFallback,@@ -666,10 +671,16 @@ function createSuspenseBoundary( if (!suspense.isInFallback) { return }+ // #15332 the suspense may have been patched while the fallback mount+ // was pending, mount the latest fallback vnode in that case+ const latestFallback =+ suspense.vnode !== vnode && suspense.vnode.ssFallback+ ? suspense.vnode.ssFallback+ : fallbackVNode // mount the fallback tree patch( null,- fallbackVNode,+ latestFallback, container, anchor, parentComponent,@@ -678,7 +689,7 @@ function createSuspenseBoundary( slotScopeIds, optimized, )- setActiveBranch(suspense, fallbackVNode)+ setActiveBranch(suspense, latestFallback) } const delayEnter =
packages/runtime-core/src/components/Suspense.tsindex 37e5067ff..6b6f58ba0 100644@@ -266,7 +266,13 @@ function patchSuspense( // because we aren't actually showing a fallback content when // patchSuspense is called. In such case, patch of fallback content // should be no op- if (!isHydrating) {+ // The same applies while the fallback mount is deferred to the leaving+ // branch's afterLeave (out-in transition): activeBranch is still the+ // leaving content, not the fallback. Patching it with the fallback here+ // would hijack activeBranch, and resolve() would then attach the+ // content move to an afterLeave that never fires, permanently dropping+ // the resolved branch.+ if (!isHydrating && !suspense.isFallbackMountPending) { patch( activeBranch, newFallback,@@ -316,7 +322,9 @@ function patchSuspense( ) if (suspense.deps <= 0) { suspense.resolve()- } else {+ } else if (!suspense.isFallbackMountPending) {+ // while the fallback mount is deferred to the leaving branch's+ // afterLeave, activeBranch is still the leaving content — see above patch( activeBranch, newFallback,@@ -666,10 +674,14 @@ function createSuspenseBoundary( if (!suspense.isInFallback) { return }+ // a parent update may have produced a newer fallback vnode while the+ // mount was deferred (its patch is skipped during that window), so+ // mount the latest one+ const latestFallback = suspense.vnode.ssFallback! // mount the fallback tree patch( null,- fallbackVNode,+ latestFallback, container, anchor, parentComponent,@@ -678,7 +690,7 @@ function createSuspenseBoundary( slotScopeIds, optimized, )- setActiveBranch(suspense, fallbackVNode)+ setActiveBranch(suspense, latestFallback) } const delayEnter =packages/vue/__tests__/e2e/Transition.spec.tsindex 025cc7c00..0a0739ca0 100644@@ -2169,6 +2169,156 @@ describe('e2e: Transition', () => { E2E_TIMEOUT, ) + // a parent update arriving while the timed-out fallback swap is waiting+ // for the leaving branch's afterLeave must not drop the resolved branch+ test(+ 'parent update during timed-out fallback swap with out-in transition',+ async () => {+ await page().evaluate(() => {+ const { createApp, shallowRef, ref, h, defineAsyncComponent } = (+ window as any+ ).Vue+ const One = {+ setup() {+ return () => h('div', { class: 'test' }, 'one')+ },+ }+ const Two = {+ async setup() {+ return () => h('div', { class: 'test' }, 'two')+ },+ }+ const AsyncTwo = defineAsyncComponent(+ () =>+ new Promise(res => {+ ;(window as any).resolveTwo = () => res(Two as any)+ }),+ )+ createApp({+ template: `+ <div id="container">+ <transition mode="out-in" :duration="300">+ <Suspense :timeout="10">+ <component :is="view" :key="name" :data-tick="tick"/>+ <template #fallback><div class="fallback">loading</div></template>+ </Suspense>+ </transition>+ </div>+ <button id="toggleBtn" @click="click">button</button>+ <button id="tickBtn" @click="tick++">tick</button>+ `,+ setup: () => {+ const view = shallowRef(One)+ const name = ref('one')+ const tick = ref(0)+ const click = () => {+ view.value = AsyncTwo+ name.value = 'two'+ }+ return { view, name, tick, click }+ },+ }).mount('#app')+ })+ await transitionFinish()+ expect(await html('#container')).toBe(+ '<div class="test" data-tick="0">one</div>',+ )++ // navigate to the cold async branch; timeout=10 starts the fallback+ // swap and the old branch's leave transition+ await click('#toggleBtn')+ await timeout(10 + buffer)+ // unrelated parent re-render while the fallback mount is deferred to+ // the leaving branch's afterLeave+ await click('#tickBtn')+ // the async branch resolves while the leave is still in progress+ await page().evaluate(() => (window as any).resolveTwo())+ await transitionFinish(300)+ await transitionFinish(300)+ await nextTick()+ expect(await html('#container')).toContain('two')+ expect(await html('#container')).not.toContain('loading')+ },+ E2E_TIMEOUT,+ )++ // a parent update that changes the fallback content while its mount is+ // deferred must mount the latest fallback, not the stale one+ test(+ 'fallback updated by parent while its mount is deferred',+ async () => {+ await page().evaluate(() => {+ const { createApp, shallowRef, ref, h, defineAsyncComponent } = (+ window as any+ ).Vue+ const One = {+ setup() {+ return () => h('div', { class: 'test' }, 'one')+ },+ }+ const Two = {+ async setup() {+ return () => h('div', { class: 'test' }, 'two')+ },+ }+ const AsyncTwo = defineAsyncComponent(+ () =>+ new Promise(res => {+ ;(window as any).resolveTwo = () => res(Two as any)+ }),+ )+ createApp({+ template: `+ <div id="container">+ <transition mode="out-in" :duration="300">+ <Suspense :timeout="10">+ <component :is="view" :key="name" :data-tick="tick"/>+ <template #fallback><div class="fallback">loading {{ tick }}</div></template>+ </Suspense>+ </transition>+ </div>+ <button id="toggleBtn" @click="click">button</button>+ <button id="tickBtn" @click="tick++">tick</button>+ `,+ setup: () => {+ const view = shallowRef(One)+ const name = ref('one')+ const tick = ref(0)+ const click = () => {+ view.value = AsyncTwo+ name.value = 'two'+ }+ return { view, name, tick, click }+ },+ }).mount('#app')+ })+ await transitionFinish()+ expect(await html('#container')).toBe(+ '<div class="test" data-tick="0">one</div>',+ )++ // navigate to the cold async branch; the fallback mount is deferred+ // to the old branch's afterLeave+ await click('#toggleBtn')+ await timeout(10 + buffer)+ // parent update changes the fallback content while its mount is+ // still deferred+ await click('#tickBtn')+ // let the leave finish so the (latest) fallback mounts+ await transitionFinish(300)+ await nextTick()+ expect(await html('#container')).toContain('loading 1')+ // the async branch resolves after the leave completed+ await page().evaluate(() => (window as any).resolveTwo())+ await transitionFinish(300)+ await transitionFinish(300)+ await nextTick()+ expect(await html('#container')).toContain('two')+ expect(await html('#container')).not.toContain('loading')+ },+ E2E_TIMEOUT,+ )+ // #14640 test( 'switch suspense branches after teleport updates before pending mount finishes',