fix: capture React root errors in Sentry

This commit is contained in:
Codex Review Integration 2026-09-03 15:53:50 -03:00
parent a24002bc24
commit dc313dc50a
2 changed files with 11 additions and 2 deletions

View file

@ -18,7 +18,10 @@ Use the pinned `@sentry/react` 10.73.0 SDK. Initialize it before the application
router is created, and wrap `createBrowserRouter` with Sentry's current React
Router compatibility API. Configure the browser tracing integration with a 100%
transaction sample rate, and propagate trace headers only to the SPA origin and
the configured `VITE_API_URL` base.
the configured `VITE_API_URL` base. Pass `Sentry.reactErrorHandler()` as the
`onCaughtError`, `onUncaughtError`, and `onRecoverableError` callbacks of
`ReactDOM.createRoot`, so React 19's root error hooks capture caught, uncaught,
and recoverable component errors as Sentry events.
The DSN comes from `VITE_SENTRY_DSN`. It is intentionally treated as public
browser configuration because every `VITE_` value is embedded in the built

View file

@ -1,3 +1,5 @@
import * as Sentry from "@sentry/react";
import "@/observability/sentry";
import React from "react";
@ -12,7 +14,11 @@ if (!rootElement) {
throw new Error("Root element #root not found");
}
ReactDOM.createRoot(rootElement).render(
ReactDOM.createRoot(rootElement, {
onCaughtError: Sentry.reactErrorHandler(),
onRecoverableError: Sentry.reactErrorHandler(),
onUncaughtError: Sentry.reactErrorHandler(),
}).render(
<React.StrictMode>
<AppProviders>
<AppRoot />