Backtestsvuerun-20261005-155915#7506

Issue #7506 Merged fix PR #15411 Run 5 Oct 2026 · run-20261005-155915 vuejs/core

suspense.resolve() is called without a pending branch.

Better

Our patch was judged better than the merged fix.

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

In the issue, the user navigates away from inside a pending page's setup(), which means the Suspense is toggled back to its current active branch while a pending branch still exists. In the 'toggled back' path, the active branch is patched while `suspense.pendingBranch` is still set. Any async dep or suspensible nested Suspense mounted during that patch therefore registers against the boundary: `registerDep` only increments deps when `pendingBranch` is non-null. The code then force-resolves, clearing the pending branch. When the leftover dep later settles, deps drops to 0 and `resolve()` runs with no pending branch, which produces exactly the reported error. Patch B fixes this root cause: it nulls `pendingBranch` during the toggle-back patch so new deps are not counted against the discarded pending branch, then restores it so `resolve(true)` works. Its tests reproduce the issue's flow (changing the view inside setup() and mounting a new async child, or a suspensible nested Suspense, in the active branch). They assert no error, correct output, that onResolve is not called twice, and that a later pending branch still resolves, so dep counts stay consistent. These tests would fail before the change. Patch A instead changes the same-root-type pending patch path, adding a deps++/-- guard against a nested suspensible Suspense resolving the parent mid-patch. That is a different scenario from the toggle-back race in the issue. Its tests target nested suspensible boundaries rather than navigation during setup, so it likely leaves the reported error in place. Patch B is targeted, correct, and well tested for the reported case.

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

17m 21s

Wall-clock time in the container

Full test suite

No new failures

3,703 passed · 6 skipped · 3,709 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

141vs 141 merged

Changed lines, ours vs merged

Vue version

3.2.45

Link to minimal reproduction

https://codesandbox.io/s/vue-router-playground-forked-w9164p?file=/src/pages/Page2.vue

Steps to reproduce

Create an application with vue and vue-router and the suspense component.

When creating a page, during the setup function navigate to another page (in my case this is how I handle an error) than this error is triggered.

What is expected?

Just no error message from vue / Suspense.

What is actually happening?

I get the following error message:

`
suspense.resolve() is called without a pending branch.
`

Nevertheless I can keep on using the application without any problems. I just want to get rid of the error message.

System Info

_No response_

Any additional comments?

_No response_

The two patches

Our patch+141 −0
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..9ce5ecc21 100644@@ -1395,6 +1395,140 @@ describe('Suspense', () => {     expect(calls).toEqual([`one mounted`])   }) +  test('branch switch back during pending setup mounts new async dep in active branch', async () => {+    const showChild = ref(false)+    const Child = defineAsyncComponent({+      render: () => h('span', 'child'),+    })+    const One = {+      props: ['show'],+      setup(props: any) {+        return () => h('div', ['one', props.show ? h(Child) : null])+      },+    }+    const Three = defineAsyncComponent({+      props: ['show'],+      render: () => h('div', 'three'),+    })+    const view = shallowRef<any>(One)+    // like navigating away from inside setup() of the pending page+    const Two = {+      setup() {+        view.value = One+        showChild.value = true+        const p = new Promise(r => setTimeout(r)).then(+          () => () => h('div', 'two'),+        )+        deps.push(p)+        return p+      },+    }++    const onResolve = vi.fn()+    const Comp = {+      setup() {+        return () =>+          h(Suspense, { onResolve }, {+            default: h(view.value, { show: showChild.value }),+            fallback: h('div', 'fallback'),+          })+      },+    }++    const root = nodeOps.createElement('div')+    render(h(Comp), root)+    expect(serializeInner(root)).toBe(`<div>one<!----></div>`)+    expect(onResolve).toHaveBeenCalledTimes(1)++    view.value = Two+    await nextTick()+    // switched back to One, whose new async child is pending in place+    expect(serializeInner(root)).toBe(`<div>one<!----></div>`)+    expect(onResolve).toHaveBeenCalledTimes(2)++    await Promise.all(deps)+    await nextTick()+    // must not throw "suspense.resolve() is called without a pending branch"+    expect(serializeInner(root)).toBe(`<div>one<span>child</span></div>`)+    // the child resolving must not resolve the boundary a second time+    expect(onResolve).toHaveBeenCalledTimes(2)++    // boundary dep count must stay consistent for later pending branches+    view.value = Three+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>one<span>child</span></div>`)+    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>three</div>`)+    expect(onResolve).toHaveBeenCalledTimes(3)+  })++  test('branch switch back during pending setup mounts suspensible nested suspense in active branch', async () => {+    const showInner = ref(false)+    const InnerAsync = defineAsyncComponent({+      render: () => h('span', 'inner'),+    })+    const One = {+      props: ['show'],+      setup(props: any) {+        return () =>+          h('div', [+            'one',+            props.show+              ? h(+                  Suspense,+                  { suspensible: true },+                  { default: h(InnerAsync), fallback: h('i', 'loading') },+                )+              : null,+          ])+      },+    }+    const Three = defineAsyncComponent({+      props: ['show'],+      render: () => h('div', 'three'),+    })+    const view = shallowRef<any>(One)+    const Two = {+      setup() {+        view.value = One+        showInner.value = true+        const p = new Promise(r => setTimeout(r)).then(+          () => () => h('div', 'two'),+        )+        deps.push(p)+        return p+      },+    }++    const Comp = {+      setup() {+        return () =>+          h(Suspense, null, {+            default: h(view.value, { show: showInner.value }),+            fallback: h('div', 'fallback'),+          })+      },+    }++    const root = nodeOps.createElement('div')+    render(h(Comp), root)+    expect(serializeInner(root)).toBe(`<div>one<!----></div>`)++    view.value = Two+    await nextTick()+    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>one<span>inner</span></div>`)++    // the outer boundary must not be left waiting on the nested suspense+    view.value = Three+    await nextTick()+    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>three</div>`)+  })+   test('branch switch timeout + fallback', async () => {     const calls: string[] = [] packages/runtime-core/src/components/Suspense.tsindex 8a186fff2..77382c3e8 100644@@ -341,6 +341,12 @@ function patchSuspense(         }       } else if (activeBranch && isSameVNodeType(activeBranch, newBranch)) {         // toggled "back" to current active branch+        // the active branch is already visible, so patch it as a resolved+        // branch: async deps (or suspensible nested suspenses) mounted during+        // this patch must not be counted as deps of the discarded pending+        // branch, otherwise they would resolve this boundary again later+        // without a pending branch.+        suspense.pendingBranch = null         patch(           activeBranch,           newBranch,@@ -353,6 +359,7 @@ function patchSuspense(           optimized,         )         // force resolve+        suspense.pendingBranch = newBranch         suspense.resolve(true)       } else {         // switched to a 3rd branch 
Merged fix · PR #15411+141 −0
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..68d71ebd1 100644@@ -2004,6 +2004,143 @@ describe('Suspense', () => {     ])   }) +  // toggling a nested suspensible suspense to sync content resolves the+  // parent boundary synchronously while it is still being patched; the+  // fallback fall-through must then be skipped or it patches the unmounted+  // fallback and corrupts activeBranch+  test('nested suspensible suspense toggled to sync content while parent is in fallback', async () => {+    const route = ref('a')+    const label = ref('first')++    const AsyncChild = {+      async setup() {+        await new Promise(() => {}) // never resolves+        return () => h('div', 'async child')+      },+    }+    const PageA = {+      setup: () => () => h('div', [h('span', 'page a'), h(AsyncChild)]),+    }+    const PageB = {+      setup: () => () => h('div', `page b ${label.value}`),+    }++    const Comp = {+      setup() {+        return () =>+          h(Suspense, null, {+            default: h('div', { 'data-label': label.value }, [+              h(+                Suspense,+                { suspensible: true },+                {+                  default:+                    route.value === 'a'+                      ? h(PageA, { key: 'a' })+                      : h(PageB, { key: 'b' }),+                },+              ),+            ]),+            fallback: h('div', 'fallback'),+          })+      },+    }++    const root = nodeOps.createElement('div')+    render(h(Comp), root)+    expect(serializeInner(root)).toBe(`<div>fallback</div>`)++    // the nested suspense resolves synchronously, propagates, and resolves+    // the outer boundary mid-patch+    route.value = 'b'+    await nextTick()+    expect(serializeInner(root)).toBe(+      `<div data-label="first"><div>page b first</div></div>`,+    )++    // a follow-up update must still reach the DOM+    label.value = 'second'+    await nextTick()+    expect(serializeInner(root)).toBe(+      `<div data-label="second"><div>page b second</div></div>`,+    )+  })++  // a nested suspensible suspense resolving synchronously inside the parent's+  // same-root patch must not resolve the parent before later siblings in the+  // same patch have registered their async deps+  test('nested suspensible suspense resolving the parent mid-patch while a later sibling registers an async dep', async () => {+    const route = ref('a')+    const show = ref(false)+    let releaseSibling: () => void+    const siblingGate = new Promise<void>(r => (releaseSibling = r))++    const NeverChild = {+      async setup() {+        await new Promise(() => {}) // never resolves+        return () => h('div', 'never')+      },+    }+    const Sibling = {+      async setup() {+        await siblingGate+        return () => h('div', 'sibling')+      },+    }+    const PageA = {+      setup: () => () => h('div', [h('span', 'page a'), h(NeverChild)]),+    }+    const PageB = {+      setup: () => () => h('div', 'page b'),+    }++    const onResolve = vi.fn()+    const Comp = {+      setup() {+        return () =>+          h(+            Suspense,+            { onResolve },+            {+              default: h('div', [+                h(+                  Suspense,+                  { suspensible: true },+                  {+                    default:+                      route.value === 'a'+                        ? h(PageA, { key: 'a' })+                        : h(PageB, { key: 'b' }),+                  },+                ),+                show.value ? h(Sibling) : null,+              ]),+              fallback: h('div', 'fallback'),+            },+          )+      },+    }++    const root = nodeOps.createElement('div')+    render(h(Comp), root)+    expect(serializeInner(root)).toBe(`<div>fallback</div>`)++    // the nested suspense resolves synchronously and releases the parent's+    // last dep, but the sibling mounted right after it is still pending+    route.value = 'b'+    show.value = true+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>fallback</div>`)+    expect(onResolve).not.toHaveBeenCalled()++    releaseSibling!()+    await new Promise(r => setTimeout(r))+    expect(serializeInner(root)).toBe(+      `<div><div>page b</div><div>sibling</div></div>`,+    )+    expect(onResolve).toHaveBeenCalledTimes(1)+  })+   // #6416   test('KeepAlive with Suspense', async () => {     const Async = defineAsyncComponent({packages/runtime-core/src/components/Suspense.tsindex 8a186fff2..ba61c6340 100644@@ -246,6 +246,9 @@ function patchSuspense(     suspense.pendingBranch = newBranch     if (isSameVNodeType(pendingBranch, newBranch)) {       // same root type but content may have changed.+      // hold the boundary pending across the patch: a nested branch that+      // resolves in here must not resolve it before later siblings register.+      suspense.deps++       patch(         pendingBranch,         newBranch,@@ -258,6 +261,7 @@ function patchSuspense(         slotScopeIds,         optimized,       )+      suspense.deps--       if (suspense.deps <= 0) {         suspense.resolve()       } else if (isInFallback) {