mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 2 of a 6-PR stack migrating all `next/router` and `next/compat/router` imports in `apps/studio` onto TanStack Router hooks and removing the router shims. | Part | PR | Scope | | --- | --- | --- | | 1 | #54053 | Core navigation helpers, `hooks/**`, `lib/**`, `data/prefetchers/**` | | **2** | **#54054 ← this PR** | **`components/ui/**`** | | 3 | #54055 | `components/layouts/**` and `state/tabs.tsx` | | 4 | #54056 | Database, Branching, Compute, Edge Functions, Explorer, SQL Editor, Storage, Table Editor | | 5 | #54057 | Remaining `components/interfaces/**` and `QueryInsightsTable` router events | | 6 | #54058 | Remove `next/router` & `next/compat/router` shims, `_router-events.ts`, Vite aliases, and test mocks | Migrates all 15 `apps/studio/components/ui/**` files off `next/router`. **Changed:** - Replaced `useRouter` across `AIAssistantPanel` (`AIAssistant`, `ModelSelector`), `Charts/ComposedChartHandler`, `EditorPanel`, `ErrorBoundary` (`ClientSideExceptionHandler`, `GlobalErrorBoundaryState`, `InsertBeforeRemoveChildErrorHandler`), `GlobalShortcuts/ShortcutsReferenceSheet`, `HelpPanel` (`HelpOptionsList`, `HelpPanel`), `ProductMenu/ProductMenuShortcuts`, `QueryBlock/EditQueryButton`, and `ResourceExhaustionWarningBanner` with TanStack's `useNavigate`, `useLocation`, `useRoutePattern`, and `useParams` from `common` - Updated `AIAssistant.test.tsx`, `HelpOptionsList.test.tsx`, and `ProductMenuShortcuts.test.tsx` to use TanStack Router instead of `next/router` mocks **Simplified:** - `EditQueryButton` and `ShortcutsReferenceSheet` match against `useRoutePattern()` instead of the real pathname, as `router.pathname` did before. A ref or slug containing `sql` or `advisors` no longer misfires. - Removed the unused `restrictToRoutes` field from `ResourceExhaustionWarningBanner` (no warning sets it) - `AIAssistant` clears the handoff param with `navigate({ to: '.' })`, dropping a pathname subscription and an `AnyRouter` cast - `ProductMenuShortcuts` inlines its handler (`useShortcut` always calls the latest callback) - Moved the `AdvisorsNavigationShortcuts.test.tsx` fix into this PR so it passes on its own - Tests use the shared `createTestRouter` and `customRender` router Addresses [FE-5109](https://linear.app/supabase/issue/FE-5109/replace-the-nextrouter-shims-with-tanstack-router-hooks) ## To test - [ ] AI Assistant panel links, model selector navigation, and "Edit in SQL Editor" (`EditQueryButton`) navigate cleanly - [ ] Keyboard shortcuts in `ProductMenuShortcuts` and the shortcuts reference sheet (`?`) match the active section and navigate as expected - [ ] Error boundary recovery ("Reload page" / navigation actions) and Help panel links still work - [ ] Resource exhaustion warning banner matches project routes as before --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
111 lines
3.8 KiB
TypeScript
111 lines
3.8 KiB
TypeScript
import { SupportCategories } from '@supabase/shared-types/out/constants'
|
|
import { useNavigate } from '@tanstack/react-router'
|
|
import { safeLocalStorage, safeSessionStorage } from 'common'
|
|
import { ExternalLinkIcon } from 'lucide-react'
|
|
import { Button, cn } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
|
|
import CopyButton from '../CopyButton'
|
|
import { InlineLinkClassName } from '../InlineLink'
|
|
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
|
|
|
|
interface ClientSideExceptionHandlerProps {
|
|
message: string
|
|
sentryIssueId: string
|
|
urlMessage: string
|
|
resetErrorBoundary: () => void
|
|
}
|
|
|
|
export const ClientSideExceptionHandler = ({
|
|
message,
|
|
sentryIssueId,
|
|
urlMessage,
|
|
resetErrorBoundary,
|
|
}: ClientSideExceptionHandlerProps) => {
|
|
const navigate = useNavigate()
|
|
|
|
const isProduction = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
|
|
|
|
const handleClearStorage = () => {
|
|
safeLocalStorage.clear()
|
|
safeSessionStorage.clear()
|
|
window.location.reload()
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="flex flex-col gap-y-1 text-left py-2 w-full">
|
|
<div className="flex items-center justify-between mb-3">
|
|
<p className="text-lg font-bold">Sorry! An unexpected error occurred.</p>
|
|
<CopyButton variant="outline" text={message} copyLabel="Copy error" />
|
|
</div>
|
|
<p className="text-sm">
|
|
Application error: a client-side exception has occurred (see browser console for more
|
|
information)
|
|
</p>
|
|
<p className="text-foreground-light text-sm">{message}</p>
|
|
</div>
|
|
<Admonition type="note" showIcon={false} title="We recommend trying the following:">
|
|
<ul className="list-disc mt-1.5 pl-2 list-inside text-sm space-y-1">
|
|
<li>
|
|
<span
|
|
className={cn(InlineLinkClassName, 'cursor-pointer')}
|
|
onClick={() => window.location.reload()}
|
|
>
|
|
Refresh
|
|
</span>{' '}
|
|
the page
|
|
</li>
|
|
<li>
|
|
<span
|
|
className={cn(InlineLinkClassName, 'cursor-pointer')}
|
|
onClick={() => void navigate({ to: '/logout' })}
|
|
>
|
|
Sign out
|
|
</span>{' '}
|
|
and sign back in
|
|
</li>
|
|
<li>
|
|
<span
|
|
className={cn(InlineLinkClassName, 'cursor-pointer')}
|
|
onClick={handleClearStorage}
|
|
>
|
|
Clear your browser storage
|
|
</span>{' '}
|
|
to clean potentially outdated data
|
|
</li>
|
|
<li>Disable browser extensions that might modify page content (e.g. Google Translate)</li>
|
|
<li>If the problem persists, please contact support for assistance</li>
|
|
</ul>
|
|
</Admonition>
|
|
|
|
<div className={cn('w-full mx-auto grid gap-2', 'grid-cols-2 sm:w-1/2')}>
|
|
<Button asChild icon={<ExternalLinkIcon />}>
|
|
<SupportLink
|
|
queryParams={{
|
|
category: SupportCategories.DASHBOARD_BUG,
|
|
subject: 'Client side exception occurred on dashboard',
|
|
sid: sentryIssueId,
|
|
errorMessage: urlMessage,
|
|
}}
|
|
>
|
|
Contact support
|
|
</SupportLink>
|
|
</Button>
|
|
|
|
{/* [Joshen] For local and staging, allow us to escape the error boundary */}
|
|
{/* We could actually investigate how to make this available on prod, but without being able to reliably test this, I'm not keen to do it now */}
|
|
{isProduction ? (
|
|
<Button variant="outline" onClick={() => window.location.reload()}>
|
|
Reload dashboard
|
|
</Button>
|
|
) : (
|
|
<Button variant="outline" onClick={() => resetErrorBoundary()}>
|
|
Return to dashboard
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</>
|
|
)
|
|
}
|