Skip to content

Commit 0093e5b

Browse files
onurtemizkanLms24AbhiPrasad
authored andcommitted
Document Remix v2 support. (#7320)
Co-authored-by: Lukas Stracke <[email protected]> Co-authored-by: Abhijeet Prasad <[email protected]>
1 parent 66b6fc3 commit 0093e5b

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/platform-includes/getting-started-config/javascript.remix.mdx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const createSentryRequestHandler =
9595
app.all("*", createSentryRequestHandler(/* ... */));
9696
```
9797

98-
Also, wrap your Remix root with `withSentry` to catch React component errors and to get parameterized router transactions.
98+
Also, wrap your Remix root with `withSentry` to catch React component errors (Remix v1) and routing transactions. If you use the Remix `v2_errorBoundary` future flag, you need to configure a [v2 ErrorBoundary](#v2-errorboundary) in addition.
9999

100100
```typescript {filename: root.tsx}
101101
import {
@@ -131,7 +131,7 @@ export default withSentry(App);
131131

132132
You can disable or configure `ErrorBoundary` using a second parameter to `withSentry`.
133133

134-
```ts
134+
```typescript
135135
withSentry(App, {
136136
wrapWithErrorBoundary: false,
137137
});
@@ -145,6 +145,46 @@ withSentry(App, {
145145
});
146146
```
147147

148+
## Remix v2 features
149+
150+
_Available from SDK version 7.59.0_
151+
152+
[Remix v2](https://remix.run/docs/en/main/pages/v2) will introduce new features that require additional configuration to work with Sentry. These features are also available from version [1.17.0](https://github.com/remix-run/remix/releases/tag/remix%401.17.0) with [future flags](https://remix.run/docs/en/main/pages/api-development-strategy#current-future-flags).
153+
154+
### v2 ErrorBoundary
155+
156+
To capture errors from [v2 ErrorBoundary](https://remix.run/docs/en/main/route/error-boundary-v2), you should define your own `ErrorBoundary` in `root.tsx` and use `Sentry.captureRemixErrorBoundaryError` inside of it. You can also create route-specific error capturing behaviour by defining `ErrorBoundary` in your route components. The `ErrorBoundary` you define in `root.tsx` will be used as a fallback for all routes.
157+
158+
```typescript {filename: root.tsx}
159+
import { captureRemixErrorBoundaryError } from "@sentry/remix";
160+
161+
export const ErrorBoundary: V2_ErrorBoundaryComponent = () => {
162+
const error = useRouteError();
163+
164+
captureRemixErrorBoundaryError(error);
165+
166+
return <div> ... </div>;
167+
};
168+
```
169+
170+
## v2 Server-side Errors
171+
172+
When using `v2_errorBoundary` future flag, Sentry can't capture your server-side errors automatically. Instead, define a [`handleError`](https://remix.run/docs/en/main/file-conventions/entry.server#handleerror) function in your server entry point. Then, you should use `Sentry.captureRemixServerError` to capture errors in your server-side code.
173+
174+
```typescript {filename: entry.server.tsx}
175+
export function handleError(
176+
error: unknown,
177+
{ request }: DataFunctionArgs
178+
): void {
179+
if (error instanceof Error) {
180+
Sentry.captureRemixServerException(error, "remix.server", request);
181+
} else {
182+
// Optionally capture non-Error objects
183+
Sentry.captureException(error);
184+
}
185+
}
186+
```
187+
148188
Once you've done this set up, the SDK will automatically capture unhandled errors and promise rejections, and monitor performance in the client. You can also [manually capture errors](/platforms/javascript/guides/remix/usage).
149189

150190
<Note>

0 commit comments

Comments
 (0)