diff --git a/src/components/MaintainersMap.tsx b/src/components/MaintainersMap.tsx index 3af2eaecc..6a179e495 100644 --- a/src/components/MaintainersMap.tsx +++ b/src/components/MaintainersMap.tsx @@ -672,7 +672,11 @@ function GlobeAvatar({ export function MaintainersMap({ maintainers }: MaintainersMapProps) { const { data: initialLocation } = useSuspenseQuery({ queryKey: ['maintainers-globe', 'visitor-location'], - queryFn: () => getVisitorLocation().catch(() => null), + queryFn: () => + getVisitorLocation().then( + (location) => location ?? null, + () => null, + ), staleTime: Infinity, }) const prefix = useId().replace(/[^a-zA-Z0-9_-]/g, '') diff --git a/src/instrument.server.mjs b/src/instrument.server.mjs index 594affb50..08418f77f 100644 --- a/src/instrument.server.mjs +++ b/src/instrument.server.mjs @@ -7,7 +7,9 @@ if (!Sentry.getClient()) process.env.SENTRY_DSN ?? 'https://ac4bfc43ff4a892f8dc7053c4a50d92f@o4507236158537728.ingest.us.sentry.io/4507236163649536', enabled: - process.env.NODE_ENV === 'production' || Boolean(process.env.SENTRY_DSN), + process.env.NODE_ENV !== 'test' && + (process.env.NODE_ENV === 'production' || + Boolean(process.env.SENTRY_DSN)), integrations: [], sendDefaultPii: true, // Performance Monitoring diff --git a/src/utils/sentry.server.ts b/src/utils/sentry.server.ts index 9422c6b31..08f748736 100644 --- a/src/utils/sentry.server.ts +++ b/src/utils/sentry.server.ts @@ -10,6 +10,7 @@ export function initSentryServer(): void { Sentry.init({ dsn: env.SENTRY_DSN ?? SENTRY_DSN, enabled: + process.env.NODE_ENV !== 'test' && import.meta.env.MODE !== 'staging' && (process.env.NODE_ENV === 'production' || Boolean(env.SENTRY_DSN)), tracesSampleRate: 1.0, diff --git a/tests/sentry-initialization.test.ts b/tests/sentry-initialization.test.ts index a16f42973..1bd1c7e53 100644 --- a/tests/sentry-initialization.test.ts +++ b/tests/sentry-initialization.test.ts @@ -2,7 +2,12 @@ import assert from 'node:assert/strict' import test from 'node:test' import * as Sentry from '@sentry/tanstackstart-react' -test('server instrumentation reuses its client after a module reload', async () => { +test('server instrumentation stays disabled in tests and reuses its client after a reload', async (t) => { + t.mock.property(process, 'env', { + ...process.env, + NODE_ENV: 'test', + SENTRY_DSN: 'https://fixture@example.invalid/1', + }) const listenerCounts = () => ['beforeExit', 'uncaughtException', 'unhandledRejection'].map((event) => process.listenerCount(event), @@ -15,6 +20,7 @@ test('server instrumentation reuses its client after a module reload', async () const client = Sentry.getClient() const counts = listenerCounts() assert.ok(client) + assert.equal(client.getOptions().enabled, false) await import( new URL('../src/instrument.server.mjs?reload=2', import.meta.url).href