Files
supabase/apps/studio/components/ui/ErrorBoundary/ClientSideExceptionHandler.tsx
Alaister Young ca2b50a0a7 chore(ui-patterns): collapse the admonition shim into ui-patterns/Admonition (#48377)
Follow-up to #48344: collapses the two resolution paths for the
Admonition module into one.

`src/admonition.tsx` was a back-compat shim re-exporting
`src/Admonition/`. Two ways to resolve one module is exactly what
produced the macOS self-import bug fixed in #48344, and the local
typecheck errors that #48374 worked around. This removes the shim and
standardizes on the PascalCase subpath, matching every other export in
the package.

**Changed:**

- Codemodded all 246 `ui-patterns/admonition` imports to
`ui-patterns/Admonition` (240 `.tsx`, 5 `.mdx`, 1 `.ts` across studio,
docs, www, design-system, and lite-studio)
- Pointed the 5 internal `'../admonition'` imports back at the
`'../Admonition'` directory

**Removed:**

- `packages/ui-patterns/src/admonition.tsx`, and its `./admonition`
entry in the exports map (regenerated with `pnpm gen:exports`)

## To test

- `grep -r "ui-patterns/admonition" --include='*.ts*'` → no hits
- `pnpm test:case-hazards` → passes
- `pnpm typecheck` → all 15 tasks green
- `pnpm --filter studio run lint:ratchet` → passes
- `pnpm --filter ui-patterns vitest run src/Admonition` → 11 tests pass

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Standardized Admonition component imports across the application and
documentation.
* Improved compatibility with case-sensitive environments by using the
canonical component path.
  * Removed the legacy Admonition import entry point.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-07-29 00:48:56 +08:00

111 lines
3.7 KiB
TypeScript

import { SupportCategories } from '@supabase/shared-types/out/constants'
import { safeLocalStorage, safeSessionStorage } from 'common'
import { ExternalLink } from 'lucide-react'
import { useRouter } from 'next/router'
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 router = useRouter()
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={() => router.push('/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 variant="default" icon={<ExternalLink />}>
<SupportLink
queryParams={{
category: SupportCategories.DASHBOARD_BUG,
subject: 'Client side exception occurred on dashboard',
sid: sentryIssueId,
error: 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={() => router.reload()}>
Reload dashboard
</Button>
) : (
<Button variant="outline" onClick={() => resetErrorBoundary()}>
Return to dashboard
</Button>
)}
</div>
</>
)
}