✨ NextJS Add addNextJSError component#4308
Conversation
- Rename test app from `nextjs-app-router` to `nextjs` to reflect it now contains both App Router and Pages Router code - Add Pages Router error-test page using `NextjsErrorBoundary` with trigger/reset UI - Add `pages/_error.tsx` custom error page calling `addNextjsError` via `useEffect` - Add `pages-router/throw-error` page (SSR throw via `getServerSideProps`) to trigger `_error.tsx` - Add `app/global-error-test/page.tsx` that throws when `?throw=true` to trigger `global-error.tsx` - Add navigation links in Pages Router home and App Router home to reach new test pages - Restructure `nextjsPlugin.scenario.ts` into "router" and "errors" describe blocks, loop over `routerConfigs` - Export `isContinuousIntegration` from `test/e2e/lib/framework/index.ts` - Fix `eslint.config.mjs` path reference (`nextjs-app-router` → `nextjs`)
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 586c754 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
|
@codex pls review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 673952b723
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1f87375 to
f7678cb
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7678cbe8b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| Next.js uses [error boundaries][2] (`error.tsx` files) to catch uncaught exceptions in each route segment. Use `addNextjsError` inside these boundaries to report errors to Datadog RUM. | ||
|
|
||
| For **Server Component** errors, Next.js sends a generic message to the client and attaches `error.digest` — a hash that links the client-side error to your server-side logs. For **Client Component** errors, `error.message` is the original message and `digest` is absent. |
There was a problem hiding this comment.
| For **Server Component** errors, Next.js sends a generic message to the client and attaches `error.digest` — a hash that links the client-side error to your server-side logs. For **Client Component** errors, `error.message` is the original message and `digest` is absent. | |
| For **Server Component** errors, Next.js sends a generic message to the client and attaches `error.digest` — a hash that links the client-side error to your server-side logs. For **Client Component** errors, `error.message` is the original message and `error.digest` is absent. |
Is the digest listed here meant to be the error.digest listed earlier?
If yes, I recommend writing it out fully to avoid any confusion.
If no, feel free to dismiss this comment. But I'd recommend clarifying where this digest originates/is used, since we are saying it is absent in this circumstance.
Let me know if you have any questions!
iadjivon
left a comment
There was a problem hiding this comment.
Hi there,
Thanks for sharing this PR with the Doc team!
I've approved this with a small comment.
Let us know if you have any questions!
Motivation
Discussed in this RFC specifically here
Changes
(AI written)
Adds
addNextjsError(error, context?)andNextjsErrorBoundaryto@datadog/browser-rum-nextjs— the integration points for reporting errors from Next.js error boundaries to Datadog RUM.addNextjsError(error, context?)framework: 'nextjs'contextnextjs.digestcontext when the error carries adigestproperty (server component errors — the hash links client-side errors to server-side logs)onRumStartdeferred callback so calls before SDK init are buffered and replayedframework,nextjs.digest) are always applied last in the context merge, so user-provided context cannot overwrite themNextjsErrorBoundaryaddNextjsErrorfor Pages Router client-side error catchingfallbackrender prop (NextjsErrorBoundaryFallback) and an optionalonErrorcallbackaddNextjsErrorincomponentDidCatchTest app & E2E
nextjs-app-router→nextjs(now covers both App Router and Pages Router)pages-router/index, user, guides, error boundary testNextjsErrorBoundarycatch + reset (pages router)Both APIs exported from
@datadog/browser-rum-nextjsmain entry.Test instructions
(AI written)
Navigating into
test/apps/nextjsyou can doyarn devoryarn start(for production) and use the developer extension to test the events.Checklist