Backtestsvuerun-20261003-231210#7506
suspense.resolve() is called without a pending branch.
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Patch B fixes the cause of the warning in the issue; Patch A fixes a different, narrower scenario. The warning appears when a dep is registered while the boundary is pending and settles after the boundary has already resolved. This happens when a pending branch is toggled back to the active one, as when navigating away during setup. When that late dep settles, registerDep's callback decrements `deps` to 0 and calls `resolve()` with `pendingBranch === null`. That is exactly the warning. Patch B adds two guards: - It checks `suspense.pendingBranch` before decrementing and resolving. - It resets `deps = 0` on resolve, so stale counts cannot leak into the next pending cycle. Its tests reproduce this flow: switch to an async branch, switch back while the active branch mounts a new async child (or a nested suspensible Suspense), then check that `onResolve` is not called again and that the next cycle still resolves normally. Before the fix, these tests would trigger an extra resolve or warning, or leave a stale dep count. Patch A wraps the same-root-type patch in `patchSuspense` with `deps++`/`deps--`. This only targets nested suspensible Suspense boundaries resolving the parent mid-patch. It does not touch the registerDep path, where a dep settles after the boundary has resolved, so the reported warning is still possible. Its tests are reasonable, but they exercise a different bug from the one in the issue. On correctness and relevance to the issue, Patch B is clearly better.
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
15m 5s
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
The issue
View on GitHubVue 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
packages/runtime-core/__tests__/components/Suspense.spec.tsindex 6b6373fab..ad38eacff 100644@@ -1395,6 +1395,160 @@ describe('Suspense', () => { expect(calls).toEqual([`one mounted`]) }) + test('branch switch back before resolve mounts async deps in active branch', async () => {+ const AsyncChild = defineAsyncComponent(+ {+ render: () => h('span', 'child'),+ },+ 5,+ )+ const Two = defineAsyncComponent(+ {+ render: () => h('div', 'two'),+ },+ 20,+ )+ const Three = defineAsyncComponent(+ {+ props: ['n'],+ render: () => h('div', 'three'),+ },+ 10,+ )+ const One = {+ props: ['n'],+ render(this: any) {+ return h('div', ['one', this.n ? h(AsyncChild) : null])+ },+ }++ const view = shallowRef<any>(One)+ const n = ref(0)+ const onResolve = vi.fn()+ const Comp = {+ setup() {+ return () =>+ h(+ Suspense,+ { onResolve },+ {+ default: h(view.value, { n: n.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()+ expect(serializeInner(root)).toBe(`<div>one<!----></div>`)++ // switch back before two resolves; the active branch now mounts an+ // async child while the boundary is still pending+ view.value = One+ n.value+++ await nextTick()+ expect(onResolve).toHaveBeenCalledTimes(2)++ await Promise.all(deps)+ await nextTick()+ // the async child resolving must not resolve the boundary again+ expect(serializeInner(root)).toBe(`<div>one<span>child</span></div>`)+ expect(onResolve).toHaveBeenCalledTimes(2)++ // the next pending cycle should resolve normally+ 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 before resolve mounts nested suspensible suspense in active branch', async () => {+ const AsyncChild = defineAsyncComponent(+ {+ render: () => h('span', 'child'),+ },+ 5,+ )+ const Two = defineAsyncComponent(+ {+ render: () => h('div', 'two'),+ },+ 20,+ )+ const Three = defineAsyncComponent(+ {+ props: ['n'],+ render: () => h('div', 'three'),+ },+ 10,+ )+ const One = {+ props: ['n'],+ render(this: any) {+ return h('div', [+ 'one',+ this.n+ ? h(Suspense, { suspensible: true }, { default: h(AsyncChild) })+ : null,+ ])+ },+ }++ const view = shallowRef<any>(One)+ const n = ref(0)+ const onResolve = vi.fn()+ const Comp = {+ setup() {+ return () =>+ h(+ Suspense,+ { onResolve },+ {+ default: h(view.value, { n: n.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()++ // switch back before two resolves; the active branch now mounts a+ // suspensible suspense while the boundary is still pending+ view.value = One+ n.value+++ await nextTick()+ expect(onResolve).toHaveBeenCalledTimes(2)++ await Promise.all(deps)+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>one<span>child</span></div>`)+ expect(onResolve).toHaveBeenCalledTimes(2)++ // the nested suspense dep must not leak into the next pending cycle+ view.value = Three+ await nextTick()+ await Promise.all(deps)+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>three</div>`)+ expect(onResolve).toHaveBeenCalledTimes(3)+ })+ test('branch switch timeout + fallback', async () => { const calls: string[] = [] packages/runtime-core/src/components/Suspense.tsindex 8a186fff2..7e9aab060 100644@@ -617,6 +617,11 @@ function createSuspenseBoundary( setActiveBranch(suspense, pendingBranch!) suspense.pendingBranch = null suspense.isInFallback = false+ // a forced resolve (branch toggled back to the active one) can happen+ // while async deps registered during that patch are still pending.+ // they no longer belong to a pending branch, so drop them from the count+ // to keep it from leaking into the next pending cycle.+ suspense.deps = 0 // flush buffered effects // check if there is a pending parent suspense@@ -786,7 +791,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() } })
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) {