Skip to content

Commit c9e28b6

Browse files
nicohrubecclaude
andcommitted
fix(tanstackstart-react): Move Sentry.init() to client entry point
Moves client-side Sentry.init() from getRouter() to client.tsx so it runs before hydration. The browser tracing integration is added later via addIntegration() once the router is available. This ensures errors and breadcrumbs from code that runs before hydration (e.g. third-party library inits) are captured. Fixes #21088 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2be523a commit c9e28b6

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/src/client.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
import * as Sentry from '@sentry/browser';
12
import { StartClient } from '@tanstack/react-start/client';
23
import { StrictMode, startTransition } from 'react';
34
import { hydrateRoot } from 'react-dom/client';
45

6+
Sentry.init({
7+
environment: 'qa',
8+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
9+
tracesSampleRate: 1.0,
10+
release: 'e2e-test',
11+
tunnel: 'http://localhost:3031/',
12+
});
13+
514
console.log('early-breadcrumb-from-client-entry');
615

716
if (window.location.pathname === '/crash-before-hydration') {

dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/src/router.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ export const getRouter = () => {
99
});
1010

1111
if (!router.isServer) {
12-
Sentry.init({
13-
environment: 'qa',
14-
dsn: 'https://public@dsn.ingest.sentry.io/1337',
15-
integrations: [Sentry.browserTracingIntegration()],
16-
tracesSampleRate: 1.0,
17-
release: 'e2e-test',
18-
tunnel: 'http://localhost:3031/',
19-
});
12+
Sentry.addIntegration(Sentry.browserTracingIntegration());
2013
}
2114

2215
return router;

dev-packages/e2e-tests/test-applications/tanstackstart-react/src/client.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
import * as Sentry from '@sentry/tanstackstart-react';
12
import { StartClient } from '@tanstack/react-start/client';
23
import { StrictMode, startTransition } from 'react';
34
import { hydrateRoot } from 'react-dom/client';
45

6+
Sentry.init({
7+
environment: 'qa', // dynamic sampling bias to keep transactions
8+
dsn: __APP_DSN__,
9+
// We recommend adjusting this value in production, or using tracesSampler
10+
// for finer control
11+
tracesSampleRate: 1.0,
12+
release: 'e2e-test',
13+
tunnel: __APP_TUNNEL__,
14+
});
15+
516
console.log('early-breadcrumb-from-client-entry');
617

718
if (window.location.pathname === '/crash-before-hydration') {

dev-packages/e2e-tests/test-applications/tanstackstart-react/src/router.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ export const getRouter = () => {
99
});
1010

1111
if (!router.isServer) {
12-
Sentry.init({
13-
environment: 'qa', // dynamic sampling bias to keep transactions
14-
dsn: __APP_DSN__,
15-
integrations: [Sentry.tanstackRouterBrowserTracingIntegration(router)],
16-
// We recommend adjusting this value in production, or using tracesSampler
17-
// for finer control
18-
tracesSampleRate: 1.0,
19-
release: 'e2e-test',
20-
tunnel: __APP_TUNNEL__,
21-
});
12+
Sentry.addIntegration(Sentry.tanstackRouterBrowserTracingIntegration(router));
2213
}
2314

2415
return router;

0 commit comments

Comments
 (0)