Files
supabase/apps/studio/lib/sentry-server-options.ts
Alaister YoungandAlaister Young bbb0af65cb [FE-3106] (part 14) – refactor(studio): drop the dual-runtime shims and aliases (#53223)
Drops the remaining Next-era shims and aliases that only existed for the
dual runtime (FE-3106). Part 14 of the stack.

**Depends on:** #53222

**Changed:**
- ~45 files – import Sentry from `@sentry/react` directly instead of the
aliased `@sentry/nextjs`
- `hooks/ui/usePreventNavigationOnUnsavedChanges.ts` – is now the
TanStack `useBlocker` implementation (previously swapped in by a Vite
alias)
- `components/interfaces/App/RouteValidationWrapper.tsx` – `next/router`
→ `useNavigate` + the leaf route's `fullPath` (`/project/$ref/sql/$id`)
for the exempt-route and last-visited checks
- `hooks/misc/withAuth.tsx` – no `getLayout` forwarding
- `TemplateEditor.test.tsx` – renders inside a router for the
unsaved-changes blocker

**Removed:**
- `compat/sentry-nextjs.ts` and its Vite alias, the
`usePreventNavigationOnUnsavedChanges` alias and Next hook,
`types/next.ts` (`NextPageWithLayout`), the `@sentry/nextjs` dependency

The `compat/next/*` shims for `link`, `router`, `head`, `image`,
`navigation`, `dynamic` and `script` stay: about 300 components outside
`routes/**` still import them.

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

## To test

- Trigger an error (e.g. a failing query) – it reaches Sentry as before
- Edit an email template or edge function and navigate away – the
unsaved-changes prompt appears
- Open an org you don't belong to – toast and redirect home; open a SQL
snippet, leave and come back – last snippet is restored

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-17 17:49:20 +09:00

54 lines
1.9 KiB
TypeScript

// Sentry server-side configuration, used by `instrument.server.mjs` (imported
// first by `server.ts`).
import type { init } from '@sentry/tanstackstart-react'
import { applyStudioErrorPolicy } from '@/lib/errors/sentry-event-policy'
// `@sentry/core`'s `Options` isn't a direct dependency, and the SDK doesn't re-export it.
type SentryServerOptions = Parameters<typeof init>[0]
export interface SentryServerOptionsOverrides {
/**
* Release identifier (the commit SHA). The build runs no Sentry bundler plugin to inject one.
*/
release?: string
}
export function buildSentryServerOptions({
release,
}: SentryServerOptionsOverrides = {}): SentryServerOptions {
return {
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
...(process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT && {
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
}),
// Conditional spread so the key is absent, not `undefined`; see `release` above.
...(release && { release }),
debug: false,
tracesSampleRate: 0.02,
// Integrations (e.g. the Vercel AI SDK tool-call capture) report thrown errors directly, without
// going through `reportStudioError`, so Studio's privacy rules are applied here too.
beforeSend(event, hint) {
return applyStudioErrorPolicy(event, hint.originalException)
},
ignoreErrors: [
'ResizeObserver',
'Failed to load Stripe.js',
// Next.js internals, not actual errors (harmless on TanStack)
'NEXT_NOT_FOUND',
'NEXT_REDIRECT',
// Network / infrastructure
/504 Gateway Time-out/,
'Network request failed',
'Failed to fetch',
'AbortError',
// Code-split loading failures
'ChunkLoadError',
/Loading chunk [\d]+ failed/,
// React hydration mismatches caused by extensions modifying DOM before hydration
/text content does not match/i,
/There was an error while hydrating/i,
],
}
}