Backtestsvuerun-20261013-093701#7506

Issue #7506 Merged fix PR #15411 Run 13 Oct 2026 · run-20261013-093701 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.

The issue's scenario: an async-setup component navigates away during setup, so it is unmounted while the suspense is still pending. Its setup promise later settles, and the registerDep callback runs `suspense.resolve()` after the boundary has already resolved or switched branches. That triggers the 'resolve() called without a pending branch' warning.

Patch B targets this root cause directly, in three ways:
- It adds a `!instance.scope.active` check in the registerDep `.then`. `isUnmounted` is set in a post-render effect that is buffered while the suspense is pending, so the existing `isUnmounted` guard misses this case.
- When a component with an unresolved async dep is unmounted, it decrements the suspense's `deps`. If that empties the boundary, it defers `resolve()` to a post-flush callback with pendingId and pendingBranch re-checks, so the boundary still resolves to the replacement content.
- It handles the analogous case of a pending suspensible nested Suspense being unmounted, and removes the placeholder comment of a still-pending async component.

B's tests reproduce the issue directly: a component reassigns the view during async setup, then its setup resolves. The tests cover sync replacement, async replacement, removal by a nested update, and a nested suspensible suspense. They check that nothing stale renders and that onResolve fires exactly once. These would fail before the change.

Patch A only brackets the same-root pending-branch patch with `deps++`/`deps--`. This stops a nested suspensible suspense from resolving the parent mid-patch. It does nothing about an unmounted async component whose setup promise later settles and calls resolve on a boundary with no pending branch. Its tests cover a different nested-suspensible scenario, not the navigate-during-setup case.

B touches more code (renderer unmount path), which adds some risk. But it is guarded carefully and is the only patch that actually fixes the reported bug.

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

16m 5s

Wall-clock time in the container

Full test suite

No new failures

1,801 passed · 1 skipped · 1,802 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

221vs 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+221 −0
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..b3f8cf87a 100644@@ -2879,6 +2879,168 @@ describe('Suspense', () => {     expect(serializeInner(root)).toBe(`<div>B</div>`)   }) +  // #7506+  describe('async setup component unmounted while pending branch is patched', () => {+    function setup(nextAsync: boolean) {+      const rendered: string[] = []+      const resolvers: Record<string, () => void> = {}+      const view = shallowRef<any>(null)+      const Next = nextAsync+        ? defineComponent({+            async setup() {+              await new Promise<void>(r => (resolvers.next = r))+              return () => (rendered.push('next'), h('div', 'next'))+            },+          })+        : { render: () => (rendered.push('next'), h('div', 'next')) }+      const Redirecting = defineComponent({+        async setup() {+          // navigate away during setup (e.g. router.push on error)+          view.value = Next+          await new Promise<void>(r => (resolvers.redirecting = r))+          return () => (rendered.push('redirecting'), h('div', 'redirecting'))+        },+      })+      view.value = Redirecting+      const onResolve = vi.fn()+      // the root of the pending branch keeps its type, so the pending branch+      // is patched in place when the view changes+      const Comp = {+        setup: () => () =>+          h(+            Suspense,+            { onResolve },+            {+              default: () => h('main', [h(view.value)]),+              fallback: h('div', 'fallback'),+            },+          ),+      }+      const root = nodeOps.createElement('div')+      render(h(Comp), root)+      expect(serializeInner(root)).toBe(`<div>fallback</div>`)+      return { root, rendered, resolvers, onResolve }+    }++    test('sync replacement', async () => {+      const { root, rendered, resolvers, onResolve } = setup(false)++      await nextTick()+      expect(serializeInner(root)).toBe(`<main><div>next</div></main>`)+      expect(onResolve).toHaveBeenCalledTimes(1)++      // the unmounted component's async setup settling later is a no-op+      resolvers.redirecting()+      await new Promise(r => setTimeout(r))+      expect(rendered).toEqual(['next'])+      expect(serializeInner(root)).toBe(`<main><div>next</div></main>`)+      expect(onResolve).toHaveBeenCalledTimes(1)+    })++    test('async replacement', async () => {+      const { root, rendered, resolvers, onResolve } = setup(true)++      await nextTick()+      expect(serializeInner(root)).toBe(`<div>fallback</div>`)++      // the unmounted component neither renders nor resolves the suspense+      resolvers.redirecting()+      await new Promise(r => setTimeout(r))+      expect(rendered).toEqual([])+      expect(serializeInner(root)).toBe(`<div>fallback</div>`)+      expect(onResolve).not.toHaveBeenCalled()++      resolvers.next()+      await new Promise(r => setTimeout(r))+      expect(rendered).toEqual(['next'])+      expect(serializeInner(root)).toBe(`<main><div>next</div></main>`)+      expect(onResolve).toHaveBeenCalledTimes(1)+    })++    test('unmounted by a nested component update', async () => {+      const show = ref(true)+      const rendered: string[] = []+      let resolveSlow!: () => void+      const Slow = defineComponent({+        async setup() {+          await new Promise<void>(r => (resolveSlow = r))+          return () => (rendered.push('slow'), h('div', 'slow'))+        },+      })+      // the async child is removed by its parent's own update, not by a+      // patch of the suspense+      const Wrapper = {+        setup: () => () =>+          h('section', [show.value ? h(Slow) : h('div', 'sync')]),+      }+      const onResolve = vi.fn()+      const root = nodeOps.createElement('div')+      render(+        h(+          Suspense,+          { onResolve },+          { default: h(Wrapper), fallback: h('div', 'fallback') },+        ),+        root,+      )+      expect(serializeInner(root)).toBe(`<div>fallback</div>`)++      show.value = false+      await nextTick()+      expect(serializeInner(root)).toBe(`<section><div>sync</div></section>`)+      expect(onResolve).toHaveBeenCalledTimes(1)++      resolveSlow()+      await new Promise(r => setTimeout(r))+      expect(rendered).toEqual([])+      expect(serializeInner(root)).toBe(`<section><div>sync</div></section>`)+      expect(onResolve).toHaveBeenCalledTimes(1)+    })++    test('pending suspensible suspense unmounted', async () => {+      const show = ref(true)+      const rendered: string[] = []+      let resolveSlow!: () => void+      const Slow = defineComponent({+        async setup() {+          await new Promise<void>(r => (resolveSlow = r))+          return () => (rendered.push('slow'), h('div', 'slow'))+        },+      })+      // the nested suspensible suspense is removed while still pending+      const Wrapper = {+        setup: () => () =>+          h('section', [+            show.value+              ? h(Suspense, { suspensible: true }, { default: h(Slow) })+              : h('div', 'sync'),+          ]),+      }+      const onResolve = vi.fn()+      const root = nodeOps.createElement('div')+      render(+        h(+          Suspense,+          { onResolve },+          { default: h(Wrapper), fallback: h('div', 'fallback') },+        ),+        root,+      )+      expect(serializeInner(root)).toBe(`<div>fallback</div>`)++      show.value = false+      await nextTick()+      expect(serializeInner(root)).toBe(`<section><div>sync</div></section>`)+      expect(onResolve).toHaveBeenCalledTimes(1)++      resolveSlow()+      await new Promise(r => setTimeout(r))+      expect(rendered).toEqual([])+      expect(serializeInner(root)).toBe(`<section><div>sync</div></section>`)+      expect(onResolve).toHaveBeenCalledTimes(1)+    })+  })+   describe('warnings', () => {     // base function to check if a combination of slots warns or not     function baseCheckWarn(packages/runtime-core/src/components/Suspense.tsindex 8a186fff2..893d6f1f2 100644@@ -738,8 +738,11 @@ function createSuspenseBoundary(         .then(asyncSetupResult => {           // retry when the setup() promise resolves.           // component may have been unmounted before resolve.+          // (`isUnmounted` is set in a post-render effect that is buffered+          // while the suspense is pending, but the scope is stopped right away)           if (             instance.isUnmounted ||+            !instance.scope.active ||             suspense.isUnmounted ||             suspense.pendingId !== instance.suspenseId           ) {@@ -794,6 +797,30 @@ function createSuspenseBoundary(      unmount(parentSuspense, doRemove) {       suspense.isUnmounted = true+      // #7506 a pending suspensible suspense is unmounted before it resolves,+      // remove it from the deps of its parent suspense+      const parent = suspense.parent+      if (+        isSuspensible &&+        suspense.pendingBranch &&+        parent &&+        parent.pendingBranch &&+        !parent.isUnmounted &&+        parentSuspenseId === parent.pendingId &&+        --parent.deps === 0+      ) {+        const { pendingId } = parent+        queuePostFlushCb(() => {+          if (+            parent.pendingBranch &&+            !parent.isUnmounted &&+            parent.pendingId === pendingId &&+            parent.deps === 0+          ) {+            parent.resolve()+          }+        })+      }       if (suspense.activeBranch) {         unmount(           suspense.activeBranch,packages/runtime-core/src/renderer.tsindex c0fab7373..2d2672e7b 100644@@ -2364,6 +2364,38 @@ function baseCreateRenderer(       // so that scheduler will no longer invoke it       job.flags! |= SchedulerJobFlags.DISPOSED       unmount(subTree, instance, parentSuspense, doRemove)+    } else if (__FEATURE_SUSPENSE__ && subTree) {+      // remove the comment placeholder of a still-pending async setup+      unmount(subTree, instance, parentSuspense, doRemove)+    }++    // #7506 a component with async dep inside a pending suspense is unmounted+    // before its async dep resolves. Remove the dep from the suspense. The+    // suspense must not be resolved synchronously here since we may be in the+    // middle of patching its pending branch (#13453): patchSuspense re-checks+    // deps once the patch is done, otherwise resolve after the current flush.+    const suspense = instance.suspense+    if (+      __FEATURE_SUSPENSE__ &&+      suspense &&+      suspense.pendingBranch &&+      !suspense.isUnmounted &&+      instance.asyncDep &&+      !instance.asyncResolved &&+      instance.suspenseId === suspense.pendingId &&+      --suspense.deps === 0+    ) {+      const { pendingId } = suspense+      queuePostFlushCb(() => {+        if (+          suspense.pendingBranch &&+          !suspense.isUnmounted &&+          suspense.pendingId === pendingId &&+          suspense.deps === 0+        ) {+          suspense.resolve()+        }+      })     }     // unmounted hook     if (um) { 
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) {