mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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>
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import * as Sentry from '@sentry/react'
|
|
import { AlertCircleIcon } from 'lucide-react'
|
|
import { ErrorInfo } from 'react'
|
|
import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'
|
|
import { Alert, AlertDescription, AlertTitle, Button } from 'ui'
|
|
|
|
interface ErrorFallbackProps {
|
|
error: Error
|
|
resetErrorBoundary: () => void
|
|
message?: string
|
|
actions?: {
|
|
label: string
|
|
onClick: () => void
|
|
}[]
|
|
sentryContext?: Record<string, any>
|
|
}
|
|
|
|
const ErrorFallback = ({
|
|
error: _error,
|
|
resetErrorBoundary,
|
|
message = 'Something went wrong',
|
|
actions = [],
|
|
}: ErrorFallbackProps) => {
|
|
return (
|
|
<div className="p-4 bg-destructive-foreground h-full flex flex-col justify-center items-center">
|
|
<Alert variant="destructive">
|
|
<AlertCircleIcon />
|
|
<AlertTitle>{message}</AlertTitle>
|
|
<AlertDescription>We've been notified and will review and fix this issue.</AlertDescription>
|
|
<div className="mt-4 flex gap-2">
|
|
<Button onClick={resetErrorBoundary} className="text-sm">
|
|
Try again
|
|
</Button>
|
|
{actions?.map((action, index) => (
|
|
<Button key={index} onClick={action.onClick} className="text-sm">
|
|
{action.label}
|
|
</Button>
|
|
))}
|
|
</div>
|
|
</Alert>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
interface ErrorBoundaryProps {
|
|
children: React.ReactNode
|
|
message?: string
|
|
actions?: {
|
|
label: string
|
|
onClick: () => void
|
|
}[]
|
|
sentryContext?: Record<string, any>
|
|
onReset?: () => void
|
|
}
|
|
|
|
export const ErrorBoundary = ({
|
|
children,
|
|
message,
|
|
actions,
|
|
sentryContext,
|
|
onReset,
|
|
}: ErrorBoundaryProps) => {
|
|
const handleError = (error: Error, info: ErrorInfo) => {
|
|
Sentry.withScope((scope) => {
|
|
scope.setExtra('componentStack', info.componentStack)
|
|
if (sentryContext) {
|
|
Object.entries(sentryContext).forEach(([key, value]) => {
|
|
scope.setExtra(key, value)
|
|
})
|
|
}
|
|
Sentry.captureException(error)
|
|
})
|
|
}
|
|
|
|
const handleReset = () => {
|
|
onReset?.()
|
|
}
|
|
|
|
return (
|
|
<ReactErrorBoundary
|
|
fallbackRender={({ error, resetErrorBoundary }) => (
|
|
<ErrorFallback
|
|
error={error}
|
|
resetErrorBoundary={resetErrorBoundary}
|
|
message={message}
|
|
actions={actions}
|
|
/>
|
|
)}
|
|
onError={handleError}
|
|
onReset={handleReset}
|
|
>
|
|
{children}
|
|
</ReactErrorBoundary>
|
|
)
|
|
}
|