Backtestsvuerun-20261001-022054#7506

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

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

Better

Our patch was judged better than the merged fix.

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

The issue is a page whose setup navigates away while Suspense is pending, which leads to the 'suspense.resolve() is called without a pending branch' warning. Patch A targets the 'toggled back to current active branch' path in patchSuspense. When the router redirects back to the already-active page while the new page is pending, the active branch is patched while `suspense.pendingBranch` is still set. Any async dep mounted during that patch is counted against the pending branch. `resolve(true)` then clears pendingBranch, and when the stray dep later resolves, it calls `suspense.resolve()` with no pending branch, producing the reported warning. Patch A temporarily nulls pendingBranch during the patch so such deps are not counted, then restores it for the forced resolve. That addresses this sequence directly. Its test models the issue: page B redirects to A during its async setup, and A renders a new async child. The test asserts that no unhandled rejection or error occurs and that the final DOM is correct. Patch B instead changes the same-root-type pending-branch path with a deps++/deps-- guard and tests nested `suspensible` Suspense scenarios. Those scenarios do not involve navigating away during setup and are not the issue's reproduction. Patch B may be a valid hardening for nested suspense, but it does not address the reported toggle-back case. Patch A is the better fix on correctness and test relevance.

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

8m 40s10 turns

Wall-clock time in the container

Full test suite

No new failures

3,702 passed · 6 skipped · 3,708 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

64vs 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+64 −0
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..757bdfcd7 100644@@ -1395,6 +1395,66 @@ describe('Suspense', () => {     expect(calls).toEqual([`one mounted`])   }) +  test('async dep mounted while toggling back to active branch before resolve', async () => {+    // the resolution of async deps happens in a promise chain, so errors+    // thrown there surface as unhandled rejections+    const errors: unknown[] = []+    const onRejection = (err: unknown) => errors.push(err)+    process.on('unhandledRejection', onRejection)++    const AsyncChild = defineAsyncComponent({+      render: () => h('div', 'async child'),+    })+    const view = shallowRef<any>(null)+    const show = ref(false)++    const A = {+      props: ['show'],+      setup(props: any) {+        return () => (props.show ? h(AsyncChild) : h('div', 'a'))+      },+    }+    // page B "navigates" back to A (e.g. router redirect) during its async+    // setup, and A then renders a new async child+    const B = {+      setup() {+        view.value = A+        show.value = true+        return new Promise(r => setTimeout(r, 10))+      },+      render: () => h('div', 'b'),+    }+    view.value = A++    const Comp = {+      setup() {+        return () =>+          h(Suspense, null, {+            default: h(view.value, { show: show.value }),+            fallback: h('div', 'fallback'),+          })+      },+    }++    const root = nodeOps.createElement('div')+    try {+      render(h(Comp), root)+      expect(serializeInner(root)).toBe(`<div>a</div>`)++      view.value = B+      await nextTick()+      expect(deps.length).toBe(1)++      await Promise.all(deps)+      await new Promise(r => setTimeout(r, 20))+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>async child</div>`)+    } finally {+      process.off('unhandledRejection', onRejection)+    }+    expect(errors).toEqual([])+  })+   test('branch switch timeout + fallback', async () => {     const calls: string[] = [] packages/runtime-core/src/components/Suspense.tsindex 8a186fff2..f6f9c8d56 100644@@ -341,6 +341,9 @@ function patchSuspense(         }       } else if (activeBranch && isSameVNodeType(activeBranch, newBranch)) {         // toggled "back" to current active branch+        // the active branch is already resolved, so async deps mounted while+        // patching it must not be counted as pending deps+        suspense.pendingBranch = null         patch(           activeBranch,           newBranch,@@ -353,6 +356,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) { 

What the agent reported

The "without a pending branch" error is fixed. The new regression test fails on the old code and passes with the fix. I reproduced it with a simulated redirect (a shared ref the page's setup changes), not with vue-router or the codesandbox.

What was wrong: say a page has rendered inside <Suspense>, the user moves to a page whose setup() is async, and that setup() sends them back to the first page before it finishes. Suspense then patches the page that is already showing (packages/runtime-core/src/components/Suspense.ts, the "toggled back" branch of patchSuspense). During that patch the suspense still looked like it was waiting on something. So any new async component mounted during the patch was counted as something to wait for. resolve(true) then cleared the pending state, but that count stayed above zero. When the async component later finished, it called suspense.resolve() with nothing pending and threw the error. It's thrown inside a promise, which is why the app keeps working, as the report says.

What I changed (Suspense.ts:344-359, 4 lines): in that branch, the pending state is cleared while the visible page is patched, then put back just before suspense.resolve(true), which still needs it. The page being patched has already resolved, so async components inside it now resolve on their own, as they do in any resolved suspense.

Test evidence:

  • New test: async dep mounted while toggling back to active branch before resolve in packages/runtime-core/__tests__/components/Suspense.spec.ts. Page B's async setup() sends the user back to page A, which then mounts a new async child. The test checks that the child renders and that no error is thrown.
  • Before the fix it failed with "suspense.resolve() is called without a pending branch.".
  • After the fix it passes, as do all 60 tests in that file.
  • The page check alone passes even without the fix, because the child renders before the error. So the test catches the error through a temporary unhandled-rejection listener; that is less direct than a plain assertion.
  • Nearby suites: all 1386 tests in runtime-core and server-renderer pass. In runtime-dom and vue, 290 pass and 1 is skipped. No existing test was changed.
  • Review: a read-only review found the fix correct and the diff limited to these two files. It noted that while the visible page is patched, its effects, transitions and teleports now run as they would on a normal update. That is right for a page already on screen.

Requirements:

  1. No "suspense.resolve() is called without a pending branch" error when a page's setup sends the user to another page: fixed and covered by the new test above.
  2. The app keeps working (it already did): the test checks that the content still renders (<div>async child</div>).
  3. Leaving to some other page instead of going back: no change. Reading the code, that path starts a new pending round and ignores the earlier page's result, so it doesn't reach this error. I didn't write a test for it.

The changes are uncommitted in the working tree.