Skip to content

Commit 9c765e0

Browse files
authored
feat(react-router): support react router v8 (#21633)
closes #21622 closes [JS-2800](https://linear.app/getsentry/issue/JS-2800) Basically only `packages/react/src/reactrouterv8.tsx` has been added to make it work. I copied over 3 tests: `-cross-usage`, `-spa` and `-framework` that covers the exports. To make it easier to check what actually changed in the apps, I made one commit with the copy and another with the changes. So it might be easier to review only the actual changes: b084c55 Docs will be updated once the PR lands
1 parent 815c1cf commit 9c765e0

82 files changed

Lines changed: 2521 additions & 23 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44

55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66

7+
- **feat(react): Add version-agnostic React Router SPA exports ([#21633](https://github.com/getsentry/sentry-javascript/pull/21633))**
8+
9+
`@sentry/react` now exports version-agnostic wrappers for React Router v6+ SPA instrumentation.
10+
The new exports replace the version-specific `V6`/`V7` variants, which are now deprecated:
11+
12+
| Deprecated | New |
13+
| ----------------------------------------------- | -------------------------------------- |
14+
| `reactRouterV6BrowserTracingIntegration` / `V7` | `reactRouterBrowserTracingIntegration` |
15+
| `withSentryReactRouterV6Routing` / `V7` | `wrapReactRouterRouting` |
16+
| `wrapCreateBrowserRouterV6` / `V7` | `wrapCreateBrowserRouter` |
17+
| `wrapCreateMemoryRouterV6` / `V7` | `wrapCreateMemoryRouter` |
18+
| `wrapUseRoutesV6` / `V7` | `wrapUseRoutes` |
19+
20+
The deprecated exports continue to work and will be removed in the next major version.
21+
722
## 10.58.0
823

924
### Important Changes

‎dev-packages/e2e-tests/test-applications/react-router-6-use-routes/src/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Sentry.init({
1818
environment: 'qa', // dynamic sampling bias to keep transactions
1919
dsn: process.env.REACT_APP_E2E_TEST_DSN,
2020
integrations: [
21-
Sentry.reactRouterV6BrowserTracingIntegration({
21+
Sentry.reactRouterBrowserTracingIntegration({
2222
useEffect: React.useEffect,
2323
useLocation,
2424
useNavigationType,
@@ -39,7 +39,7 @@ Sentry.init({
3939
tunnel: 'http://localhost:3031', // proxy server
4040
});
4141

42-
const useSentryRoutes = Sentry.wrapUseRoutesV6(useRoutes);
42+
const useSentryRoutes = Sentry.wrapUseRoutes(useRoutes);
4343

4444
function App() {
4545
return useSentryRoutes([

‎dev-packages/e2e-tests/test-applications/react-router-6-use-routes/tests/transactions.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('sends a pageload transaction with a parameterized URL', async ({ page }) =
1414
contexts: {
1515
trace: {
1616
op: 'pageload',
17-
origin: 'auto.pageload.react.reactrouter_v6',
17+
origin: 'auto.pageload.react.reactrouter',
1818
},
1919
},
2020
transaction: '/',
@@ -45,7 +45,7 @@ test('sends a navigation transaction with a parameterized URL', async ({ page })
4545
contexts: {
4646
trace: {
4747
op: 'navigation',
48-
origin: 'auto.navigation.react.reactrouter_v6',
48+
origin: 'auto.navigation.react.reactrouter',
4949
},
5050
},
5151
transaction: '/user/:id',

‎dev-packages/e2e-tests/test-applications/react-router-7-cross-usage/src/index.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Sentry.init({
2121
environment: 'qa', // dynamic sampling bias to keep transactions
2222
dsn: process.env.REACT_APP_E2E_TEST_DSN,
2323
integrations: [
24-
Sentry.reactRouterV7BrowserTracingIntegration({
24+
Sentry.reactRouterBrowserTracingIntegration({
2525
useEffect: React.useEffect,
2626
useLocation,
2727
useNavigationType,
@@ -43,9 +43,9 @@ Sentry.init({
4343
tunnel: 'http://localhost:3031',
4444
});
4545

46-
const SentryRoutes = Sentry.withSentryReactRouterV7Routing(Routes);
47-
const sentryUseRoutes = Sentry.wrapUseRoutesV7(useRoutes);
48-
const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV7(createBrowserRouter);
46+
const SentryRoutes = Sentry.wrapReactRouterRouting(Routes);
47+
const sentryUseRoutes = Sentry.wrapUseRoutes(useRoutes);
48+
const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouter(createBrowserRouter);
4949

5050
const DetailsRoutes = () =>
5151
sentryUseRoutes([

‎dev-packages/e2e-tests/test-applications/react-router-7-cross-usage/tests/transactions.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('sends a pageload transaction with a parameterized URL', async ({ page }) =
1515
contexts: {
1616
trace: {
1717
op: 'pageload',
18-
origin: 'auto.pageload.react.reactrouter_v7',
18+
origin: 'auto.pageload.react.reactrouter',
1919
},
2020
},
2121
transaction: '/projects/:projectId/views/:viewId/:detailId',
@@ -39,7 +39,7 @@ test('sends a pageload transaction with a parameterized URL - alternative route'
3939
contexts: {
4040
trace: {
4141
op: 'pageload',
42-
origin: 'auto.pageload.react.reactrouter_v7',
42+
origin: 'auto.pageload.react.reactrouter',
4343
},
4444
},
4545
transaction: '/projects/:projectId/old-views/:viewId/:detailId',
@@ -65,7 +65,7 @@ test('sends a navigation transaction with a parameterized URL', async ({ page })
6565
contexts: {
6666
trace: {
6767
op: 'pageload',
68-
origin: 'auto.pageload.react.reactrouter_v7',
68+
origin: 'auto.pageload.react.reactrouter',
6969
},
7070
},
7171
transaction: '/',
@@ -83,7 +83,7 @@ test('sends a navigation transaction with a parameterized URL', async ({ page })
8383
contexts: {
8484
trace: {
8585
op: 'navigation',
86-
origin: 'auto.navigation.react.reactrouter_v7',
86+
origin: 'auto.navigation.react.reactrouter',
8787
},
8888
},
8989
transaction: '/projects/:projectId/views/:viewId/:detailId',
@@ -109,7 +109,7 @@ test('sends a navigation transaction with a parameterized URL - alternative rout
109109
contexts: {
110110
trace: {
111111
op: 'pageload',
112-
origin: 'auto.pageload.react.reactrouter_v7',
112+
origin: 'auto.pageload.react.reactrouter',
113113
},
114114
},
115115
transaction: '/',
@@ -127,7 +127,7 @@ test('sends a navigation transaction with a parameterized URL - alternative rout
127127
contexts: {
128128
trace: {
129129
op: 'navigation',
130-
origin: 'auto.navigation.react.reactrouter_v7',
130+
origin: 'auto.navigation.react.reactrouter',
131131
},
132132
},
133133
transaction: '/projects/:projectId/old-views/:viewId/:detailId',

‎dev-packages/e2e-tests/test-applications/react-router-7-spa/src/main.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Sentry.init({
2121
environment: 'qa', // dynamic sampling bias to keep transactions
2222
dsn: import.meta.env.PUBLIC_E2E_TEST_DSN,
2323
integrations: [
24-
Sentry.reactRouterV7BrowserTracingIntegration({
24+
Sentry.reactRouterBrowserTracingIntegration({
2525
useEffect: React.useEffect,
2626
useLocation,
2727
useNavigationType,
@@ -43,7 +43,7 @@ Sentry.init({
4343
dataCollection: { userInfo: true },
4444
});
4545

46-
const SentryRoutes = Sentry.withSentryReactRouterV7Routing(Routes);
46+
const SentryRoutes = Sentry.wrapReactRouterRouting(Routes);
4747

4848
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
4949
root.render(

‎dev-packages/e2e-tests/test-applications/react-router-7-spa/tests/transactions.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('sends a pageload transaction with a parameterized URL', async ({ page }) =
1414
contexts: {
1515
trace: {
1616
op: 'pageload',
17-
origin: 'auto.pageload.react.reactrouter_v7',
17+
origin: 'auto.pageload.react.reactrouter',
1818
},
1919
},
2020
transaction: '/',
@@ -45,7 +45,7 @@ test('sends a navigation transaction with a parameterized URL', async ({ page })
4545
contexts: {
4646
trace: {
4747
op: 'navigation',
48-
origin: 'auto.navigation.react.reactrouter_v7',
48+
origin: 'auto.navigation.react.reactrouter',
4949
},
5050
},
5151
transaction: '/user/:id',
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
/test-results/
26+
/playwright-report/
27+
/playwright/.cache/
28+
29+
!*.d.ts
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "react-router-8-cross-usage",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@sentry/react": "file:../../packed/sentry-react-packed.tgz",
7+
"@types/react": "19.2.17",
8+
"@types/react-dom": "19.2.3",
9+
"express": "^4.21.2",
10+
"react": "19.2.7",
11+
"react-dom": "19.2.7",
12+
"react-router": "^8.0.0",
13+
"react-scripts": "5.0.1",
14+
"typescript": "^5.6.3"
15+
},
16+
"scripts": {
17+
"build": "react-scripts build",
18+
"start": "serve -s build",
19+
"test": "playwright test",
20+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
21+
"test:build": "pnpm install && npx playwright install && pnpm build",
22+
"test:build-ts3.8": "pnpm install && pnpm add typescript@3.8 && npx playwright install && pnpm build",
23+
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build",
24+
"test:assert": "pnpm test"
25+
},
26+
"eslintConfig": {
27+
"extends": [
28+
"react-app",
29+
"react-app/jest"
30+
]
31+
},
32+
"browserslist": {
33+
"production": [
34+
">0.2%",
35+
"not dead",
36+
"not op_mini all"
37+
],
38+
"development": [
39+
"last 1 chrome version",
40+
"last 1 firefox version",
41+
"last 1 safari version"
42+
]
43+
},
44+
"devDependencies": {
45+
"@playwright/test": "~1.56.0",
46+
"@sentry-internal/test-utils": "link:../../../test-utils",
47+
"serve": "14.0.1",
48+
"npm-run-all2": "^6.2.0"
49+
},
50+
"volta": {
51+
"extends": "../../package.json"
52+
}
53+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
2+
3+
const config = getPlaywrightConfig({
4+
startCommand: `pnpm start`,
5+
});
6+
7+
export default config;

0 commit comments

Comments
 (0)