Repository navigation
Conversation
Nuxt 4.7 added SSR support to <NuxtErrorBoundary>, rendering its #error slot and returning HTTP 200 when a component errors during SSR. These errors were never forwarded to Sentry because Nitro's error hook only catches uncaught errors, and the client plugin does not receive vue:error during hydration. This registers a server-side Nuxt app plugin that listens to vue:error on the server and captures caught errors during app:rendered, unless the page errored fatally (nuxtApp.payload.error).
66b8cea to
ecc2714
Compare
|
@JPeer264 @chargome @nicohrubec I've implemented a fix for this by adding a server-only plugin (error-boundary.server.ts) that listens to vue:error during SSR and flushes caught errors on app:rendered using reportNuxtError. It skips reporting if nuxtApp.payload.error is present (so fatal page errors continue to be handled by Nitro without duplication) and filters out 3xx/4xx control-flow errors. Unit test coverage has been added. Please do review it |
Avoid deferring via setTimeout so events are captured before Cloudflare or serverless request wrappers dispose the client. Calls flushIfServerless on app:rendered to ensure pending envelopes are dispatched.
|
@pranav514 can you please stop pinging random people from the team. we see that you opened a PR and we'll get to it. |
Sure I'll take care |
| function isIgnoredNuxtError(error: unknown): boolean { | ||
| if (!isNuxtError(error)) { | ||
| return false; | ||
| } | ||
| // oxlint-disable-next-line typescript/no-deprecated | ||
| const statusCode = error?.status || error?.statusCode; | ||
| return !!statusCode && statusCode >= 300 && statusCode < 500; | ||
| } |
There was a problem hiding this comment.
This function already exists in sentry.client.ts and can be reused. We can put this function into an utils file so it's shared and then re-use it from there.
| return !!statusCode && statusCode >= 300 && statusCode < 500; | ||
| } | ||
|
|
||
| export default defineNuxtPlugin(nuxtApp => { |
There was a problem hiding this comment.
This plugin is re-writing a lot of code that already exists. By reusing the things we already have, this can be condensed to just this:
export default defineNuxtPlugin(nuxtApp => {
const caught: Parameters<typeof reportNuxtError>[0][] = [];
nuxtApp.hook('vue:error', (error, instance, info) => {
if (!isIgnoredNuxtError(error)) caught.push({ error, instance, info });
});
// The Nitro `error` hook reports errors that end on the error page.
nuxtApp.hook('app:rendered', () => {
if (!nuxtApp.payload.error) caught.forEach(reportNuxtError);
});
});| addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' }); | ||
| } | ||
|
|
||
| addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/error-boundary.server'), mode: 'server' }); |
There was a problem hiding this comment.
Could we add this plugin only when nuxt.options.experimental.ssrErrorBoundary is on?
Otherwise, the hooks just run without doing anything.
There was a problem hiding this comment.
I'd replace the unit tests with one E2E case in nuxt-5: a component that throws during SSR inside <NuxtErrorBoundary>, with a check that the page returns 200 and the error reaches Sentry. These mocks can't show that Nuxt actually calls vue:error.
- Share isIgnoredNuxtError in runtime utils for both client and server plugins - Condense error-boundary.server.ts to reuse reportNuxtError - Register plugin only when experimental.ssrErrorBoundary is enabled - Replace unit tests with an E2E test in nuxt-5 test application
|
@s1gr1d Addressed all feedback: Extracted isIgnoredNuxtError to shared runtime utils and reused it in both sentry.client.ts and error-boundary.server.ts. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit baa820c. Configure here.
|
|
||
| const error = await errorPromise; | ||
|
|
||
| expect(error.transaction).toEqual('/ssr-error-boundary'); |
There was a problem hiding this comment.
| expect(error.transaction).toEqual('/ssr-error-boundary'); | |
| expect(error.transaction).toEqual('GET /ssr-error-boundary'); |
could be that this is with GET as this is the server-side.
| } | ||
|
|
||
| // oxlint-disable-next-line typescript/no-unsafe-member-access | ||
| if (nuxt.options.experimental && (nuxt.options.experimental as Record<string, unknown>).ssrErrorBoundary) { |
There was a problem hiding this comment.
| if (nuxt.options.experimental && (nuxt.options.experimental as Record<string, unknown>).ssrErrorBoundary) { | |
| if ((nuxt.options.experimental as { ssrErrorBoundary?: boolean }).ssrErrorBoundary) { |
| experimental: { | ||
| ssrErrorBoundary: true, | ||
| }, |
There was a problem hiding this comment.
This is on by default, so we can remove this flag.
- Use inline type for experimental.ssrErrorBoundary check - Remove redundant experimental flag from Nuxt 5 test app config - Expect HTTP method in server error transaction name - Assert error fallback visibility instead of matching sanitized error text
|
@s1gr1d Thanks for the review! Applied all suggested updates: Switched to the inline type check (nuxt.options.experimental as { ssrErrorBoundary?: boolean }).ssrErrorBoundary in module.ts. |

What
Captures errors caught by
<NuxtErrorBoundary>during SSR in Nuxt 4.7+ and reports them to Sentry.Why
In Nuxt 4.7+,
<NuxtErrorBoundary>supports SSR and catches component errors to render its#errorslot with a 200 HTTP response. These errors never reached Sentry because Nitro'serrorhook only fires for unhandled server crashes and the client plugin does not receivevue:errorduring hydration. We buffer server-sidevue:errorevents and report them onapp:renderedviareportNuxtError, while ignoring intentional 3xx/4xx control-flow errors and fatal page crashes already reported by Nitro.Closes: #26795