Files
supabase/apps/studio/lib/toast-errors.tsx
Gildas Garcia 54a271b0f8 Upgrade sonner to 2x and update toast design (#52003)
## Problem

Two issues:
- There's an accessibility issue with sonner before v2 as it applies
`role="status"` to an `li` element
- The custom Tailwind classes we pass are not applied and once applied
correctly, the design is not what we want

## Solution

- Upgrade sonner to v2 (the aria attribute are now applied to the toasts
container)
- Fix the design, especially the close icon and the upload usages (with
progression)

In all screenshots, the close button is only displayed when hovering the
toast.

<img width="384" height="73" alt="image"
src="https://github.com/user-attachments/assets/c34038f1-30ce-43d7-a031-81727d61592c"
/>

<img width="776" height="156" alt="image"
src="https://github.com/user-attachments/assets/ec27ff42-6887-4b12-a39b-262a3adacf6b"
/>

<img width="385" height="78" alt="image"
src="https://github.com/user-attachments/assets/c6b36ec9-881c-4dbe-a0c0-81b2b2b5053f"
/>

## Review instructions

On [Design
System](https://design-system-hgbzzl10s-supabase.vercel.app/design-system/docs/components/sonner):
- Check each example with extra attention to the loading/promise and
upload ones

On
[Studio](https://studio-staging-1nx2cwequ-supabase.vercel.app/dashboard/),
in the Table Editor:
- Create a new table by importing a CSV file and check there's only one
loading icon while the progress is shown (requires a quite big CSV as
it's fast)
- Then import more data in the new table
2026-10-26 09:45:23 +01:00

43 lines
1.4 KiB
TypeScript

import { useEffect } from 'react'
import { useSonner } from 'sonner'
import { isDashboardErrorSampled } from '@/lib/telemetry/error-sampling'
import type { FunnelErrorClassification, FunnelOrigin } from '@/lib/telemetry/funnel-errors'
import { useTrack } from '@/lib/telemetry/track'
type FunnelErrorProperties = { origin: FunnelOrigin } & FunnelErrorClassification
// Funnel call sites register their toast id (via useTrackFunnelError) so the tracker emits a
// single enriched event for that toast instead of an untagged duplicate.
const funnelErrorToasts = new Map<string | number, FunnelErrorProperties>()
const seenToastIds = new Set<string | number>()
export function registerFunnelErrorToast(
toastId: string | number,
properties: FunnelErrorProperties
) {
funnelErrorToasts.set(toastId, properties)
}
export const ToastErrorTracker = () => {
const track = useTrack()
const { toasts } = useSonner()
useEffect(() => {
toasts.forEach((toast) => {
if (toast.type !== 'error' || seenToastIds.has(toast.id)) return
seenToastIds.add(toast.id)
const funnelProperties = funnelErrorToasts.get(toast.id)
funnelErrorToasts.delete(toast.id)
if (isDashboardErrorSampled()) {
track('dashboard_error_created', {
source: 'toast',
...funnelProperties,
})
}
})
}, [toasts, track])
return null
}