mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
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>
76 lines
3.9 KiB
TypeScript
76 lines
3.9 KiB
TypeScript
// Sentry client init for the TanStack Start (Vite) build.
|
|
//
|
|
// NOTE: deliberately not named `sentry.client.tanstack.ts` — TanStack Start's
|
|
// import-protection denies `**/*.client.*` modules in the server bundle, and
|
|
// this module is imported from router.tsx (shared between client and server).
|
|
// It is isomorphic by design: the `typeof window` guard below makes it a
|
|
// no-op on the server.
|
|
//
|
|
// Without this init every `Sentry.captureException` in the app (including the
|
|
// globalErrorBoundary / routerErrorComponent captures in routes/__root.tsx)
|
|
// would be a silent no-op.
|
|
//
|
|
// Called from `getRouter()` (router.tsx) — the earliest point in the TanStack
|
|
// client bootstrap with access to the router instance, which
|
|
// `tanstackRouterBrowserTracingIntegration` needs at init time so the
|
|
// pageload span is captured, not just later navigations.
|
|
//
|
|
// App code imports the same `@sentry/react` instance, so its captures report
|
|
// through the client initialized here.
|
|
import * as Sentry from '@sentry/react'
|
|
import type { AnyRouter } from '@tanstack/react-router'
|
|
|
|
import { buildSentryClientOptions } from '@/lib/sentry-client-options'
|
|
|
|
let isInitialized = false
|
|
|
|
export function initSentryTanStackClient(router: AnyRouter) {
|
|
// Client-only: getRouter() also runs during SSR/prerender; the server is
|
|
// initialized separately by instrument.server.mjs.
|
|
if (typeof window === 'undefined') return
|
|
// getRouter() is called once per pageload today; keep the guard so a future
|
|
// second call can't double-init the client.
|
|
if (isInitialized) return
|
|
isInitialized = true
|
|
|
|
// No-ops cleanly when NEXT_PUBLIC_SENTRY_DSN is unset (local/self-hosted):
|
|
// `init` without a dsn creates a disabled client, and beforeSend drops
|
|
// everything when !IS_PLATFORM regardless.
|
|
Sentry.init(
|
|
buildSentryClientOptions({
|
|
// The Vite build doesn't run a Sentry bundler plugin, so stack frames
|
|
// carry no `supabase-studio` applicationKey metadata. Without the
|
|
// metadata the integration would tag EVERY event third_party_code=true
|
|
// and beforeSend would drop them all. Leave it off until the Vite build
|
|
// annotates frames (@sentry/vite-plugin moduleMetadata).
|
|
includeThirdPartyErrorFilter: false,
|
|
extraIntegrations: [
|
|
Sentry.tanstackRouterBrowserTracingIntegration(router, {
|
|
// Skip the per-asset resource-timing spans. The Vite/Rolldown build
|
|
// ships ~250 separate immutable chunks on initial load, and the
|
|
// browser tracing integration turns EVERY one of them into a child
|
|
// span of the pageload transaction. Measured over 7 days in the
|
|
// supabase-app Sentry project, this build emitted ~3,500x the
|
|
// `resource.other` spans of the former Next build on comparable pageload
|
|
// traffic, and `resource.*` was over half of all span volume in the
|
|
// project. That burned the span budget, tripped Sentry's spike
|
|
// protection, and made the pageload/throughput alerts fire (FE-4755).
|
|
//
|
|
// What this does NOT drop: `http.client` spans (the SDK excludes
|
|
// `fetch`/`xmlhttprequest` initiators from resource spans and
|
|
// instruments them separately), Web Vitals, navigation and pageload
|
|
// timings. We only lose the per-asset waterfall.
|
|
ignoreResourceSpans: ['resource.other', 'resource.link', 'resource.script'],
|
|
}),
|
|
],
|
|
// Without a release the SDK silently drops session envelopes
|
|
// (`Client.sendSession` early-returns), so Release Health sends nothing
|
|
// at all. Inline the Vercel commit SHA (vite.config.ts re-exposes
|
|
// VERCEL_GIT_COMMIT_SHA under the NEXT_PUBLIC_ name).
|
|
// Unset outside Vercel (local/self-hosted), where sessions don't matter —
|
|
// so session envelopes only fire on deploys, not on a local dev build.
|
|
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
|
|
})
|
|
)
|
|
}
|