Skip to content

Commit fb54490

Browse files
authored
docs(js): Update rr framework docs for client side errors (#17276)
documents getsentry/sentry-javascript#20120
1 parent b7a097d commit fb54490

File tree

2 files changed

+5
-43
lines changed

2 files changed

+5
-43
lines changed

docs/platforms/javascript/guides/cloudflare/frameworks/hydrogen-react-router.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ startTransition(() => {
115115
hydrateRoot(
116116
document,
117117
<StrictMode>
118-
<HydratedRouter />
118+
<HydratedRouter onError={Sentry.sentryOnError} />
119119
</StrictMode>
120120
);
121121
});
122122
```
123123

124+
The `sentryOnError` handler integrates with React Router's [`onError` hook](https://reactrouter.com/how-to/error-reporting) to automatically capture and report client-side errors to Sentry.
125+
124126
### Configure Server-side Sentry
125127

126128
First, create an `instrument.server.mjs` file to initialize Sentry on the server:

docs/platforms/javascript/guides/react-router/manual-setup.mdx

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -151,53 +151,13 @@ startTransition(() => {
151151
hydrateRoot(
152152
document,
153153
<StrictMode>
154-
<HydratedRouter />
154+
<HydratedRouter onError={Sentry.sentryOnError} />
155155
</StrictMode>
156156
);
157157
});
158158
```
159159

160-
#### Report Errors from Error Boundaries
161-
162-
Update your `app/root.tsx` file to capture unhandled errors in your error boundary:
163-
164-
```tsx {diff} {filename: app/root.tsx}
165-
+import * as Sentry from "@sentry/react-router";
166-
167-
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
168-
let message = "Oops!";
169-
let details = "An unexpected error occurred.";
170-
let stack: string | undefined;
171-
172-
if (isRouteErrorResponse(error)) {
173-
message = error.status === 404 ? "404" : "Error";
174-
details =
175-
error.status === 404
176-
? "The requested page could not be found."
177-
: error.statusText || details;
178-
} else if (error && error instanceof Error) {
179-
// you only want to capture non 404-errors that reach the boundary
180-
+ Sentry.captureException(error);
181-
if (import.meta.env.DEV) {
182-
details = error.message;
183-
stack = error.stack;
184-
}
185-
}
186-
187-
return (
188-
<main>
189-
<h1>{message}</h1>
190-
<p>{details}</p>
191-
{stack && (
192-
<pre>
193-
<code>{stack}</code>
194-
</pre>
195-
)}
196-
</main>
197-
);
198-
}
199-
// ...
200-
```
160+
The `sentryOnError` handler integrates with React Router's [`onError` hook](https://reactrouter.com/how-to/error-reporting) to automatically capture and report client-side errors to Sentry.
201161

202162
### Configure Server-side Sentry
203163

0 commit comments

Comments
 (0)