GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(nuxt): Capture errors caught by <NuxtErrorBoundary> during SSR by pranav514 · Pull Request #26815 · getsentry/sentry-javascript

feat(nuxt): Capture errors caught by <NuxtErrorBoundary> during SSR #26815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
JPeer264 merged 6 commits into getsentry:develop from pranav514:feat/nuxt-ssr-error-boundary
Nov 25, 2026
+111 −26
Merged

feat(nuxt): Capture errors caught by <NuxtErrorBoundary> during SSR #26815

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
809c932
feat(nuxt): Capture errors caught by <NuxtErrorBoundary> during SSR
pranav514 Nov 24, 2026
3411c42
fix(nuxt): Synchronously capture and flush SSR error boundary errors
pranav514 Nov 24, 2026
5d7122a
refactor(nuxt): Address maintainer review for SSR error boundary
pranav514 Nov 24, 2026
034ba29
refactor(nuxt): Apply review suggestions for SSR error boundary E2E test
pranav514 Nov 24, 2026
ca0c7fb
refactor(nuxt): Capture errors synchronously in reportNuxtError and d…
pranav514 Nov 25, 2026
7f5b873
test(nuxt): Guard transaction assertion for Bun in SSR error boundary…
pranav514 Nov 25, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

9 changes: 9 additions & 0 deletions 9 dev-packages/e2e-tests/test-applications/nuxt-5/app/components/SSRErrorComponent.vue
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup>
Comment thread

@JPeer264 JPeer264 Nov 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note. The original issue was reported for Cloudflare, after the merge of #26756 this PR has a merge conflict, but after a rebase it would run also on Cloudflare, so we have this case covered too. No action item other than the rebase.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
if (import.meta.server) {
throw new Error('SSR Error inside NuxtErrorBoundary');
}
</script>

<template>
<div>Normal SSR Content</div>
</template>
14 changes: 14 additions & 0 deletions 14 dev-packages/e2e-tests/test-applications/nuxt-5/app/pages/ssr-error-boundary.vue
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup>
import SSRErrorComponent from '../components/SSRErrorComponent.vue';
</script>

<template>
<div>
<NuxtErrorBoundary>
<SSRErrorComponent />
<template #error="{ error }">
<p id="error-fallback">Caught SSR Error: {{ error.message }}</p>
</template>
</NuxtErrorBoundary>
</div>
</template>
28 changes: 28 additions & 0 deletions 28 dev-packages/e2e-tests/test-applications/nuxt-5/tests/errors.server.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/test-utils';
import { IMPORT_SURFACES } from './importSurfaces';
import { RUNTIME } from './runtime';
import { waitForHydration } from './waitForHydration';

IMPORT_SURFACES.forEach(({ name, apiPrefix }) => {
Expand Down Expand Up @@ -114,3 +115,30 @@ IMPORT_SURFACES.forEach(({ name, apiPrefix }) => {
});
});
});

test.describe('SSR error boundary', () => {
test('captures error thrown in NuxtErrorBoundary during SSR with 200 response', async ({ page }) => {
const errorPromise = waitForError('nuxt-5', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'SSR Error inside NuxtErrorBoundary';
});

const response = await page.goto('/ssr-error-boundary');
expect(response?.status()).toBe(200);

const error = await errorPromise;

if (RUNTIME !== 'bun') {
expect(error.transaction).toEqual('GET /ssr-error-boundary');
}
expect(error.exception.values[0]).toMatchObject({
type: 'Error',
value: 'SSR Error inside NuxtErrorBoundary',
mechanism: {
handled: false,
type: 'auto.function.nuxt.vue-error',
},
});

await expect(page.locator('#error-fallback')).toBeVisible();
});
});
4 changes: 4 additions & 0 deletions 4 packages/nuxt/src/module.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export default defineNuxtModule<ModuleOptions>({
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });
}

if ((nuxt.options.experimental as { ssrErrorBoundary?: boolean }).ssrErrorBoundary) {
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/error-boundary.server'), mode: 'server' });
}

if (clientConfigFile || serverConfigFile || cloudflareOptionsFile) {
// The bundler plugins do not get `sourcemaps.delete`.
warnOnConflictingSourceMapOptions(moduleOptions.sourcemaps);
Expand Down
14 changes: 14 additions & 0 deletions 14 packages/nuxt/src/runtime/plugins/error-boundary.server.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineNuxtPlugin } from 'nuxt/app';
import { reportNuxtError } from '../utils';
import { isIgnoredNuxtError } from '../utils/isIgnoredNuxtError';

export default defineNuxtPlugin(nuxtApp => {
Comment thread

@s1gr1d s1gr1d Nov 24, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
  });
});

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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);
Comment thread

@s1gr1d s1gr1d Nov 25, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportNuxtError wraps captureException in setTimeout. That delay is for client breadcrumbs, but now the server gets it too. On Cloudflare, the request wrapper flushes when the response ends, so the capture can come too late.

Could we remove the setTimeout from reportNuxtError and put it around the two calls in sentry.client.ts (in app:error, vue:error)? Then the server captures right away (captures in the next event loop, so that all breadcrumbs are recorded in time).

Kinda like this:

// utils.ts
captureException(error, {
  captureContext: { contexts: { nuxt: metadata } },
  mechanism: { handled: false, type: `auto.function.nuxt.${instance ? 'vue' : 'app'}-error` },
});

// in sentry.client.ts
setTimeout(() => reportNuxtError({ error }));
setTimeout(() => reportNuxtError({ error, instance, info }));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JPeer264 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
});
});
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

22 changes: 9 additions & 13 deletions 22 packages/nuxt/src/runtime/plugins/sentry.client.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
setRouteProvider,
vueIntegration,
} from '@sentry/vue';
import { defineNuxtPlugin, isNuxtError } from 'nuxt/app';
import { defineNuxtPlugin } from 'nuxt/app';
import type { GlobalObjWithIntegrationOptions } from '../../client/vueIntegration';
import { reportNuxtError } from '../utils';
import { isIgnoredNuxtError } from '../utils/isIgnoredNuxtError';

// --- Types are copied from @sentry/vue (so it does not need to be exported) ---
// The following type is an intersection of the Route type from VueRouter v2, v3, and v4.
Expand Down Expand Up @@ -38,16 +39,6 @@ interface VueRouter {

type VueRouteProviderRouter = ReturnType<Parameters<typeof _INTERNAL_createVueRouteProvider>[0]>;

// 3xx/4xx Nuxt errors are expected control flow (redirects, not-found pages), not bugs. The server skips them too.
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;
}

// Tree-shakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean;

Expand Down Expand Up @@ -106,11 +97,14 @@ export default defineNuxtPlugin({
}
});

// Capture exception in the next event loop, to make sure that all breadcrumbs are recorded in time.
nuxtApp.hook('app:error', error => {
if (isIgnoredNuxtError(error)) {
return;
}
reportNuxtError({ error });
setTimeout(() => {
reportNuxtError({ error });
});
});

// Nuxt calls `vue:error` for every error that reaches the root component, so an error thrown during setup
Expand All @@ -119,7 +113,9 @@ export default defineNuxtPlugin({
if (isIgnoredNuxtError(error)) {
return;
}
reportNuxtError({ error, instance, info });
setTimeout(() => {
reportNuxtError({ error, instance, info });
});
});
},
});
9 changes: 3 additions & 6 deletions 9 packages/nuxt/src/runtime/utils.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ export function reportNuxtError(options: {
}
}

// Capture exception in the next event loop, to make sure that all breadcrumbs are recorded in time.
setTimeout(() => {
captureException(error, {
captureContext: { contexts: { nuxt: metadata } },
mechanism: { handled: false, type: `auto.function.nuxt.${instance ? 'vue' : 'app'}-error` },
});
captureException(error, {
captureContext: { contexts: { nuxt: metadata } },
mechanism: { handled: false, type: `auto.function.nuxt.${instance ? 'vue' : 'app'}-error` },
});
}
11 changes: 11 additions & 0 deletions 11 packages/nuxt/src/runtime/utils/isIgnoredNuxtError.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isNuxtError } from 'nuxt/app';

// 3xx/4xx Nuxt errors are expected control flow (redirects, not-found pages), not bugs. The server skips them too.
export 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;
}
20 changes: 19 additions & 1 deletion 20 packages/nuxt/test/runtime/plugins/client.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NAVIGATION, PAGELOAD } from '@sentry/conventions/op';
import type { Client, StartSpanOptions } from '@sentry/core';
import type { isNuxtError as nuxtIsNuxtError, NuxtApp } from 'nuxt/app';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import clientPlugin from '../../../src/runtime/plugins/sentry.client';
import * as utils from '../../../src/runtime/utils';

Expand Down Expand Up @@ -245,6 +245,14 @@ describe('Sentry Nuxt client plugin', () => {
});

describe.each(['app:error', 'vue:error'] as const)('%s hook — status-code filtering', hookName => {
beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => {
vi.useRealTimers();
});

const fireHook = (nuxtApp: { hook: ReturnType<typeof vi.fn> }, error: unknown) => {
const cb = nuxtApp.hook.mock.calls.find(c => c[0] === hookName)?.[1] as (
e: unknown,
Expand All @@ -255,6 +263,7 @@ describe('Sentry Nuxt client plugin', () => {
// plugin passes the extra args through for vue:error, so include them
// uniformly here and rely on expect.objectContaining({ error }) below.
cb(error, undefined, 'setup');
vi.runAllTimers();
};

// The plugin's skip guard reads `error.status || error.statusCode`, so both
Expand Down Expand Up @@ -310,6 +319,14 @@ describe('Sentry Nuxt client plugin', () => {
});

describe('vue:error hook — component instance passthrough', () => {
beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => {
vi.useRealTimers();
});

it('forwards the error, component instance and info to reportNuxtError', async () => {
const reportSpy = vi.spyOn(utils, 'reportNuxtError').mockImplementation(() => {});
getClient.mockReturnValue(makeClient());
Expand All @@ -325,6 +342,7 @@ describe('Sentry Nuxt client plugin', () => {
const err = new Error('vue boom');
const instance = { $props: { foo: 1 } };
vueErrorCb(err, instance, 'render');
vi.runAllTimers();

expect(reportSpy).toHaveBeenCalledWith({ error: err, instance, info: 'render' });
});
Expand Down
6 changes: 0 additions & 6 deletions 6 packages/nuxt/test/runtime/utils.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ describe('reportNuxtError', () => {
};

beforeEach(() => {
// Using fake timers as setTimeout is used in `reportNuxtError`
vi.useFakeTimers();
vi.clearAllMocks();
(getClient as Mock).mockReturnValue(mockClient);
});
Expand All @@ -127,7 +125,6 @@ describe('reportNuxtError', () => {

test('captures exception with correct error and metadata', () => {
reportNuxtError({ error: mockError });
vi.runAllTimers();

expect(captureException).toHaveBeenCalledWith(mockError, {
captureContext: { contexts: { nuxt: { info: undefined } } },
Expand All @@ -137,7 +134,6 @@ describe('reportNuxtError', () => {

test('includes instance props if attachProps is not explicitly defined', () => {
reportNuxtError({ error: mockError, instance: mockInstance });
vi.runAllTimers();

expect(captureException).toHaveBeenCalledWith(mockError, {
captureContext: { contexts: { nuxt: { info: undefined, propsData: { foo: 'bar' } } } },
Expand All @@ -149,7 +145,6 @@ describe('reportNuxtError', () => {
mockClient.getOptions.mockReturnValue({ attachProps: false });

reportNuxtError({ error: mockError, instance: mockInstance });
vi.runAllTimers();

expect(captureException).toHaveBeenCalledWith(mockError, {
captureContext: { contexts: { nuxt: { info: undefined } } },
Expand All @@ -159,7 +154,6 @@ describe('reportNuxtError', () => {

test('handles absence of instance correctly', () => {
reportNuxtError({ error: mockError, info: 'Some info' });
vi.runAllTimers();

expect(captureException).toHaveBeenCalledWith(mockError, {
captureContext: { contexts: { nuxt: { info: 'Some info' } } },
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.