Skip to content

Commit de93cb8

Browse files
chargomeandreiborzas1gr1d
authored
docs(react-router): Update guide for @sentry/react-router (#12867)
--------- Co-authored-by: Andrei <168741329+andreiborza@users.noreply.github.com> Co-authored-by: Sigrid Huemer <32902192+s1gr1d@users.noreply.github.com>
1 parent ba3bdbb commit de93cb8

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

docs/platforms/javascript/guides/react-router/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: React Router v7 (framework mode)
1+
title: React Router Framework
22
description: React Router v7 is a framework for building full-stack web apps and websites. Learn how to set it up with Sentry.
33
sdk: sentry.javascript.react-router
44
categories:

platform-includes/getting-started-config/javascript.react-router.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ npx react-router reveal
1111
Initialize the Sentry React SDK in your `entry.client.tsx` file:
1212

1313
```tsx {filename: entry.client.tsx} {"onboardingOptions": {"performance": "9, 12-16", "session-replay": "10, 17-21"}}
14-
import * as Sentry from "@sentry/react";
14+
import * as Sentry from "@sentry/react-router";
1515
import { startTransition, StrictMode } from "react";
1616
import { hydrateRoot } from "react-dom/client";
1717
import { HydratedRouter } from "react-router/dom";
@@ -47,7 +47,7 @@ startTransition(() => {
4747
Now, update your `app/root.tsx` file to report any unhandled errors from your error boundary:
4848

4949
```tsx {diff} {filename: app/root.tsx}
50-
import * as Sentry from "@sentry/react";
50+
import * as Sentry from "@sentry/react-router";
5151

5252
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
5353
let message = "Oops!";
@@ -89,7 +89,7 @@ export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
8989
Create an `instrument.server.mjs` file in the root of your app:
9090

9191
```js {filename: instrument.server.mjs} {"onboardingOptions": {"performance": "7", "profiling": "2, 6, 8"}}
92-
import * as Sentry from "@sentry/node";
92+
import * as Sentry from "@sentry/react-router";
9393
import { nodeProfilingIntegration } from '@sentry/profiling-node';
9494

9595
Sentry.init({
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
<OnboardingOptionButtons
2-
options={["error-monitoring", "performance", "profiling", "session-replay"]}
2+
options={[
3+
"error-monitoring",
4+
"performance",
5+
"session-replay",
6+
{
7+
id: 'profiling',
8+
checked: false
9+
}
10+
]}
311
/>
412

513
<OnboardingOption optionId="profiling">
614

715
```bash {tabTitle:npm}
8-
npm install @sentry/react @sentry/node @sentry/profiling-node
16+
npm install @sentry/react-router @sentry/profiling-node
917
```
1018

1119
```bash {tabTitle:yarn}
12-
yarn add @sentry/react @sentry/node @sentry/profiling-node
20+
yarn add @sentry/react-router @sentry/profiling-node
1321
```
1422

1523
```bash {tabTitle:pnpm}
16-
pnpm add @sentry/react @sentry/node @sentry/profiling-node
24+
pnpm add @sentry/react-router @sentry/profiling-node
1725
```
1826

1927
</OnboardingOption>
2028

2129
<OnboardingOption optionId="profiling" hideForThisOption>
2230
```bash {tabTitle:npm}
23-
npm install @sentry/react @sentry/node
31+
npm install @sentry/react-router
2432
```
2533

2634
```bash {tabTitle:yarn}
27-
yarn add @sentry/react @sentry/node
35+
yarn add @sentry/react-router
2836
```
2937

3038
```bash {tabTitle:pnpm}
31-
pnpm add @sentry/react @sentry/node
39+
pnpm add @sentry/react-router
3240
```
3341
</OnboardingOption>
3442

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Alert title='Looking for library mode?' level='warning'>
1+
<Alert title='SDK Limitations' level='warning'>
22

3-
If you are using React Router in library mode, you can follow the instructions in the [React guide here](/platforms/javascript/guides/react/features/react-router/v7).
3+
This SDK is considered **experimental and in an alpha state**. It may experience breaking changes. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/) if you have any feedback or concerns.
44

55
</Alert>
66

7-
<Alert title='SDK Limitations' level='warning'>
7+
<Alert title='Looking for library mode?' level='info'>
88

9-
We do not yet have a dedicated SDK for React Router in framework mode.
10-
This guide demonstrates how to setup error monitoring and basic performance tracing using the `@sentry/react` and `@sentry/node` packages instead.
9+
If you are using React Router in library mode, you can follow the instructions in the [React guide here](/platforms/javascript/guides/react/features/react-router/v7).
1110

1211
</Alert>
12+
Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1-
## Add Readable Stack Traces to Errors
1+
## Source Maps Upload
22

3-
By default, React Router will minify your JavaScript and CSS files in production. This makes it difficult to debug errors. To make debugging easier, you can generate source maps and upload them to Sentry.
3+
Update `vite.config.ts` to include the `sentryReactRouter` plugin. Also add your `SentryReactRouterBuildOptions` config options to the Vite config (this is required for uploading source maps at the end of the build):
44

5-
We recommend using [Sentry's Vite plugin](/platforms/javascript/sourcemaps/uploading/vite/) to upload sourcemaps.
5+
<OrgAuthTokenNote />
66

7-
Please refer to the <PlatformLink to="/sourcemaps">Source Maps Documentation</PlatformLink>, for more information.
7+
```typescript {filename: vite.config.ts}
8+
import { reactRouter } from '@react-router/dev/vite';
9+
import { sentryReactRouter, type SentryReactRouterBuildOptions } from '@sentry/react-router';
10+
import { defineConfig } from 'vite';
811

9-
For more advanced configuration, you can use [`sentry-cli`](https://github.com/getsentry/sentry-cli) directly to upload source maps.
12+
const sentryConfig: SentryReactRouterBuildOptions = {
13+
org: "___ORG_SLUG___",
14+
project: "___PROJECT_SLUG___",
15+
16+
// An auth token is required for uploading source maps.
17+
authToken: "___ORG_AUTH_TOKEN___"
18+
// ...
19+
};
20+
21+
export default defineConfig(config => {
22+
return {
23+
plugins: [reactRouter(), sentryReactRouter(sentryConfig, config)],
24+
sentryConfig,
25+
};
26+
});
27+
```
28+
29+
Include the `sentryOnBuildEnd` hook in `react-router.config.ts`:
30+
31+
```typescript {filename: react-router.config.ts} {9}
32+
import type { Config } from '@react-router/dev/config';
33+
import { sentryOnBuildEnd } from '@sentry/react-router';
34+
35+
export default {
36+
ssr: true,
37+
buildEnd: ({ viteConfig, reactRouterConfig, buildManifest }) => {
38+
// ...
39+
// Call this at the end of the hook
40+
sentryOnBuildEnd({ viteConfig, reactRouterConfig, buildManifest });
41+
},
42+
} satisfies Config;
43+
```

0 commit comments

Comments
 (0)