Backtestsvuerun-20261021-133314#12575

Issue #12575 Merged fix PR #12601 Run 21 Oct 2026 · run-20261021-133314 vuejs/core

Vue is not catching errors on server side in SSR when using async child setup

Better

Our patch was judged better than the merged fix.

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

Patch A addresses the root cause: when a component's async setup rejects during SSR, the rejection is re-thrown from the SSR-only catch in setupStatefulComponent (after handleError has already notified errorCaptured/errorHandler), and renderComponentVNode now detects that rejection and emits a `<!---->` placeholder instead of calling renderComponentSubTree with a half-initialized instance. That matches the issue's ask: errorCaptured fires once, the child template is never rendered with missing state, and siblings still render. The rethrow is confined to the isSSR branch and is caught by the renderer's own chain, so the client path is unaffected. Its tests cover await-then-throw, compiled ssrRender, and app.config.errorHandler, and it updates existing expectations that previously encoded the buggy behaviour (rendering children / 'missing template' warnings after a rejected setup). Patch B only wraps the sync render path in try/catch and routes render errors through handleError; it still renders the failed child's template, so the parent receives a second spurious TypeError and props-only templates still emit markup. Its own test enshrines that double-error behaviour, which is the symptom the issue complains about. The independent tests confirm: A passes all four, B fails the three that check the template is not rendered and that only the setup error is captured.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

9m 31s

Wall-clock time in the container

Full test suite

No new failures

1,735 passed · 1 skipped · 1,736 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

163vs 58 merged

Changed lines, ours vs merged

Vue version

3.5.13

Link to minimal reproduction

Vue SFC Playground

Steps to reproduce

Just open a link and you will see errors when SSR is ON.
When SSR is OFF everything works as expected.

Also, commeting the line with top-level await (making Comp.vue a sync component) will also work fine both with and without SSR.

What is expected?

In SSR mode the page is expected to be blank white for 1 second and then display error message from App.vue.
This works as expected with SSR turned off.

Basically onErrorCaptured should be triggered, child setup and <template> render immediately stopped and error message from parent component shown.

What is actually happening?

In SSR mode the page is blank for 1 second but then it tries to render the <template> of Comp.vue using the data that might not even exist (because it appears in setup after throwing error).

And even if it manages to render <template> correctly, it still does not trigger onErrorCaptured in App.vue and do not switch to show error message.

Any additional comments?

I am building a custom rendering package built on top of Vue and it heavily uses structures like these:

 // Wrappers are supposed to catch ALL errors and throws in child <Block /> and show nice error message

<BlockWrapper>
    <Block ... />
</BlockWrapper>

<BlockWrapper>
    <Block ... />
</BlockWrapper>

<BlockWrapper>
    <Block ... />
</BlockWrapper>

...

Because of this bug OR my misunderstanding of how to handle async errors in Vue 3, even when thrown it still tries to render child block's <template> even with missing data (because setup is stopped executing), throws on reading properties of non-existing objects and the whole Nuxt page breaks.

Please, don't tell me this is a no-fix. It would be a disaster... 😭

The two patches

Our patch+148 −15
packages/runtime-core/src/component.tsindex c46741bee..7eeb199f8 100644@@ -898,6 +898,9 @@ function setupStatefulComponent(           })           .catch(e => {             handleError(e, instance, ErrorCodes.SETUP_FUNCTION)+            // re-throw so the server renderer knows setup failed and skips+            // rendering this component's subtree (#12575)+            throw e           })       } else if (__FEATURE_SUSPENSE__) {         // async setup returned Promise.packages/server-renderer/__tests__/render.spec.tsindex 268c7dc1e..35b5ee558 100644@@ -935,7 +935,9 @@ function testRender(type: string, render: typeof renderToString) {       }        const html = await renderToString(app)-      expect(html).toBe(`<div class="app"><div>asyncChildren</div></div>`)+      // #12575 the subtree of a component whose async setup rejected+      // must not be rendered+      expect(html).toBe(`<div class="app"><!----></div>`)        expect(fn).toHaveBeenCalledTimes(1)       expect(fn).toBeCalledWith('async child error')@@ -944,6 +946,108 @@ function testRender(type: string, render: typeof renderToString) {       expect(fn2).toBeCalledWith('async child error')     }) +    // #12575+    test('should not render subtree when async setup throws after await', async () => {+      const captured: unknown[] = []+      const renderChild = vi.fn()+      const prefetch = vi.fn()++      const Child = defineComponent({+        async setup() {+          await new Promise(r => setTimeout(r, 1))+          const fail = true+          if (fail) throw new Error('async setup error')+          // never reached: state used by the template is never created+          return { data: { msg: 'hello' } }+        },+        serverPrefetch: prefetch,+        render(this: any) {+          renderChild()+          return h('div', this.data.msg)+        },+      })++      const app = createApp({+        setup() {+          onErrorCaptured(e => {+            captured.push(e)+            return false+          })+          return () => h('div', [h(Child), h('span', 'after')])+        },+      })++      const html = await render(app)+      expect(html).toBe(`<div><!----><span>after</span></div>`)+      expect(captured.length).toBe(1)+      expect((captured[0] as Error).message).toBe('async setup error')+      expect(renderChild).not.toHaveBeenCalled()+      expect(prefetch).not.toHaveBeenCalled()+    })++    // #12575+    test('should not run compiled ssrRender when async setup throws', async () => {+      const captured: unknown[] = []+      const ssrRenderChild = vi.fn()++      const Child = defineComponent({+        async setup() {+          throw new Error('async setup error')+        },+        ssrRender(_ctx: any, _push: any) {+          ssrRenderChild()+          _push(`<div>${_ctx.data.msg}</div>`)+        },+      })++      const app = createApp({+        errorCaptured(e) {+          captured.push(e)+          return false+        },+        ssrRender(_ctx: any, _push: any, _parent: any) {+          _push(`<div>`)+          _push(ssrRenderComponent(Child, null, null, _parent))+          _push(ssrRenderComponent(Child, null, null, _parent))+          _push(`</div>`)+        },+      })++      const html = await render(app)+      expect(html).toBe(`<div><!----><!----></div>`)+      expect(captured.length).toBe(2)+      expect(ssrRenderChild).not.toHaveBeenCalled()+    })++    // #12575+    test('should render siblings when async setup throws and error is handled by app errorHandler', async () => {+      const handler = vi.fn()++      const Bad = defineComponent({+        async setup() {+          throw new Error('bad')+        },+        template: `<div>{{ data.msg }}</div>`,+      })+      const Good = defineComponent({+        async setup() {+          return { msg: 'good' }+        },+        template: `<p>{{ msg }}</p>`,+      })++      const app = createApp({+        components: { Bad, Good },+        template: `<section><Good /><Bad /><Good /></section>`,+      })+      app.config.errorHandler = handler++      const html = await render(app)+      expect(html).toBe(`<section><p>good</p><!----><p>good</p></section>`)+      expect(handler).toHaveBeenCalledTimes(1)+      expect(handler.mock.calls[0][0].message).toBe('bad')+    })+     // https://github.com/vuejs/core/issues/3322     test('effect onInvalidate does not error', async () => {       const noop = () => {}packages/server-renderer/__tests__/ssrSuspense.spec.tsindex 5f8cecaf9..5b3b6f823 100644@@ -43,7 +43,8 @@ describe('SSR Suspense', () => {     expect(await renderToString(createApp(Comp))).toBe(`<!---->`)      expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)-    expect('missing template').toHaveBeenWarned()+    // #12575 a component whose async setup rejected is not rendered+    expect('missing template').not.toHaveBeenWarned()   })    test('2 components', async () => {@@ -77,7 +78,8 @@ describe('SSR Suspense', () => {     )      expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)-    expect('missing template or render function').toHaveBeenWarned()+    // #12575 a component whose async setup rejected is not rendered+    expect('missing template or render function').not.toHaveBeenWarned()   })    test('failing suspense in passing suspense', async () => {@@ -102,7 +104,8 @@ describe('SSR Suspense', () => {     )      expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)-    expect('missing template').toHaveBeenWarned()+    // #12575 a component whose async setup rejected is not rendered+    expect('missing template').not.toHaveBeenWarned()   })    // nuxt/nuxt#28162@@ -148,6 +151,7 @@ describe('SSR Suspense', () => {       `<div><!----><div><div>async</div></div></div>`,     )     expect(Comp.errorCaptured).toHaveBeenCalledTimes(1)-    expect('missing template').toHaveBeenWarned()+    // #12575 a component whose async setup rejected is not rendered+    expect('missing template').not.toHaveBeenWarned()   }) })packages/server-renderer/src/render.tsindex 8fc9b0128..52f71d431 100644@@ -105,24 +105,46 @@ export function renderComponentVNode(   const hasAsyncSetup = isPromise(res)   let prefetches = instance.sp /* LifecycleHooks.SERVER_PREFETCH */   if (hasAsyncSetup || prefetches) {+    let setupFailed = false     const p: Promise<unknown> = Promise.resolve(res as Promise<void>)-      .then(() => {-        // instance.sp may be null until an async setup resolves, so evaluate it here-        if (hasAsyncSetup) prefetches = instance.sp-        if (prefetches) {-          return Promise.all(-            prefetches.map(prefetch => prefetch.call(instance.proxy)),-          )-        }-      })+      .then(+        () => {+          // instance.sp may be null until an async setup resolves, so evaluate it here+          if (hasAsyncSetup) prefetches = instance.sp+          if (prefetches) {+            return Promise.all(+              prefetches.map(prefetch => prefetch.call(instance.proxy)),+            )+          }+        },+        () => {+          // async setup rejected. The error has already been passed to+          // handleError (errorCaptured / app.config.errorHandler) during+          // setup. The component never finished setup, so it must not be+          // rendered with incomplete state (#12575).+          setupFailed = true+        },+      )       // Note: error display is already done by the wrapped lifecycle hook function.       .catch(NOOP)-    return p.then(() => renderComponentSubTree(instance, slotScopeId))+    return p.then(() =>+      setupFailed+        ? renderFailedComponent()+        : renderComponentSubTree(instance, slotScopeId),+    )   } else {     return renderComponentSubTree(instance, slotScopeId)   } } +function renderFailedComponent(): SSRBuffer {+  // render a placeholder comment, same as the client does for a component+  // that fails to render+  const { getBuffer, push } = createBuffer()+  push(`<!---->`)+  return getBuffer()+}+ function renderComponentSubTree(   instance: ComponentInternalInstance,   slotScopeId?: string, 
Merged fix · PR #12601+55 −3
packages/server-renderer/__tests__/render.spec.tsindex 268c7dc1e..f537a6219 100644@@ -12,6 +12,7 @@ import {   defineComponent,   getCurrentInstance,   h,+  nextTick,   onErrorCaptured,   onServerPrefetch,   reactive,@@ -822,6 +823,9 @@ function testRender(type: string, render: typeof renderToString) {           )         } catch {}         expect(getCurrentInstance()).toBe(prev)+        expect(+          '[Vue warn]: Unhandled error during execution of render function',+        ).toHaveBeenWarned()       })        // #7733@@ -1191,6 +1195,40 @@ function testRender(type: string, render: typeof renderToString) {       expect((capturedError as unknown as Error).message).toBe('An error')     }) +    test('async setup throwing error', async () => {+      const capturedError: string[] = []++      const Child = {+        async setup() {+          await nextTick()+          throw new Error('An error')+          return { foo: { bar: 1 } }+        },+        template: `<span>{{ foo.bar }}</span>`,+      }++      const app = createApp({+        components: { Child },+        setup() {+          onErrorCaptured(e => {+            capturedError.push(e.message)+            return false+          })+        },+        template: `<Suspense><Child /></Suspense>`,+      })++      expect(await render(app)).toBe('')+      expect(capturedError.length).toBe(2)+      expect(capturedError).toStrictEqual([+        'An error',+        "Cannot read properties of undefined (reading 'bar')",+      ])+      expect(+        '[Vue warn]: Property "foo" was accessed during render but is not defined on instance',+      ).toHaveBeenWarned()+    })+     test('computed reactivity during SSR with onServerPrefetch', async () => {       const store = {         // initial state could be hydratedpackages/server-renderer/__tests__/ssrSuspense.spec.tsindex 5f8cecaf9..2cc3da1cd 100644@@ -107,9 +107,10 @@ describe('SSR Suspense', () => {    // nuxt/nuxt#28162   test('propagates sync errors from compiled ssrRenderSuspense default slot', async () => {+    const error = new TypeError('bang')     const Throwing = defineComponent({       ssrRender(_ctx: any, _push: any) {-        throw new TypeError('bang')+        throw error       },     }) @@ -124,7 +125,10 @@ describe('SSR Suspense', () => {       },     }) -    await expect(renderToString(createApp(Root))).rejects.toThrow('bang')+    await expect(renderToString(createApp(Root))).rejects.toBe(error)+    expect(+      '[Vue warn]: Unhandled error during execution of render function',+    ).toHaveBeenWarnedTimes(1)   })    test('passing suspense in failing suspense', async () => {packages/server-renderer/src/render.tsindex 8fc9b0128..c2bde4d1e 100644@@ -3,6 +3,7 @@ import {   type Component,   type ComponentInternalInstance,   type DirectiveBinding,+  ErrorCodes,   Fragment,   type FunctionalComponent,   Static,@@ -10,6 +11,7 @@ import {   type VNode,   type VNodeArrayChildren,   type VNodeProps,+  handleError,   mergeProps,   ssrUtils,   warn,@@ -119,7 +121,13 @@ export function renderComponentVNode(       .catch(NOOP)     return p.then(() => renderComponentSubTree(instance, slotScopeId))   } else {-    return renderComponentSubTree(instance, slotScopeId)+    try {+      return renderComponentSubTree(instance, slotScopeId)+    } catch (err) {+      // let the SSR buffer propagate the error so parent render functions+      // don't handle the same error again+      return Promise.reject(err)+    }   } } @@ -201,6 +209,8 @@ function renderComponentSubTree(           instance.data,           instance.ctx,         )+      } catch (err) {+        handleError(err, instance, ErrorCodes.RENDER_FUNCTION)       } finally {         setCurrentRenderingInstance(prev)       }