Backtestsvuerun-20261013-093701#15142

Issue #15142 Merged fix PR #15143 Run 13 Oct 2026 · run-20261013-093701 vuejs/core

Suspense: flushing buffered effects overflows the call stack when many effects accumulate while pending (RangeError: Maximum call stack size exceeded)

Better

Our patch was judged better than the merged fix.

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

Both patches fix the three spread sites the issue names in the same way, replacing each spread with an index loop: `pendingPostFlushCbs.push(...cb)` in `queuePostFlushCb`, `activePostFlushCbs.push(...deduped)` in the nested `flushPostFlushCbs` path, and `parent.effects.push(...effects)` in Suspense's merge into a pending parent. Their core correctness is equivalent. B also converts the spread in `queueEffectWithSuspense` (`suspense.effects.push(...fn)`). That site is another place where an array is spread into call arguments on the same buffering path. This is low-risk hardening and neutral under the scope criterion, but it does close a real remaining spread site. The tests are the main difference. A adds two scheduler-level tests covering `queuePostFlushCb` and the nested active-flush merge, but nothing exercises the Suspense parent-merge fix it made. B adds the same two scheduler tests plus two Suspense integration tests. The first resolves a pending boundary holding 1M buffered effects, which is the issue's actual scenario. The second resolves an inner Suspense while the outer is still pending, which directly exercises the `parent.effects` merge. Each of these would fail before the change, and they assert correct rendering and effect counts. B's nested scheduler test also isolates the nested-flush path by queuing callbacks individually. With the same fixes and stronger, more complete regression coverage of every changed site, B is the better patch.

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

5m 6s

Wall-clock time in the container

Full test suite

No new failures

1,746 passed · 1 skipped · 1,747 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

144vs 55 merged

Changed lines, ours vs merged

Vue version

3.5.39 (also reproduces on 3.5.40 / @b5f8518 in the playground)

Link to minimal reproduction

https://play.vuejs.org/#eNp9VMuO4zYQ/JWCcrCE0VhKkL14JQGDRQ65BIOZALkIWNBSyyJMk1ySkmAYAvYj8g35sP2SgJRszz6wJ5PN7nJ3VbUu0ZPW23GgaBcVtjFcO1hyg65qyU9aGYcLDHUpWuq4pCd7ls0HddJKknSY0Rl1wmYcaHMreFHTGt5mL2raLo+1zDIwCeYR0PRctHA9czgSaQvXE4rXwWqSlipoki2XB3TKgKGjCZYaJVubBhzBjwQGzQ6Eph/kEXvy6UKxllq0g/G31+cnSDbyA3NcyVo2SlqHV6GmD+Hvyx8OFdcSiBOUlT8AkiY8G3XilmJDVomRUFa4LK/wdP3NT6QGF4cqrEnxBY5OWjBHO2yKlo/V29mXVovMxzeYkxS/53meLKhzktYyqW89O94cUXohYp+SZZh6LiiwZlfSwO2VtjSQCkOPhmRLgQyfuucHOEO0EM9tQLKOC4GTGqSjFoPPB3eIV46PTO6ZxF4x02LQLXMejUYy51WT5Noll47MyARKT8qf621lJfDl59iOTAz08ODvvEN8j6HCr3meoBHEzK38iprUck7xLn9Di1GTRYknY9h56y0XXyBIHly/w295nmNOEX9MwUMHPKllkS0mrzxIcdUnKH1336JBUOwqcnF3TXYPeqePj50yZR0ZcBkaqiPsjnT2IX/045V15H/q6Fa86L6er23gl44JsWfNsQqCXy6L8POML5//xcS4u+3E3UlfPv9XZF9Pkr0Z5au3KI3WjfzZvk/MNX0Kp16o+2bFr8xro7S9LdCzv8VLtzv8NZz2ZDAn37g34MWhMsXGBzfJ+l0g1vSePOyHriNjYb3BmIBW1j12YrA9qOuocd7jZvEh3ZcggGhm/DfpB/uA+NNAA/0REP7hrr/yk9TSsxkLcuAokb8HR4F378EfHpLFs4GN4NIUq5XnFBeErnbY+BY3Ydr55/6ymklYdxZU1lHLrRbsvINUkuqoumtdZD7xO+Xm/wFAmvDh

Steps to reproduce

  1. Open the playground and show the Preview pane.
  2. The app renders a <Suspense> whose default slot contains an async component (resolves after ~4s) plus a large tree (2000 rows, each with a few flush: 'post' watchers).
  3. While the suspense is pending, a timer keeps mutating a ref, so the still-mounted tree re-renders repeatedly. Each re-render buffers its post effects into suspense.effects (via queueEffectWithSuspense).
  4. When the async component resolves, the suspense flushes the buffered effects.

What is expected?

The buffered effects flush and the app keeps working.

What is actually happening?

Uncaught (in promise): RangeError: Maximum call stack size exceeded — thrown from queuePostFlushCb called by suspense.resolve():

RangeError: Maximum call stack size exceeded
    at queuePostFlushCb (runtime-core.esm-bundler.js:331)
    at Object.resolve   (runtime-core.esm-bundler.js:7426)

The scheduler dies mid-flush, leaving the app permanently wedged (blank page).

Root cause

suspense.effects is unbounded — every post effect of every component under a pending suspense boundary is buffered into it. On resolve, the whole array is flushed with a spread call:

  • scheduler.ts: pendingPostFlushCbs.push(...cb)
  • scheduler.ts (flushPostFlushCbs nested case): activePostFlushCbs.push(...deduped)
  • Suspense.ts (merge into pending parent): parent.effects.push(...effects)

Spreading an array into a function call is limited by the engine's call stack (~100k–200k args in V8), so once enough effects accumulate the flush itself throws.

Real-world impact

We hit this in production in a Nuxt app: a kanban board page with ~1000 mounted cards that re-renders once per second (elapsed-time ticker). Navigating to another page keeps the board mounted under <NuxtPage>'s pending Suspense; its buffered effects exceed the spread limit and every SPA navigation away from the board crashes with a permanent white screen (hard reload of the target URL works fine, since there is no pending suspense in that case).

Suggested fix

Replace the unbounded spread pushes with plain loops. I have a PR ready with the fix and a regression test (queuePostFlushCb with a 1M-entry array).

The two patches

Our patch+139 −5
packages/runtime-core/__tests__/components/Suspense.spec.tsindex d40f85b86..c7dd5e966 100644@@ -43,7 +43,10 @@ import {   provide, } from 'vue' import type { RawSlots } from '../../src/componentSlots'-import { resetSuspenseId } from '../../src/components/Suspense'+import {+  queueEffectWithSuspense,+  resetSuspenseId,+} from '../../src/components/Suspense' import { PatchFlags } from '@vue/shared'  describe('Suspense', () => {@@ -747,6 +750,103 @@ describe('Suspense', () => {     expect(calls).toEqual([`inner mounted`, `outer mounted`])   }) +  // #15142+  describe('flushing a very large number of buffered effects', () => {+    const N = 1_000_000+    let count = 0++    // buffers N post effects into the nearest pending suspense boundary+    const BufferEffects = {+      setup() {+        const suspense = getCurrentInstance()!.suspense+        queueEffectWithSuspense(+          Array.from({ length: N }, () => () => count++),+          suspense,+        )+        return () => h('div', 'sync')+      },+    }++    beforeEach(() => {+      count = 0+    })++    test('on resolve', async () => {+      const Async = defineAsyncComponent({+        render() {+          return h('div', 'async')+        },+      })+      const Comp = {+        setup() {+          return () =>+            h(Suspense, null, {+              default: h('div', [h(Async), h(BufferEffects)]),+              fallback: h('div', 'fallback'),+            })+        },+      }++      const root = nodeOps.createElement('div')+      render(h(Comp), root)+      expect(serializeInner(root)).toBe(`<div>fallback</div>`)+      expect(count).toBe(0)++      await Promise.all(deps)+      await nextTick()+      expect(serializeInner(root)).toBe(+        `<div><div>async</div><div>sync</div></div>`,+      )+      expect(count).toBe(N)+    })++    test('when merged into a pending parent suspense', async () => {+      const AsyncOuter = defineAsyncComponent(+        { render: () => h('div', 'async outer') },+        10,+      )+      const AsyncInner = defineAsyncComponent(+        { render: () => h('div', 'async inner') },+        1,+      )+      const Inner = {+        setup() {+          return () =>+            h(Suspense, null, {+              default: h('div', [h(AsyncInner), h(BufferEffects)]),+              fallback: h('div', 'fallback inner'),+            })+        },+      }+      const Comp = {+        setup() {+          return () =>+            h(Suspense, null, {+              default: h('div', [h(AsyncOuter), h(Inner)]),+              fallback: h('div', 'fallback outer'),+            })+        },+      }++      const root = nodeOps.createElement('div')+      render(h(Comp), root)+      expect(serializeInner(root)).toBe(`<div>fallback outer</div>`)++      // inner resolves first: its buffered effects merge into the outer+      await deps[1]+      await nextTick()+      expect(serializeInner(root)).toBe(`<div>fallback outer</div>`)+      expect(count).toBe(0)++      await Promise.all(deps)+      await nextTick()+      expect(serializeInner(root)).toBe(+        `<div><div>async outer</div><div><div>async inner</div><div>sync</div></div></div>`,+      )+      expect(count).toBe(N)+    })+  })+   test('error handling', async () => {     const Async = {       async setup() {packages/runtime-core/__tests__/scheduler.spec.tsindex 3e454aec0..8a2a688e9 100644@@ -844,4 +844,27 @@ describe('scheduler', () => {     await nextTick()     expect(calls).toEqual(['cb2', 'cb1'])   })++  // #15142+  test('queuePostFlushCb with a very large array of callbacks', async () => {+    let count = 0+    const cbs = Array.from({ length: 1_000_000 }, () => () => count++)+    expect(() => queuePostFlushCb(cbs)).not.toThrow()+    await nextTick()+    expect(count).toBe(1_000_000)+  })++  // #15142+  test('nested flushPostFlushCbs with a very large array of callbacks', async () => {+    let count = 0+    const cbs = Array.from({ length: 1_000_000 }, () => () => count++)+    queuePostFlushCb(() => {+      // queue individually so only the nested flush handles the large batch+      cbs.forEach(cb => queuePostFlushCb(cb))+      flushPostFlushCbs()+    })+    flushPostFlushCbs()+    await nextTick()+    expect(count).toBe(1_000_000)+  }) })packages/runtime-core/src/components/Suspense.tsindex ba5e194ae..82f70910d 100644@@ -617,7 +617,10 @@ function createSuspenseBoundary(         if (parent.pendingBranch) {           // found a pending parent suspense, merge buffered post jobs           // into that parent-          parent.effects.push(...effects)+          // avoid spread push: effects can be too large for call arguments+          for (let i = 0; i < effects.length; i++) {+            parent.effects.push(effects[i])+          }           hasUnresolvedAncestor = true           break         }@@ -906,7 +909,9 @@ export function queueEffectWithSuspense( ): void {   if (suspense && suspense.pendingBranch) {     if (isArray(fn)) {-      suspense.effects.push(...fn)+      for (let i = 0; i < fn.length; i++) {+        suspense.effects.push(fn[i])+      }     } else {       suspense.effects.push(fn)     }packages/runtime-core/src/scheduler.tsindex af6752078..a1830f886 100644@@ -134,7 +134,11 @@ export function queuePostFlushCb(cb: SchedulerJobs): void {     // if cb is an array, it is a component lifecycle hook which can only be     // triggered by a job, which is already deduped in the main queue, so     // we can skip duplicate check here to improve perf-    pendingPostFlushCbs.push(...cb)+    // use a loop instead of spread push to avoid call stack overflow when+    // the array is very large (e.g. effects buffered by a pending suspense)+    for (let i = 0; i < cb.length; i++) {+      pendingPostFlushCbs.push(cb[i])+    }   }   queueFlush() }@@ -179,7 +183,9 @@ export function flushPostFlushCbs(seen?: CountMap): void {      // #1947 already has active queue, nested flushPostFlushCbs call     if (activePostFlushCbs) {-      activePostFlushCbs.push(...deduped)+      for (let i = 0; i < deduped.length; i++) {+        activePostFlushCbs.push(deduped[i])+      }       return     }  
Merged fix · PR #15143+51 −4
packages/runtime-core/__tests__/scheduler.spec.tsindex 3e454aec0..000a0d578 100644@@ -303,6 +303,44 @@ describe('scheduler', () => {       expect(calls).toEqual(['cb1', 'cb2', 'cb3'])     }) +    it('should not overflow the call stack with a very large cb array', async () => {+      // a suspense boundary can buffer an unbounded number of post effects+      // while pending (e.g. a large tree re-rendering under it) and flush them+      // all at once on resolve - spreading such an array into push() throws+      // RangeError: Maximum call stack size exceeded+      let called = 0+      const cbs: SchedulerJob[] = []+      for (let i = 0; i < 1000000; i++) {+        cbs.push(() => {+          called+++        })+      }++      queuePostFlushCb(cbs)+      await nextTick()+      expect(called).toBe(1000000)+    })++    it('should not overflow the call stack when merging a very large cb array into an active flush', async () => {+      // same as above, but the large array is queued while a post flush is+      // already in progress, exercising the merge into activePostFlushCbs+      // inside a nested flushPostFlushCbs call+      let called = 0+      const cbs: SchedulerJob[] = []+      for (let i = 0; i < 1000000; i++) {+        cbs.push(() => {+          called+++        })+      }++      queuePostFlushCb(() => {+        queuePostFlushCb(cbs)+        flushPostFlushCbs()+      })+      await nextTick()+      expect(called).toBe(1000000)+    })+     it('should dedupe queued postFlushCb', async () => {       const calls: string[] = []       const cb1 = () => {packages/runtime-core/src/components/Suspense.tsindex ba5e194ae..37e5067ff 100644@@ -617,7 +617,9 @@ function createSuspenseBoundary(         if (parent.pendingBranch) {           // found a pending parent suspense, merge buffered post jobs           // into that parent-          parent.effects.push(...effects)+          for (let i = 0; i < effects.length; i++) {+            parent.effects.push(effects[i])+          }           hasUnresolvedAncestor = true           break         }packages/runtime-core/src/scheduler.tsindex af6752078..4355018a0 100644@@ -133,8 +133,13 @@ export function queuePostFlushCb(cb: SchedulerJobs): void {   } else {     // if cb is an array, it is a component lifecycle hook which can only be     // triggered by a job, which is already deduped in the main queue, so-    // we can skip duplicate check here to improve perf-    pendingPostFlushCbs.push(...cb)+    // we can skip duplicate check here to improve perf.+    // use a loop instead of `push(...cb)`: the array can be arbitrarily large+    // (e.g. effects buffered by a suspense boundary) and spreading it would+    // overflow the call stack (#15142)+    for (let i = 0; i < cb.length; i++) {+      pendingPostFlushCbs.push(cb[i])+    }   }   queueFlush() }@@ -179,7 +184,9 @@ export function flushPostFlushCbs(seen?: CountMap): void {      // #1947 already has active queue, nested flushPostFlushCbs call     if (activePostFlushCbs) {-      activePostFlushCbs.push(...deduped)+      for (let i = 0; i < deduped.length; i++) {+        activePostFlushCbs.push(deduped[i])+      }       return     }