Backtestsvuerun-20261013-093701#15332

Issue #15332 Merged fix PR #15333 Run 13 Oct 2026 · run-20261013-093701 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 B = our agent, Patch A = the merged fix.

Both patches make the same core fix the issue asks for. In both `isInFallback` paths of `patchSuspense`, they skip `patch(activeBranch, newFallback)` and `setActiveBranch` while `isFallbackMountPending` is true. In the deferred `mountFallback`, both mount the latest `suspense.vnode.ssFallback` instead of the stale captured vnode. On the reported scenario they behave the same.

Patch B also fixes a related flaw in `resolve()`. While the fallback mount is pending, the original code skipped the anchor refresh along with the unmount. The anchor refresh reads `next(activeBranch)` while the leaving content is still in the DOM. Without it, the resolved content is inserted at the stale boundary anchor (for example a fragment end anchor) instead of its original position. Patch B moves the anchor read out of the `!isFallbackMountPending` guard and keeps only the unmount guarded. This is a small, low-risk change: the leaving element is still in the container at that point, so `next()` is valid. B backs it with a sibling-position test that Patch A would probably fail.

On tests, B adds four deterministic runtime-core unit tests that control the leave timing manually through `onLeave` done callbacks:
- the parent-update regression
- correct insertion position with a sibling
- mounting the latest fallback
- switching branches mid-swap

These should fail before the fix and pass after it, and they are not timing-dependent. Patch A's tests are e2e/Puppeteer tests that rely on timeouts and transition durations. They are more fragile and cover fewer edge cases.

A's `suspense.vnode.ssFallback!` versus B's `|| fallbackVNode` fallback is a minor difference; B's is slightly more defensive. Overall, B is equally correct on the core issue, more correct on insertion position, and better tested.

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

6m 56s

Wall-clock time in the container

Full test suite

No new failures

1,798 passed · 1 skipped · 1,799 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

150vs 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+144 −6
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..2c43eb793 100644@@ -3,6 +3,7 @@  */  import {+  BaseTransition,   type ComponentOptions,   Fragment,   KeepAlive,@@ -2879,6 +2880,131 @@ describe('Suspense', () => {     expect(serializeInner(root)).toBe(`<div>B</div>`)   }) +  describe('fallback mount deferred by out-in transition', () => {+    function setup(withSibling = false) {+      const leaveDones: (() => void)[] = []+      const resolvers: Record<string, () => void> = {}+      const createAsync = (name: string) =>+        defineComponent({+          async setup() {+            await new Promise<void>(r => (resolvers[name] = r))+            return () => h('div', name)+          },+        })+      const One = defineComponent({ setup: () => () => h('div', 'one') })+      const view = shallowRef<any>(One)+      const tick = ref(0)+      const Comp = defineComponent({+        setup: () => () => [+          h(+            BaseTransition,+            {+              mode: 'out-in',+              onLeave: (_el: any, done: () => void) => leaveDones.push(done),+            },+            () =>+              h(+                Suspense,+                { timeout: 0 },+                {+                  default: h(view.value),+                  fallback: h('div', `fallback ${tick.value}`),+                },+              ),+          ),+          ...(withSibling ? [h('span', 'sibling')] : []),+        ],+      })+      const root = nodeOps.createElement('div')+      render(h(Comp), root)+      expect(serializeInner(root)).toBe(+        withSibling ? `<div>one</div><span>sibling</span>` : `<div>one</div>`,+      )+      return { root, view, tick, leaveDones, resolvers, createAsync }+    }++    test('parent update during the fallback swap should not drop the resolved branch', async () => {+      const { root, view, tick, leaveDones, resolvers, createAsync } = setup()++      view.value = createAsync('async')+      await nextTick()+      // fallback swap started, old content is leaving+      expect(leaveDones.length).toBe(1)+      expect(serializeInner(root)).toBe(`<div>one</div>`)++      // parent re-render while the leave is in progress+      tick.value+++      await nextTick()+      expect(serializeInner(root)).toBe(`<div>one</div>`)++      resolvers.async()+      await new Promise(r => setTimeout(r))+      leaveDones[0]()+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>async</div>`)+    })++    test('resolved branch should be inserted at the original position', async () => {+      const { root, view, tick, leaveDones, resolvers, createAsync } =+        setup(true)++      view.value = createAsync('async')+      await nextTick()+      expect(leaveDones.length).toBe(1)++      tick.value+++      await nextTick()++      resolvers.async()+      await new Promise(r => setTimeout(r))+      leaveDones[0]()+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>async</div><span>sibling</span>`)+    })++    test('parent update during the fallback swap should mount the latest fallback', async () => {+      const { root, view, tick, leaveDones, resolvers, createAsync } = setup()++      view.value = createAsync('async')+      await nextTick()+      expect(leaveDones.length).toBe(1)++      tick.value+++      await nextTick()++      // leave finishes before the async component resolves+      leaveDones[0]()+      expect(serializeInner(root)).toBe(`<div>fallback 1</div>`)++      resolvers.async()+      await new Promise(r => setTimeout(r))+      // fallback leaves, then the resolved content enters+      expect(leaveDones.length).toBe(2)+      leaveDones[1]()+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>async</div>`)+    })++    test('switching branch during the fallback swap should not drop the resolved branch', async () => {+      const { root, view, leaveDones, resolvers, createAsync } = setup()++      view.value = createAsync('async')+      await nextTick()+      expect(leaveDones.length).toBe(1)++      // toggle to another async branch while the leave is in progress+      view.value = createAsync('async2')+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>one</div>`)++      resolvers.async2()+      await new Promise(r => setTimeout(r))+      leaveDones[0]()+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>async2</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..0bc7f432b 100644@@ -265,8 +265,12 @@ function patchSuspense(         // setup in children of suspense boundary, that would be problemtic         // 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) {+        // should be no op.+        // #7966 if the fallback mount is still deferred to the leaving+        // content's afterLeave, activeBranch is the leaving content rather than+        // the fallback, so it must not be patched or replaced here; the+        // deferred mount will pick up the latest fallback vnode.+        if (!isHydrating && !suspense.isFallbackMountPending) {           patch(             activeBranch,             newFallback,@@ -316,7 +320,7 @@ function patchSuspense(         )         if (suspense.deps <= 0) {           suspense.resolve()-        } else {+        } else if (!suspense.isFallbackMountPending) {           patch(             activeBranch,             newFallback,@@ -577,7 +581,7 @@ function createSuspenseBoundary(         // #7966 when Suspense is wrapped in Transition, fallback may wait for         // afterLeave before mounting. In that window, activeBranch is still the         // leaving content, so avoid unmounting it again during resolve.-        if (activeBranch && !suspense.isFallbackMountPending) {+        if (activeBranch) {           // if the fallback tree was mounted, it may have been moved           // as part of a parent suspense. get the latest anchor for insertion           // #8105 if `delayEnter` is true, it means that the mounting of@@ -588,10 +592,15 @@ function createSuspenseBoundary(           // (got `pendingBranch.el`).           // Therefore, after the mounting of activeBranch is completed,           // it is necessary to get the latest anchor.+          // This also applies while the fallback mount is pending: the+          // leaving content is removed before afterLeave runs, so the anchor+          // must be read now.           if (parentNode(activeBranch.el!) === container) {             anchor = next(activeBranch)             hasUpdatedAnchor = true           }+        }+        if (activeBranch && !suspense.isFallbackMountPending) {           unmount(activeBranch, parentComponent, suspense, true)           // clear el reference from fallback vnode to allow GC           if (!delayEnter && isInFallback && vnode.ssFallback) {@@ -666,10 +675,13 @@ function createSuspenseBoundary(         if (!suspense.isInFallback) {           return         }+        // the boundary may have been patched while the mount was deferred,+        // so mount the latest fallback vnode+        const latestFallback = suspense.vnode.ssFallback || fallbackVNode         // 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 = 
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',