Backtestsvuerun-20261003-231210#15142
Suspense: flushing buffered effects overflows the call stack when many effects accumulate while pending (RangeError: Maximum call stack size exceeded)
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 issue at its root cause: they replace the unbounded `push(...arr)` spreads with plain loops in `queuePostFlushCb`, in the nested `flushPostFlushCbs` merge into `activePostFlushCbs`, and in Suspense's merge into a pending parent's `effects`. Those are exactly the three sites the issue names. Patch B also converts the spread in `queueEffectWithSuspense` (`suspense.effects.push(...fn)`). This is another place where an unbounded array, a component's lifecycle hook array, is spread while the boundary is pending. It is a genuine instance of the same bug class, carries no added risk, and B includes a test for it (1M `onMounted` hooks under a pending Suspense). On tests, A adds only scheduler-level unit tests. Both are valid regressions for the queue and nested-merge paths, but neither touches the Suspense merge-into-parent path it changed. B adds the same scheduler-level coverage plus integration tests through Suspense: - A pending boundary buffering 1M post-watcher jobs, which would throw at `queuePostFlushCb` before the fix. - A nested-Suspense case where the inner boundary's 1M effects merge into a pending parent. This exercises the `parent.effects.push` site and also checks that the effects stay deferred until the outer boundary resolves. - The lifecycle-hook buffering case. These tests mirror the issue's real scenario rather than only the scheduler primitive. Scope and craft are comparable: both keep the loops minimal and add explanatory comments. B's broader fix and more thorough, scenario-faithful tests make it the stronger 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
8m 34s
Wall-clock time in the container
Full test suite
No new failures
3,637 passed · 6 skipped · 3,643 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
188vs 55 merged
Changed lines, ours vs merged
The issue
View on GitHubVue version
3.5.39 (also reproduces on 3.5.40 / @b5f8518 in the playground)
Link to minimal reproduction
Steps to reproduce
- Open the playground and show the Preview pane.
- The app renders a
<Suspense>whose default slot contains an async component (resolves after ~4s) plus a large tree (2000 rows, each with a fewflush: 'post'watchers). - 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(viaqueueEffectWithSuspense). - 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(flushPostFlushCbsnested 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
packages/runtime-core/__tests__/components/Suspense.spec.tsindex d40f85b86..3ef76d7db 100644@@ -3273,4 +3273,145 @@ describe('Suspense', () => { expect(updateSpy).not.toHaveBeenCalled() }) })++ test('should flush a very large number of buffered effects on resolve', async () => {+ const count = ref(0)+ const watchSpy = vi.fn()+ const Sync = defineComponent({+ setup() {+ watch(count, v => watchSpy(v), { flush: 'post' })+ return () => h('div', 'sync')+ },+ })+ const Async = defineAsyncComponent({+ render() {+ return h('div', 'async')+ },+ })+ const Comp = {+ setup() {+ return () =>+ h(Suspense, null, {+ default: h(Fragment, [h(Async), h(Sync)]),+ fallback: h('div', 'fallback'),+ })+ },+ }++ const root = nodeOps.createElement('div')+ render(h(Comp), root)+ expect(serializeInner(root)).toBe(`<div>fallback</div>`)++ // each trigger buffers the post watcher job into suspense.effects+ for (let i = 0; i < 1_000_000; i++) {+ count.value+++ }++ await Promise.all(deps)+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>async</div><div>sync</div>`)+ expect(watchSpy).toHaveBeenCalledTimes(1)+ expect(watchSpy).toHaveBeenCalledWith(1_000_000)+ })++ test('should buffer a very large number of lifecycle hooks while pending', async () => {+ let mountedCalls = 0+ const Sync = defineComponent({+ setup() {+ for (let i = 0; i < 1_000_000; i++) {+ onMounted(() => mountedCalls++)+ }+ return () => h('div', 'sync')+ },+ })+ const Async = defineAsyncComponent({+ render() {+ return h('div', 'async')+ },+ })+ const Comp = {+ setup() {+ return () =>+ h(Suspense, null, {+ default: h(Fragment, [h(Async), h(Sync)]),+ fallback: h('div', 'fallback'),+ })+ },+ }++ const root = nodeOps.createElement('div')+ render(h(Comp), root)+ expect(serializeInner(root)).toBe(`<div>fallback</div>`)+ expect(mountedCalls).toBe(0)++ await Promise.all(deps)+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>async</div><div>sync</div>`)+ expect(mountedCalls).toBe(1_000_000)+ })++ test('should merge a very large number of buffered effects into pending parent suspense', async () => {+ const count = ref(0)+ const watchSpy = vi.fn()+ const Sync = defineComponent({+ setup() {+ watch(count, v => watchSpy(v), { flush: 'post' })+ return () => h('div', 'sync')+ },+ })+ const OuterAsync = defineAsyncComponent(+ {+ render() {+ return h('div', 'outer')+ },+ },+ 10,+ )+ const InnerAsync = defineAsyncComponent(+ {+ render() {+ return h('div', 'inner')+ },+ },+ 1,+ )+ const Comp = {+ setup() {+ return () =>+ h(Suspense, null, {+ default: h(Fragment, [+ h(OuterAsync),+ h(Suspense, null, {+ default: h(Fragment, [h(InnerAsync), h(Sync)]),+ fallback: h('div', 'inner fallback'),+ }),+ ]),+ fallback: h('div', 'outer fallback'),+ })+ },+ }++ const root = nodeOps.createElement('div')+ render(h(Comp), root)+ expect(serializeInner(root)).toBe(`<div>outer fallback</div>`)++ // each trigger buffers the post watcher job into the inner suspense+ for (let i = 0; i < 1_000_000; i++) {+ count.value+++ }++ // inner resolves first, its effects are merged into the pending parent+ await deps[1]+ await nextTick()+ expect(serializeInner(root)).toBe(`<div>outer fallback</div>`)+ expect(watchSpy).not.toHaveBeenCalled()++ await Promise.all(deps)+ await nextTick()+ expect(serializeInner(root)).toBe(+ `<div>outer</div><div>inner</div><div>sync</div>`,+ )+ expect(watchSpy).toHaveBeenCalledTimes(1)+ expect(watchSpy).toHaveBeenCalledWith(1_000_000)+ }) })packages/runtime-core/__tests__/scheduler.spec.tsindex 3e454aec0..e75f59052 100644@@ -522,6 +522,16 @@ describe('scheduler', () => { expect(calls).toEqual(['cb1', 'cb2']) }) + test('queuePostFlushCb with a very large array of cbs', async () => {+ let calls = 0+ const cb = () => calls+++ const cbs = new Array(1_000_000).fill(cb)+ expect(() => queuePostFlushCb(cbs)).not.toThrow()+ await nextTick()+ // cbs are deduped on flush+ expect(calls).toBe(1)+ })+ test('nextTick should capture scheduler flush errors', async () => { const err = new Error('test') queueJob(() => {@@ -844,4 +854,19 @@ describe('scheduler', () => { await nextTick() expect(calls).toEqual(['cb2', 'cb1']) })++ test('nested flushPostFlushCbs with a very large number of cbs', async () => {+ let calls = 0+ const cbs: (() => void)[] = []+ for (let i = 0; i < 500_000; i++) {+ cbs.push(() => calls++)+ }+ queuePostFlushCb(() => {+ queuePostFlushCb(cbs)+ flushPostFlushCbs()+ })+ flushPostFlushCbs()+ await nextTick()+ expect(calls).toBe(500_000)+ }) })packages/runtime-core/src/components/Suspense.tsindex ba5e194ae..a464619cb 100644@@ -617,7 +617,11 @@ function createSuspenseBoundary( if (parent.pendingBranch) { // found a pending parent suspense, merge buffered post jobs // into that parent- parent.effects.push(...effects)+ // avoid spreading into push(): the buffered effects array is+ // unbounded and could exceed the engine's argument limit+ for (let i = 0; i < effects.length; i++) {+ parent.effects.push(effects[i])+ } hasUnresolvedAncestor = true break }@@ -906,7 +910,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..7f794ede6 100644@@ -133,8 +133,12 @@ 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.+ // avoid spreading into push(): large arrays (e.g. effects buffered by a+ // pending suspense) would exceed the engine's argument limit+ 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 }
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 }