-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(react): React Router v7 support (library) #14513
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ecf85a
create utils file
chargome f36d755
define v6 compatible functions
chargome 1eff1c0
add v7 e2e test
chargome f5a79cd
organize imports
chargome 41d3d67
Merge branch 'develop' into cg/react-router-v7
chargome 90e98d3
add deprecation warnings for rr
chargome 38d91d3
update variant label for tests
chargome 8117c80
ignore deprecation warnings for v6 tests
chargome 099112b
update test build command
chargome cbf0a67
Merge branch 'develop' into cg/react-router-v7
chargome 1941735
organize imports
chargome d6647d8
import types from core
chargome 7e86ffb
Merge branch 'develop' into cg/react-router-v7
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
dev-packages/e2e-tests/test-applications/react-router-7-spa/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ | ||
|
||
!*.d.ts |
2 changes: 2 additions & 0 deletions
2
dev-packages/e2e-tests/test-applications/react-router-7-spa/.npmrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/react-router-7-spa/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
60 changes: 60 additions & 0 deletions
60
dev-packages/e2e-tests/test-applications/react-router-7-spa/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "react-router-7-spa", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@sentry/react": "latest || *", | ||
"@types/react": "18.3.1", | ||
"@types/react-dom": "18.3.1", | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1", | ||
"react-router": "^7.0.1" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.1", | ||
"@sentry-internal/test-utils": "link:../../../test-utils", | ||
"vite": "^6.0.1", | ||
"@vitejs/plugin-react": "^4.3.4", | ||
"typescript": "4.9.5" | ||
}, | ||
"scripts": { | ||
"build": "tsc -b && vite build", | ||
"dev": "vite", | ||
"preview": "vite preview", | ||
"test": "playwright test", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test:build": "pnpm install && npx playwright install && pnpm build", | ||
"test:build-ts3.8": "pnpm install && pnpm add [email protected] && npx playwright install && pnpm build", | ||
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build", | ||
"test:assert": "pnpm test" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
}, | ||
"sentryTest": { | ||
"variants": [ | ||
{ | ||
"build-command": "test:build-ts3.8", | ||
"label": "react-router-6 (TS 3.8)" | ||
} | ||
] | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/react-router-7-spa/playwright.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
||
const config = getPlaywrightConfig({ | ||
startCommand: `pnpm preview --port 3030`, | ||
port: 3030, | ||
}); | ||
|
||
export default config; |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/react-router-7-spa/src/globals.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface Window { | ||
recordedTransactions?: string[]; | ||
capturedExceptionId?: string; | ||
sentryReplayId?: string; | ||
} |
55 changes: 55 additions & 0 deletions
55
dev-packages/e2e-tests/test-applications/react-router-7-spa/src/main.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as Sentry from '@sentry/react'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { | ||
BrowserRouter, | ||
Route, | ||
Routes, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
useLocation, | ||
useNavigationType, | ||
} from 'react-router'; | ||
import Index from './pages/Index'; | ||
import SSE from './pages/SSE'; | ||
import User from './pages/User'; | ||
|
||
const replay = Sentry.replayIntegration(); | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: import.meta.env.PUBLIC_E2E_TEST_DSN, | ||
integrations: [ | ||
Sentry.reactRouterV7BrowserTracingIntegration({ | ||
useEffect: React.useEffect, | ||
useLocation, | ||
useNavigationType, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
trackFetchStreamPerformance: true, | ||
}), | ||
replay, | ||
], | ||
// We recommend adjusting this value in production, or using tracesSampler | ||
// for finer control | ||
tracesSampleRate: 1.0, | ||
release: 'e2e-test', | ||
|
||
// Always capture replays, so we can test this properly | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
tunnel: 'http://localhost:3031', | ||
}); | ||
|
||
const SentryRoutes = Sentry.withSentryReactRouterV7Routing(Routes); | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); | ||
root.render( | ||
<BrowserRouter> | ||
<SentryRoutes> | ||
<Route path="/" element={<Index />} /> | ||
<Route path="/user/:id" element={<User />} /> | ||
<Route path="/sse" element={<SSE />} /> | ||
</SentryRoutes> | ||
</BrowserRouter>, | ||
); |
23 changes: 23 additions & 0 deletions
23
dev-packages/e2e-tests/test-applications/react-router-7-spa/src/pages/Index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX | ||
import * as React from 'react'; | ||
import { Link } from 'react-router'; | ||
|
||
const Index = () => { | ||
return ( | ||
<> | ||
<input | ||
type="button" | ||
value="Capture Exception" | ||
id="exception-button" | ||
onClick={() => { | ||
throw new Error('I am an error!'); | ||
}} | ||
/> | ||
<Link to="/user/5" id="navigation"> | ||
navigate | ||
</Link> | ||
</> | ||
); | ||
}; | ||
|
||
export default Index; |
59 changes: 59 additions & 0 deletions
59
dev-packages/e2e-tests/test-applications/react-router-7-spa/src/pages/SSE.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as Sentry from '@sentry/react'; | ||
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX | ||
import * as React from 'react'; | ||
|
||
const fetchSSE = async ({ timeout, abort = false }: { timeout: boolean; abort?: boolean }) => { | ||
Sentry.startSpanManual({ name: 'sse stream using fetch' }, async span => { | ||
const controller = new AbortController(); | ||
|
||
const res = await Sentry.startSpan({ name: 'sse fetch call' }, async () => { | ||
const endpoint = `http://localhost:8080/${timeout ? 'sse-timeout' : 'sse'}`; | ||
|
||
const signal = controller.signal; | ||
return await fetch(endpoint, { signal }); | ||
}); | ||
|
||
const stream = res.body; | ||
const reader = stream?.getReader(); | ||
|
||
const readChunk = async () => { | ||
if (abort) { | ||
controller.abort(); | ||
} | ||
const readRes = await reader?.read(); | ||
if (readRes?.done) { | ||
return; | ||
} | ||
|
||
new TextDecoder().decode(readRes?.value); | ||
|
||
await readChunk(); | ||
}; | ||
|
||
try { | ||
await readChunk(); | ||
} catch (error) { | ||
console.error('Could not fetch sse', error); | ||
} | ||
|
||
span.end(); | ||
}); | ||
}; | ||
|
||
const SSE = () => { | ||
return ( | ||
<> | ||
<button id="fetch-button" onClick={() => fetchSSE({ timeout: false })}> | ||
Fetch SSE | ||
</button> | ||
<button id="fetch-timeout-button" onClick={() => fetchSSE({ timeout: true })}> | ||
Fetch timeout SSE | ||
</button> | ||
<button id="fetch-sse-abort" onClick={() => fetchSSE({ timeout: false, abort: true })}> | ||
Fetch SSE with error | ||
</button> | ||
</> | ||
); | ||
}; | ||
|
||
export default SSE; |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/react-router-7-spa/src/pages/User.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX | ||
import * as React from 'react'; | ||
|
||
const User = () => { | ||
return <p>I am a blank page :)</p>; | ||
}; | ||
|
||
export default User; |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/react-router-7-spa/start-event-proxy.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
||
startEventProxyServer({ | ||
port: 3031, | ||
proxyServerName: 'react-router-7-spa', | ||
}); |
59 changes: 59 additions & 0 deletions
59
dev-packages/e2e-tests/test-applications/react-router-7-spa/tests/errors.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
||
test('Sends correct error event', async ({ page, baseURL }) => { | ||
const errorEventPromise = waitForError('react-router-7-spa', event => { | ||
return !event.type && event.exception?.values?.[0]?.value === 'I am an error!'; | ||
}); | ||
|
||
await page.goto('/'); | ||
|
||
const exceptionButton = page.locator('id=exception-button'); | ||
await exceptionButton.click(); | ||
|
||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.exception?.values).toHaveLength(1); | ||
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!'); | ||
|
||
expect(errorEvent.request).toEqual({ | ||
headers: expect.any(Object), | ||
url: 'http://localhost:3030/', | ||
}); | ||
|
||
expect(errorEvent.transaction).toEqual('/'); | ||
|
||
expect(errorEvent.contexts?.trace).toEqual({ | ||
trace_id: expect.any(String), | ||
span_id: expect.any(String), | ||
}); | ||
}); | ||
|
||
test('Sets correct transactionName', async ({ page }) => { | ||
const transactionPromise = waitForTransaction('react-router-7-spa', async transactionEvent => { | ||
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload'; | ||
}); | ||
|
||
const errorEventPromise = waitForError('react-router-7-spa', event => { | ||
return !event.type && event.exception?.values?.[0]?.value === 'I am an error!'; | ||
}); | ||
|
||
await page.goto('/'); | ||
const transactionEvent = await transactionPromise; | ||
|
||
// Only capture error once transaction was sent | ||
const exceptionButton = page.locator('id=exception-button'); | ||
await exceptionButton.click(); | ||
|
||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.exception?.values).toHaveLength(1); | ||
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!'); | ||
|
||
expect(errorEvent.transaction).toEqual('/'); | ||
|
||
expect(errorEvent.contexts?.trace).toEqual({ | ||
trace_id: transactionEvent.contexts?.trace?.trace_id, | ||
span_id: expect.not.stringContaining(transactionEvent.contexts?.trace?.span_id || ''), | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.