Backtestsvuerun-20261007-145226#7506

Issue #7506 Merged fix PR #15411 Run 7 Oct 2026 · run-20261007-145226 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 happens when a pending branch's async setup navigates back to the active branch. That forces a resolve and clears `pendingBranch`. When the abandoned async dep later settles, `registerDep` still decrements `deps` and calls `suspense.resolve()` with no pending branch, which triggers the warning. Patch A fixes exactly this. It adds a `suspense.pendingBranch` guard before decrementing and resolving in `registerDep`, and it resets `suspense.deps = 0` on resolve so stale deps don't gate the next pending branch. Its tests reproduce the issue's scenario (B's async setup sets the page back to A), check that no errors occur and that `onResolve` counts are correct, and confirm a later pending branch (D) still waits for its own dep. A second test covers a nested suspensible suspense in the same toggle-back case. Patch B instead wraps the same-root-type pending patch in `deps++`/`deps--` to stop a nested suspensible suspense from resolving the parent mid-patch. That is a different edge case. It does not touch the toggle-back path or the late-settling dep callback, so the reported warning would still appear. Its tests target nested-suspensible timing, not navigation during a pending component's setup. Patch A is correct for the reported problem and well tested; Patch B misses the root cause.

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

10m 9s

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

165vs 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+164 −1
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..b05a7ea5f 100644@@ -2879,6 +2879,161 @@ describe('Suspense', () => {     expect(serializeInner(root)).toBe(`<div>B</div>`)   }) +  test('toggling back to active branch which mounts new async deps while pending', async () => {+    const page = ref('A')+    const showAsyncChild = ref(false)++    const AsyncChild = defineAsyncComponent({+      render: () => h('div', 'async child'),+    })+    const PageA = {+      props: ['showAsyncChild'],+      setup(props: any) {+        return () =>+          h('div', ['A', props.showAsyncChild ? h(AsyncChild) : null])+      },+    }+    const PageB = {+      async setup() {+        // navigate back to A during B's async setup (B is still pending), and+        // A now renders a new async dep+        page.value = 'A'+        showAsyncChild.value = true+        return () => h('div', 'B')+      },+    }+    const PageC = {+      render: () => h('div', 'C'),+    }+    const PageD = defineAsyncComponent({+      render: () => h('div', 'D'),+    })++    const onResolve = vi.fn()+    const Comp = {+      setup() {+        return () =>+          h(+            Suspense,+            { onResolve },+            {+              default: () =>+                page.value === 'A'+                  ? h(PageA, { showAsyncChild: showAsyncChild.value })+                  : page.value === 'B'+                    ? h(PageB)+                    : page.value === 'C'+                      ? h(PageC)+                      : h(PageD),+              fallback: h('div', 'fallback'),+            },+          )+      },+    }++    const errors: unknown[] = []+    const onRejection = (err: unknown) => errors.push(err)+    process.on('unhandledRejection', onRejection)+    try {+      const root = nodeOps.createElement('div')+      render(h(Comp), root)+      expect(serializeInner(root)).toBe(`<div>A<!----></div>`)+      expect(onResolve).toHaveBeenCalledTimes(1)++      // A -> B (pending), B's setup toggles back to A+      page.value = 'B'+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>A<!----></div>`)++      await Promise.all(deps)+      await nextTick()+      await new Promise(r => setTimeout(r))+      expect(errors).toEqual([])+      expect(serializeInner(root)).toBe(`<div>A<div>async child</div></div>`)+      expect(onResolve).toHaveBeenCalledTimes(2)++      // the late async child must not affect the next pending branch's deps:+      // D stays pending until its own async dep resolves+      deps.length = 0+      page.value = 'D'+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>A<div>async child</div></div>`)+      expect(onResolve).toHaveBeenCalledTimes(2)+      await Promise.all(deps)+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>D</div>`)+      expect(onResolve).toHaveBeenCalledTimes(3)++      // the boundary keeps working afterwards+      page.value = 'C'+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>C</div>`)+      expect(errors).toEqual([])+    } finally {+      process.off('unhandledRejection', onRejection)+    }+  })++  test('toggling back to active branch which mounts a nested suspensible suspense while pending', async () => {+    const page = ref('A')+    const showNested = ref(false)++    const AsyncChild = defineAsyncComponent({+      render: () => h('div', 'async child'),+    })+    const PageA = {+      props: ['showNested'],+      setup(props: any) {+        return () =>+          h('div', [+            'A',+            props.showNested+              ? h(Suspense, { suspensible: true }, { default: h(AsyncChild) })+              : null,+          ])+      },+    }+    const PageB = {+      async setup() {+        page.value = 'A'+        showNested.value = true+        return () => h('div', 'B')+      },+    }+    const PageC = {+      render: () => h('div', 'C'),+    }++    const Comp = {+      setup() {+        return () =>+          h(Suspense, null, {+            default: () =>+              page.value === 'A'+                ? h(PageA, { showNested: showNested.value })+                : page.value === 'B'+                  ? h(PageB)+                  : h(PageC),+          })+      },+    }++    const root = nodeOps.createElement('div')+    render(h(Comp), root)+    expect(serializeInner(root)).toBe(`<div>A<!----></div>`)++    page.value = 'B'+    await nextTick()+    await Promise.all(deps)+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>A<div>async child</div></div>`)++    // the nested suspense's dep must not keep the outer boundary pending+    page.value = 'C'+    await nextTick()+    expect(serializeInner(root)).toBe(`<div>C</div>`)+  })+   describe('warnings', () => {     // base function to check if a combination of slots warns or not     function baseCheckWarn(packages/runtime-core/src/components/Suspense.tsindex 8a186fff2..04a41d8c2 100644@@ -617,6 +617,10 @@ function createSuspenseBoundary(       setActiveBranch(suspense, pendingBranch!)       suspense.pendingBranch = null       suspense.isInFallback = false+      // a forced resolve (toggling back to the active branch) may leave deps+      // registered while patching the active branch. They no longer gate this+      // boundary, so drop them to avoid blocking the next pending branch.+      suspense.deps = 0        // flush buffered effects       // check if there is a pending parent suspense@@ -786,7 +790,11 @@ function createSuspenseBoundary(             popWarningContext()           }           // only decrease deps count if suspense is not already resolved-          if (isInPendingSuspense && --suspense.deps === 0) {+          if (+            isInPendingSuspense &&+            suspense.pendingBranch &&+            --suspense.deps === 0+          ) {             suspense.resolve()           }         }) 
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) {