Backtestsvuerun-20261001-022054#12575

Issue #12575 Merged fix PR #12601 Run 30 Sep 2026 · run-20261001-022054 vuejs/core

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

Worse

The merged fix was judged better than our patch.

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

Patch B fixes the root cause. It wraps the SSR render-function call in `renderComponentSubTree` with `handleError(err, instance, ErrorCodes.RENDER_FUNCTION)`. Render errors in SSR now go through Vue's normal error-handling chain, so parent `onErrorCaptured` / `errorCaptured` hooks fire for errors raised while rendering the child's template. That covers the issue's case: async setup rejects, then the template crashes on missing data. It also covers render errors in general. Unhandled errors still propagate, because dev `logError` rethrows. Patch B also guards the sync path, returning `Promise.reject` so the same error is not handled twice up the parent chain, and updates existing tests to expect the new 'Unhandled error during execution of render function' warning. Its new test checks that both the setup error and the follow-on template error reach the parent's `onErrorCaptured` and that rendering doesn't crash.

Patch A is a narrow symptom mask. It only acts when async setup was used and `instance.render` is null. In that case it catches any template error, silently swallows it without calling `handleError`, and emits a `<!---->` placeholder. The template error never reaches error-capture hooks. Render errors outside that one path are still unhandled. A bare `catch {}` that hides errors is risky. The manual `popWarningContext` patch-up also shows the approach works around the render pipeline rather than fixing it. Its test is fine but only covers this special case, and the `if (err) throw err` construct is a bit contrived.

On correctness and generality, B is clearly better. Its scope (the sync-path rejection and the test updates) follows directly from the change rather than being unrelated churn.

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 37s18 turns

Wall-clock time in the container

Full test suite

No new failures

3,614 passed · 6 skipped · 3,620 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

48vs 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+47 −1
packages/server-renderer/__tests__/render.spec.tsindex 268c7dc1e..3a22f9b0e 100644@@ -944,6 +944,36 @@ function testRender(type: string, render: typeof renderToString) {       expect(fn2).toBeCalledWith('async child error')     }) +    test('render placeholder when async setup rejects and template throws', async () => {+      const fn = vi.fn()+      const err = new Error('async setup error')++      const Child = defineComponent({+        async setup() {+          await Promise.resolve()+          if (err) throw err+          const data = { msg: 'hello' }+          return { data }+        },+        template: `<span>{{ data.msg }}</span>`,+      })+      const app = createApp({+        errorCaptured(e) {+          fn(e)+          return false+        },+        render: () => h('div', [h(Child)]),+      })++      const html = await render(app)+      expect(html).toBe(`<div><!----></div>`)+      expect(fn).toHaveBeenCalledTimes(1)+      expect(fn).toHaveBeenCalledWith(err)+      expect(+        `Property "data" was accessed during render but is not defined`,+      ).toHaveBeenWarned()+    })+     // https://github.com/vuejs/core/issues/3322     test('effect onInvalidate does not error', async () => {       const noop = () => {}packages/server-renderer/src/render.tsindex 8fc9b0128..94da4b5d3 100644@@ -117,7 +117,23 @@ export function renderComponentVNode(       })       // Note: error display is already done by the wrapped lifecycle hook function.       .catch(NOOP)-    return p.then(() => renderComponentSubTree(instance, slotScopeId))+    return p.then(() => {+      // If async setup rejected, the error has already been reported via+      // handleError and finishComponentSetup never ran, so instance.render+      // is still null. The template may still render if it doesn't depend on+      // setup state (#2763); if it throws, that is a consequence of the+      // already-reported setup error, so render an empty placeholder instead.+      if (hasAsyncSetup && !instance.render) {+        try {+          return renderComponentSubTree(instance, slotScopeId)+        } catch {+          // renderComponentSubTree does not pop its warning context on throw+          if (__DEV__) popWarningContext()+          return [`<!---->`] as SSRBuffer+        }+      }+      return renderComponentSubTree(instance, slotScopeId)+    })   } else {     return renderComponentSubTree(instance, slotScopeId)   } 
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)       } 

What the agent reported

SSR no longer crashes when a child's async setup() throws after an await. The parent's onErrorCaptured fires and the broken child renders as an empty <!---->. The parent still won't switch to its error message in the server HTML, though, and I couldn't fix that part. The changes are uncommitted in the working tree.

What was wrong: when async setup rejects during SSR, runtime-core (component.ts ~line 893) already reports the error to the parent's errorCaptured hooks and app.config.errorHandler. But renderComponentVNode in packages/server-renderer/src/render.ts went on to render the failed child anyway. Its compiled template then ran with no setup state (e.g. reading data.msg on undefined), and that exception crashed the whole renderToString or stream.

What I changed (packages/server-renderer/src/render.ts, about 15 lines inside renderComponentVNode): when async setup has failed, the child's render is wrapped in try/catch. A failed setup is detectable because instance.render stays null (it is always set on success). If that render throws, the error is dropped as a consequence of the setup error already reported, and the child outputs <!---->. Components whose setup succeeded are unaffected, and their render errors still surface as before.

Why I didn't skip the child's template entirely, as the report asks: an existing test, error handling w/ async setup (#2763, render.spec.ts ~line 912), requires a child whose async setup rejected to still render its static template. That contradicts "child template render immediately stopped", and since I'm not allowed to change it, the fix only steps in when the template actually throws.

Test evidence:

  • New test: render placeholder when async setup rejects and template throws in packages/server-renderer/__tests__/render.spec.ts, run for renderToString, renderToNodeStream and pipeToNodeWritable. It reproduces the report's scenario and asserts:
  • the output is <div><!----></div>;
  • errorCaptured is called once with the error;
  • the expected dev warning about data appears.
  • Without the fix: it fails in all three modes with TypeError: Cannot read properties of undefined (reading 'msg').
  • With the fix: ./bt-test packages/server-renderer gives 17 files and 303 tests passed, including #2763.
  • One flaky result: in one run, a garbage-collection test in ssrRender.spec.ts (live weak references) failed. It passed on the full rerun and on 3 more runs of that file, and passed without my change too.

Requirements:

  1. SSR should not crash rendering a child whose setup failed: done, covered by the new test.
  2. onErrorCaptured should fire in SSR: done; the new test asserts it is called once with the error. It was already firing before the fix.
  3. Child template rendering should stop: done only partly. The template is still attempted (required by the #2763 test), but if it throws because data is missing, its output is replaced with <!----> and rendering continues.
  4. The parent should switch to its error message in the server HTML: not done. The parent renders before the child's async setup settles, so a state change in errorCaptured can't re-render it in single-pass SSR. On the client after hydration it behaves normally.

Limitations the reviewer raised that I left alone:

  • Swallowed errors: once setup has failed, any later error thrown while rendering that child (including from grandchildren or slot content) is silently discarded. The only trace is a dev-mode warning.
  • Dev warning traces: if the error comes from a grandchild deeper down, the dev-mode stack used for warning traces can be left one entry too deep, so later warnings in that request may show the wrong component trace.
  • Partial output: teleport content rendered before the error can still appear in the output.

These only happen on the path that used to crash the whole render.