Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { captureException } from '@sentry/nextjs';
import type { Metadata } from 'next';

/**
* Calling captureException synchronously inside generateMetadata
* during `next build` prerender (cacheComponents). uuid4 -> crypto.randomUUID() runs
*/
export const generateMetadata = (): Metadata => {
captureException(new Error('diagnostic: data missing for this page'));
return { title: 'capture-metadata' };
};

export default function Page() {
return <h1>capture-metadata</h1>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ test('Should generate metadata async', async ({ page }) => {
await expect(page.locator('#todos-fetched')).toHaveText('Todos fetched: 5');
await expect(page).toHaveTitle('Product: 1');
});

test('Should prerender a page that captures an exception in generateMetadata', async ({ page }) => {
await page.goto('/capture-metadata');

await expect(page).toHaveTitle('capture-metadata');
await expect(page.locator('h1')).toHaveText('capture-metadata');
});
3 changes: 3 additions & 0 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
_sentryRelease?: string;
};

// Call at module level so `next build` prerender workers still register the runner without `init`
prepareSafeIdGeneratorContext();

/**
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
* so they should simply be a passthrough.
Expand Down
Loading