Files
supabase/apps/studio/components/interfaces/QueryPerformance/QueryPerformance.utils.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

72 lines
2.0 KiB
TypeScript

import * as Sentry from '@sentry/react'
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
import { getErrorMessage } from '@/lib/get-error-message'
dayjs.extend(duration)
export const formatDuration = (milliseconds: number, precision: number = 2) => {
const duration = dayjs.duration(milliseconds, 'milliseconds')
const days = Math.floor(duration.asDays())
const hours = duration.hours()
const minutes = duration.minutes()
const seconds = duration.seconds()
const totalSeconds = duration.asSeconds()
if (totalSeconds < 60) {
return `${totalSeconds.toFixed(precision)}s`
}
const parts = []
if (days > 0) parts.push(`${days}d`)
if (hours > 0) parts.push(`${hours}h`)
if (minutes > 0) parts.push(`${minutes}m`)
if (seconds > 0) parts.push(`${seconds}s`)
return parts.length > 0 ? parts.join(' ') : '0s'
}
export type QueryPerformanceErrorContext = {
projectRef?: string
databaseIdentifier?: string
queryPreset?: string
queryType?: 'hitRate' | 'metrics' | 'mainQuery' | 'slowQueriesCount' | 'supamonitor'
sql?: string
postgresVersion?: string
databaseType?: 'primary' | 'read-replica'
}
export function captureQueryPerformanceError(
error: unknown,
context: QueryPerformanceErrorContext
) {
Sentry.withScope((scope) => {
scope.setTag('query-performance', 'true')
scope.setContext('query-performance', {
projectRef: context.projectRef,
databaseIdentifier: context.databaseIdentifier,
queryPreset: context.queryPreset,
queryType: context.queryType,
postgresVersion: context.postgresVersion,
databaseType: context.databaseType,
})
if (error instanceof Error) {
Sentry.captureException(error)
return
}
const errorMessage = getErrorMessage(error)
const errorToCapture = new Error(errorMessage || 'Query performance error')
if (error !== null && error !== undefined) {
errorToCapture.cause = error
}
Sentry.captureException(errorToCapture)
})
}