Backtestsvuerun-20261001-022054#15332

Issue #15332 Merged fix PR #15333 Run 30 Sep 2026 · run-20261001-022054 vuejs/core

Suspense timeout + Transition out-in: parent update during the fallback swap permanently drops the resolved branch

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

The two source fixes are essentially the same. Both skip the `patch(activeBranch, newFallback)` call in both `isInFallback` paths of `patchSuspense` while `isFallbackMountPending` is set. Both also mount the latest `suspense.vnode.ssFallback` when the deferred `mountFallback` finally runs. That addresses the root cause traced in the issue: the active branch was being hijacked into the fallback, so `resolve()` attached the content move to an `afterLeave` that never fires.

The small source differences:
- A uses `suspense.vnode.ssFallback || fallbackVNode`, which is a slightly safer fallback.
- B uses a non-null assertion.
- B's comments explain the reasoning more thoroughly. This is a minor craft plus.

The deciding difference is the tests.

Patch A adds three deterministic unit tests in `runtime-core`. They use `BaseTransition` with manually held `onLeave` callbacks, so event ordering is exact and does not depend on timing.
- Test 1 reproduces the reported scenario: a parent re-render during the leave, then resolve.
- Test 2 checks that the latest fallback is mounted.
- Test 3 switches to a different async component while the leave is pending. This exercises the second guarded path, the `else if (!suspense.isFallbackMountPending)` branch where the new branch is not the same vnode type as the pending branch.

Patch B adds two e2e tests. They rely on wall-clock timeouts, `:duration`, and buffers, so they are more timing-sensitive and heavier to run. Both only change props on the same keyed component, so they exercise only the first guarded path. The second patched branch is left untested.

Correctness is equal and B's comments are somewhat better, but A's tests are more deterministic and cover both modified code paths. A is the stronger patch.

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

7m 30s16 turns

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

259vs 170 merged

Changed lines, ours vs merged

Version

3.5.41

Reproduction link

play.vuejs.org/

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:

  1. A keyed component inside <Suspense :timeout="100"> inside <Transition mode="out-in"> navigates to a cold async component (defineAsyncComponent, chunk not loaded yet).
  2. timeout elapses → Suspense starts the fallback swap; the old content's leave transition begins.
  3. While the leave is in progress, the parent re-renders (in a real app: a ResizeObserver callback, a store update — anything).
  4. 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() sets isFallbackMountPending = true and defers mountFallback to the leaving branch's afterLeave.
  • A parent re-render hits patchSuspense's isInFallback path, which patches activeBranch → newFallback and calls setActiveBranch(suspense, newFallback) — mounting the fallback early without clearing isFallbackMountPending.
  • resolve() then skips unmount(activeBranch) because the flag is still true, yet hooks the content move onto activeBranch.transition.afterLeave — where activeBranch is now the fallback, which is never unmounted. The afterLeave never 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

Our patch+257 −2
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..36c28920c 100644@@ -3,6 +3,7 @@  */  import {+  BaseTransition,   type ComponentOptions,   Fragment,   KeepAlive,@@ -2879,6 +2880,254 @@ describe('Suspense', () => {     expect(serializeInner(root)).toBe(`<div>B</div>`)   }) +  test('Transition(out-in) + Suspense(timeout): parent re-render while old content is leaving should still show resolved content', async () => {+    const leaveDones: (() => void)[] = []+    const transitionProps = {+      mode: 'out-in' as const,+      onEnter(_el: any, done: () => void) {+        done()+      },+      onLeave(_el: any, done: () => void) {+        leaveDones.push(done)+      },+    }+    const finishLeaves = async () => {+      while (leaveDones.length) {+        leaveDones.shift()!()+        await nextTick()+      }+    }++    let resolveTwo!: () => void+    const twoPromise = new Promise<void>(r => (resolveTwo = r))++    const One = {+      setup() {+        return () => h('div', 'one')+      },+    }+    const Two = {+      async setup() {+        await twoPromise+        return () => h('div', 'two')+      },+    }++    const view = shallowRef<any>(One)+    const count = ref(0)++    const App = {+      setup() {+        return () =>+          h(BaseTransition, transitionProps, () =>+            h(+              Suspense,+              { timeout: 0 },+              {+                default: h(view.value),+                fallback: h('div', `fallback ${count.value}`),+              },+            ),+          )+      },+    }++    const root = nodeOps.createElement('div')+    render(h(App), root)+    expect(serializeInner(root)).toBe(`<div>one</div>`)++    // switch to async branch; timeout: 0 triggers fallback immediately and+    // the old content starts leaving (held open by onLeave)+    view.value = Two+    await nextTick()+    expect(leaveDones.length).toBe(1)+    expect(serializeInner(root)).toBe(`<div>one</div>`)++    // parent re-render while the old content is still leaving+    count.value+++    await nextTick()++    // resolve the async branch+    resolveTwo()+    await twoPromise+    await new Promise(r => setTimeout(r))+    await nextTick()++    // finish the pending leave(s) (old content, and fallback if it mounted)+    await finishLeaves()+    await new Promise(r => setTimeout(r))+    await finishLeaves()++    expect(serializeInner(root)).toBe(`<div>two</div>`)+  })++  test('Transition(out-in) + Suspense(timeout): parent re-render while old content is leaving should mount latest fallback', async () => {+    const leaveDones: (() => void)[] = []+    const transitionProps = {+      mode: 'out-in' as const,+      onEnter(_el: any, done: () => void) {+        done()+      },+      onLeave(_el: any, done: () => void) {+        leaveDones.push(done)+      },+    }+    const finishLeaves = async () => {+      while (leaveDones.length) {+        leaveDones.shift()!()+        await nextTick()+      }+    }++    let resolveTwo!: () => void+    const twoPromise = new Promise<void>(r => (resolveTwo = r))++    const One = {+      setup() {+        return () => h('div', 'one')+      },+    }+    const Two = {+      async setup() {+        await twoPromise+        return () => h('div', 'two')+      },+    }++    const view = shallowRef<any>(One)+    const count = ref(0)++    const App = {+      setup() {+        return () =>+          h(BaseTransition, transitionProps, () =>+            h(+              Suspense,+              { timeout: 0 },+              {+                default: h(view.value),+                fallback: h('div', `fallback ${count.value}`),+              },+            ),+          )+      },+    }++    const root = nodeOps.createElement('div')+    render(h(App), root)+    expect(serializeInner(root)).toBe(`<div>one</div>`)++    view.value = Two+    await nextTick()+    expect(leaveDones.length).toBe(1)+    expect(serializeInner(root)).toBe(`<div>one</div>`)++    // parent re-render while the old content is still leaving+    count.value+++    await nextTick()++    // finish the leave before the async branch resolves:+    // the latest fallback should be mounted+    await finishLeaves()+    expect(serializeInner(root)).toBe(`<div>fallback 1</div>`)++    resolveTwo()+    await twoPromise+    await new Promise(r => setTimeout(r))+    await nextTick()++    // finish the fallback's leave+    await finishLeaves()+    await new Promise(r => setTimeout(r))+    await finishLeaves()++    expect(serializeInner(root)).toBe(`<div>two</div>`)+  })++  test('Transition(out-in) + Suspense(timeout): switch to another async branch while old content is leaving should show resolved content', async () => {+    const leaveDones: (() => void)[] = []+    const transitionProps = {+      mode: 'out-in' as const,+      onEnter(_el: any, done: () => void) {+        done()+      },+      onLeave(_el: any, done: () => void) {+        leaveDones.push(done)+      },+    }+    const finishLeaves = async () => {+      while (leaveDones.length) {+        leaveDones.shift()!()+        await nextTick()+      }+    }++    const twoPromise = new Promise<void>(() => {})+    let resolveThree!: () => void+    const threePromise = new Promise<void>(r => (resolveThree = r))++    const One = {+      setup() {+        return () => h('div', 'one')+      },+    }+    const Two = {+      async setup() {+        await twoPromise+        return () => h('div', 'two')+      },+    }+    const Three = {+      async setup() {+        await threePromise+        return () => h('div', 'three')+      },+    }++    const view = shallowRef<any>(One)++    const App = {+      setup() {+        return () =>+          h(BaseTransition, transitionProps, () =>+            h(+              Suspense,+              { timeout: 0 },+              {+                default: h(view.value),+                fallback: h('div', 'fallback'),+              },+            ),+          )+      },+    }++    const root = nodeOps.createElement('div')+    render(h(App), root)+    expect(serializeInner(root)).toBe(`<div>one</div>`)++    view.value = Two+    await nextTick()+    expect(leaveDones.length).toBe(1)+    expect(serializeInner(root)).toBe(`<div>one</div>`)++    // toggle to another async branch while the old content is still leaving+    view.value = Three+    await nextTick()++    resolveThree()+    await threePromise+    await new Promise(r => setTimeout(r))+    await nextTick()++    // finish the pending leave(s) (old content, and fallback if it mounted)+    await finishLeaves()+    await new Promise(r => setTimeout(r))+    await finishLeaves()++    expect(serializeInner(root)).toBe(`<div>three</div>`)+  })+   describe('warnings', () => {     // base function to check if a combination of slots warns or not     function baseCheckWarn(packages/runtime-core/src/components/Suspense.tsindex 37e5067ff..4b718130e 100644@@ -266,7 +266,10 @@ 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) {+        // if the fallback mount is still pending (waiting for the+        // leaving content's afterLeave in out-in mode), activeBranch is still+        // the leaving content and must not be patched into the fallback.+        if (!isHydrating && !suspense.isFallbackMountPending) {           patch(             activeBranch,             newFallback,@@ -316,7 +319,7 @@ function patchSuspense(         )         if (suspense.deps <= 0) {           suspense.resolve()-        } else {+        } else if (!suspense.isFallbackMountPending) {           patch(             activeBranch,             newFallback,@@ -666,6 +669,9 @@ function createSuspenseBoundary(         if (!suspense.isInFallback) {           return         }+        // the suspense may have been patched while waiting for afterLeave,+        // so mount the latest fallback vnode+        fallbackVNode = suspense.vnode.ssFallback || fallbackVNode         // mount the fallback tree         patch(           null, 
Merged fix · PR #15333+166 −4
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', 

What the agent reported

I fixed the bug: when the parent re-renders during the fallback swap, the resolved page now mounts instead of the fallback staying up forever. The runtime-core, server-renderer and vue unit suites pass (77 files, 1540 tests), including three new regression tests that each fail without the fix.

What was wrong. It is the cause described in the report:

  • With out-in, fallback() sets isFallbackMountPending and waits for the old content to finish leaving before it mounts the fallback.
  • A parent re-render in that window hits patchSuspense's isInFallback paths. These patch the old content (still leaving) into the new fallback and make the fallback the active branch.
  • resolve() then skips the unmount because the flag is still set, and attaches the content move to the fallback's afterLeave. The fallback is never unmounted, so that hook never fires and the resolved content is lost.

What I changed (all in packages/runtime-core/src/components/Suspense.ts):

  1. In patchSuspense, both isInFallback paths now skip the fallback patch and the active-branch switch while isFallbackMountPending is set. These are the same-type path (~line 272) and the toggled-branch path (~line 322). At that point the active branch is still the leaving content.
  2. mountFallback now mounts suspense.vnode.ssFallback, the latest fallback, instead of the one captured when fallback() ran. Without this, a re-render during the leave would mount an outdated fallback (e.g. "fallback 0" instead of "fallback 1"). This also applies when timeout is used without a Transition: the latest fallback is mounted, not the one from when the timer started. That's harmless, but it is a small behaviour change beyond the report.

Tests. I added three unit tests to packages/runtime-core/__tests__/components/Suspense.spec.ts. Each uses BaseTransition in out-in mode, a JS onLeave hook that holds the leave open, and <Suspense timeout: 0>:

  • Content resolves after a re-render during the leave: the screen ends on <div>two</div>. Before the fix it stayed on <div>fallback 1</div>. Removing the re-render makes it pass on the old code, so the re-render is what triggers the bug.
  • Leave finishes before the content resolves: the latest fallback, <div>fallback 1</div>, is shown, then two. Removing change 2 makes it fail with fallback 0.
  • Switching to another async component during the leave: the screen ends on <div>three</div>. Turning the line-322 guard back into a plain else makes it fail.

The full Suspense.spec.ts passes (62 tests).

Requirements

ItemDisposition
Resolved page mounts after timeout + out-in + mid-swap parent re-renderDone; test 1
Guard in patchSuspense while isFallbackMountPending (the proposed fix)Done for both isInFallback paths; tests 1 and 3
Keep the #9392 / #7966 behaviourProduction code it relies on is unchanged, but its test is an e2e test in packages/vue/__tests__/e2e/Transition.spec.ts, which I didn't run here. That test never re-renders the parent, so it doesn't reach the new guards.
Three controls (no timeout, no out-in, no re-render)Only "no re-render" is checked, in test 1. The timeout-off and out-in-off cases don't take the new paths; existing Suspense tests cover them, and they pass.
E2E regression test, as the reporter offeredNot added: the e2e suite needs a browser build that wasn't run here. The scenario is covered at unit level instead.

The tests use timeout: 0, so they don't exercise the timer that triggers the fallback with a non-zero timeout; the code after that point is the same. Changes are uncommitted and there are no scratch files left.