Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sentry-client-entry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workspace/web": patch
---

Sentry now initializes in a dedicated client entry before hydration, so client errors thrown during early module evaluation are captured. The router-aware browser-tracing integration is attached separately once the router exists.
30 changes: 30 additions & 0 deletions apps/web/src/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as Sentry from "@sentry/tanstackstart-react";
import { StartClient } from "@tanstack/react-start/client";
import { StrictMode, startTransition } from "react";
import { hydrateRoot } from "react-dom/client";

// Initialize Sentry here, in the client entry, before hydration — so telemetry
// emitted during module evaluation (e.g. a third-party lib that throws at import
// time) is captured. The router-aware browser-tracing integration needs the
// router instance, so it's attached separately in router.tsx via
// Sentry.addIntegration once the router exists. See issue #320.
//
// The hydration below mirrors TanStack Start's default client entry for our
// version; defining this file overrides that default.
if (import.meta.env.VITE_SENTRY_DSN) {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
environment: import.meta.env.MODE,
sendDefaultPii: true,
tracesSampleRate: 1.0,
});
}

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<StartClient />
</StrictMode>,
);
});
11 changes: 4 additions & 7 deletions apps/web/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ export const getRouter = () => {
defaultStaleTime: 30_000, // Cache loader data for 30s to avoid re-fetching on navigations
});

// Sentry.init() runs in the client entry (client.tsx) before hydration; here
// we only attach the router-aware browser-tracing integration, which needs
// the router instance that doesn't exist yet at client-entry time. See #320.
if (!router.isServer && import.meta.env.VITE_SENTRY_DSN) {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
environment: import.meta.env.MODE,
sendDefaultPii: true,
integrations: [Sentry.tanstackRouterBrowserTracingIntegration(router)],
tracesSampleRate: 1.0,
});
Sentry.addIntegration(Sentry.tanstackRouterBrowserTracingIntegration(router));
}

setupRouterSsrQueryIntegration({ router, queryClient: rqContext.queryClient });
Expand Down