-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Document lazyRouteManifest option for React Router v6 and v7
#16397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
fc58840
3d9bb0e
657d0ad
99343d0
3ec2939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -151,6 +151,55 @@ ReactDOM.render( | |||||
|
|
||||||
| Now, Sentry should generate `pageload`/`navigation` transactions with parameterized transaction names (for example, `/teams/:teamid/user/:userid`), where applicable. This is only needed at the top level of your app, unlike React Router v4/v5, which required wrapping every `<Route />` you wanted parametrized. | ||||||
|
|
||||||
| ## Static Route Manifest | ||||||
|
|
||||||
| _Available in `@sentry/react` version `10.39.0` and above._ | ||||||
|
|
||||||
| When using [`patchRoutesOnNavigation`](https://reactrouter.com/6.30.3/routers/create-browser-router#optspatchroutesonnavigation) to dynamically load route definitions, the full route hierarchy isn't available to Sentry until each route is navigated to. This can cause transactions to receive incomplete or wildcard names (for example, `/users/*` instead of `/users/:userId`). | ||||||
|
|
||||||
| To ensure accurate transaction names, you can provide a static list of route patterns via the `lazyRouteManifest` option. When provided, Sentry uses this manifest as the primary source for determining transaction names without needing to wait for route modules to load. | ||||||
|
|
||||||
| <Alert level="warning" title="Important"> | ||||||
| `lazyRouteManifest` requires `enableAsyncRouteHandlers: true` to be set on the integration. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this alert is needed because we clearly state the dependency below + it's in the code example |
||||||
|
|
||||||
| </Alert> | ||||||
|
|
||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add the explanation here:
Suggested change
|
||||||
| ```javascript {20-27} | ||||||
| import React from "react"; | ||||||
| import { | ||||||
| createRoutesFromChildren, | ||||||
| matchRoutes, | ||||||
| useLocation, | ||||||
| useNavigationType, | ||||||
| } from "react-router-dom"; | ||||||
|
|
||||||
| import * as Sentry from "@sentry/react"; | ||||||
|
|
||||||
| Sentry.init({ | ||||||
| dsn: "___PUBLIC_DSN___", | ||||||
| integrations: [ | ||||||
| Sentry.reactRouterV6BrowserTracingIntegration({ | ||||||
| useEffect: React.useEffect, | ||||||
| useLocation, | ||||||
| useNavigationType, | ||||||
| createRoutesFromChildren, | ||||||
| matchRoutes, | ||||||
| enableAsyncRouteHandlers: true, | ||||||
| lazyRouteManifest: [ | ||||||
| "/users", | ||||||
| "/users/:userId", | ||||||
| "/users/:userId/settings", | ||||||
| "/dashboard", | ||||||
| "/dashboard/analytics", | ||||||
| ], | ||||||
| }), | ||||||
| ], | ||||||
| tracesSampleRate: 1.0, | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| Add the `enableAsyncRouteHandlers` and `lazyRouteManifest` options to your `reactRouterV6BrowserTracingIntegration` configuration. Keep the `lazyRouteManifest` array in sync with your route definitions. Any route that doesn't match a pattern in the manifest will fall back to the default behavior, which may result in incomplete transaction names until the route is visited. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's move the first sentence above the code snippet.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: in the SDK PR you wrote:
Do you think this is clear to our users, or should we also add this to the docs (maybe in a note alert)? |
||||||
|
|
||||||
| ## Set Up a Custom Error Boundary | ||||||
|
|
||||||
| When using `react-router`, errors thrown inside route elements will only be re-thrown in **development mode** while using [`strict mode`](https://react.dev/reference/react/StrictMode).\ | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,8 @@ sidebar_order: 10 | |
| --- | ||
|
|
||
| <Alert level="info" title="Looking for framework mode?"> | ||
| React Router v7 (framework mode) is currently in Beta, check out | ||
| the docs [here](/platforms/javascript/guides/react-router/). | ||
| React Router v7 (framework mode) is currently in Beta, check out the docs | ||
| [here](/platforms/javascript/guides/react-router/). | ||
| </Alert> | ||
| Apply the following setup steps based on your routing method and create a | ||
| [custom error boundary](#set-up-a-custom-error-boundary) to make sure Sentry | ||
|
|
@@ -155,6 +155,55 @@ ReactDOM.render( | |
|
|
||
| Now, Sentry should generate `pageload`/`navigation` transactions with parameterized transaction names (for example, `/teams/:teamid/user/:userid`), where applicable. This is only needed at the top level of your app, unlike React Router v4/v5, which required wrapping every `<Route />` you wanted parametrized. | ||
|
|
||
| ## Static Route Manifest | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it make sense to create an include for this?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would need to exclude the code snippet, I think it can stay like this for now. |
||
|
|
||
| _Available in `@sentry/react` version `10.39.0` and above._ | ||
|
|
||
| When using [`patchRoutesOnNavigation`](https://reactrouter.com/api/data-routers/createBrowserRouter#optspatchroutesonnavigation) to dynamically load route definitions, the full route hierarchy isn't available to Sentry until each route is navigated to. This can cause transactions to receive incomplete or wildcard names (for example, `/users/*` instead of `/users/:userId`). | ||
|
|
||
| To ensure accurate transaction names, you can provide a static list of route patterns via the `lazyRouteManifest` option. When provided, Sentry uses this manifest as the primary source for determining transaction names without needing to wait for route modules to load. | ||
|
|
||
| <Alert level="warning" title="Important"> | ||
| `lazyRouteManifest` requires `enableAsyncRouteHandlers: true` to be set on the integration. | ||
|
|
||
| </Alert> | ||
|
|
||
| ```javascript {20-27} | ||
| import React from "react"; | ||
| import { | ||
| createRoutesFromChildren, | ||
| matchRoutes, | ||
| useLocation, | ||
| useNavigationType, | ||
| } from "react-router"; | ||
|
|
||
| import * as Sentry from "@sentry/react"; | ||
|
|
||
| Sentry.init({ | ||
| dsn: "___PUBLIC_DSN___", | ||
| integrations: [ | ||
| Sentry.reactRouterV7BrowserTracingIntegration({ | ||
| useEffect: React.useEffect, | ||
| useLocation, | ||
| useNavigationType, | ||
| createRoutesFromChildren, | ||
| matchRoutes, | ||
| enableAsyncRouteHandlers: true, | ||
| lazyRouteManifest: [ | ||
| "/users", | ||
| "/users/:userId", | ||
| "/users/:userId/settings", | ||
| "/dashboard", | ||
| "/dashboard/analytics", | ||
| ], | ||
| }), | ||
| ], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
| ``` | ||
|
|
||
| Add the `enableAsyncRouteHandlers` and `lazyRouteManifest` options to your `reactRouterV7BrowserTracingIntegration` configuration. Keep the `lazyRouteManifest` array in sync with your route definitions. Any route that doesn't match a pattern in the manifest will fall back to the default behavior, which may result in incomplete transaction names until the route is visited. | ||
|
|
||
| ## Set Up a Custom Error Boundary | ||
|
|
||
| When using `react-router`, errors thrown inside route elements will only be re-thrown in **development mode** while using [`strict mode`](https://react.dev/reference/react/StrictMode).\ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a component for this!