ask-sonner

Leitfaden für Sonner, die React-Toast-Bibliothek — Installation und Einrichtung des Toasters, Auswahl des richtigen toast()-Aufrufs, Promise- und Lade-Toasts, Aktualisieren, Schließen und Beibehalten von Toasts, Styling, Theming und Icons, Positionierung und mehrere Toaster. Verwenden Sie dies, wenn Sie mit Sonner arbeiten oder Probleme beheben — Toasts, die nicht erscheinen, doppelt erscheinen, ihre Stile verlieren, Tailwind-Klassen ignorieren, hinter einem Modal liegen oder den Dunkelmodus nicht befolgen.

npx skills add https://github.com/emilkowalski/skills --skill ask-sonner

Working With Sonner

Initial Response

When this skill is first invoked without a specific question, respond only with:

I'm ready to help you set up, style, and troubleshoot Sonner, my knowledge comes from its author, Emil Kowalski.

Do not provide any other information until the user asks a question.

A guide skill for Sonner, the toast library. When a task involves Sonner — wiring it up, rendering toasts, styling them, or fixing them — answer from this file first. Full prop tables for <Toaster /> and toast() live in API.md; read it when you need an exact prop name, type, or default.

Setup

Two pieces, and only two:

  1. One <Toaster />, mounted once, as close to the root as possible (in Next.js: layout.tsx — it works inside server components). Never render it per-page or conditionally; a second Toaster without its own id duplicates every toast.
  2. toast() called from client code — event handlers, effects, callbacks. It's a plain function, no hook or provider needed, but it does nothing on the server: in a server action, return the result and call toast() in the client code that receives it.
import { Toaster } from 'sonner'; // once, in layout
import { toast } from 'sonner';   // anywhere client-side

Picking the right call

You wantCall
Plain messagetoast('Title') — add { description } for a second line
Success / error / info / warning icontoast.success('…'), toast.error('…'), etc.
Spinner while you manage state yourselftoast.loading('…'), then update it by id
Loading → success/error tied to a promisetoast.promise(promise, { loading, success, error }) — success/error accept functions receiving the resolved value/error
Button that does something{ action: { label, onClick } } — closes the toast unless onClick calls event.preventDefault(); cancel is the secondary variant
Custom JSX, default toast shelltoast(<jsx />)
Custom JSX, no styles at alltoast.custom((t) => <jsx />) — headless, t gives you the id to dismiss

Recipes

Update a toast — call toast() again with the same id; only the props you pass change. Switching to toast.success(…, { id }) changes the type. This is how loading → success flows work without toast.promise:

const id = toast.loading('Uploading…');
toast.success('Uploaded', { id });

Persist — { duration: Infinity }. Dismiss — toast.dismiss(id), or toast.dismiss() for all. Read active toasts — useSonner() in React, toast.getToasts() outside it.

Links or components in the text — pass a function for the title or description: toast(() => <a href="…">View</a>).

Multiple toasters — give each an id and target with toast('…', { toasterId: 'canvas' }). A toaster with an id renders only toasts targeted at it; a toaster without one renders only untargeted toasts.

Close callbacks — onDismiss fires on close button, swipe, or toast.dismiss(); onAutoClose fires on timeout. They are separate; there is no single "closed" callback.

Styling — the escalation ladder

Climb only as far as the change requires. Exception: if you'd mark more than a few classes !important, go straight to headless — it's the recommended end state.

  1. Defaults — plus richColors on the Toaster for colorful success/error, invert to flip against the theme.
  2. Inline tweaks — toastOptions={{ style: {…} }} on the Toaster for all toasts, or style per toast() call.
  3. Classes on parts — toastOptions={{ classNames: { toast, title, description, actionButton, cancelButton, closeButton } }}. Sonner's injected styles win the cascade, so every class needs !important (Tailwind: !text-red-900). If you're marking more than a few things important, stop — go headless.
  4. Headless — toast.custom() with your own JSX, keeping Sonner's positioning, stacking, and swipe. The recommended approach for a design-system toast: wrap it in your own toast() abstraction. (unstyled: true exists as a halfway house, but headless gives more control for the same effort.)

Icons — swap defaults per-type with the Toaster's icons prop, per-toast with icon, remove with null.

Theme — theme defaults to 'light' and does not track the OS. Pass theme="system", or wire your theme provider: <Toaster theme={resolvedTheme} /> from next-themes.

Troubleshooting

SymptomCause → fix
Toast never appearsNo <Toaster /> mounted, or it unmounted (conditional render, per-page placement). Mount one at the root. If calling from a server action: toast() is client-only — call it with the action's result on the client.
Same toast appears twiceTwo Toasters mounted (layout and page) — keep one. Or toast() fired in an effect under React StrictMode's dev double-invoke — fire from the event handler instead, or pass a stable id so the second call updates rather than duplicates.
Tailwind/CSS classes have no effectDefault styles override them. Mark them !important, or use unstyled / headless (see the ladder above).
Toasts render completely unstyled (common in Astro, view transitions)Sonner's injected stylesheet was lost — import it explicitly in a layout: import 'sonner/dist/styles.css'.
Unstyled inside Shadow DOMStyles land in document.head, not the shadow root. Copy the style tag whose text includes [data-sonner-toaster] into the shadow root.
Toast behind a modal/overlay, or clippedAn ancestor creates a stacking context (transform, filter) or clips it (overflow), or the overlay out-z-indexes the toaster. Move <Toaster /> to the document root, outside any dialog/portal container.
Dark mode ignoredtheme defaults to 'light' — set theme="system" or pass the resolved theme (see Theme above).
Success/error look gray, not green/redThat's the default. Add richColors to the Toaster.
Toast never closesduration: Infinity, or a toast.promise whose promise never settles — the loading toast waits forever.
toast.promise stuck on loadingIt needs a promise (or a function returning one) as its first argument, and the promise must actually resolve/reject.
Swipe-to-dismiss goes the wrong way / doesn't workDirections derive from position. Override with swipeDirections on the Toaster.
Toast shows up in every toasterMultiple toasters need targeting: give each Toaster an id and pass toasterId in the toast() call.
Toasts too close to the screen edge on mobileoffset (desktop, default 24px) and mobileOffset (<600px, default 16px) — numbers, CSS strings, or per-side objects.

Mehr Skills von emilkowalski

animate
emilkowalski
Erstelle eine Animation von Grund auf und triff die Entscheidungen in der Reihenfolge, die bestimmt, ob sie sich richtig anfühlt – soll sie überhaupt animieren, welcher Zweck, welches Werkzeug, welche Eigenschaften, welche Kurve und Dauer, wie sie unterbricht, wie sie endet. Schreibt die Implementierung. Verwenden, wenn darum gebeten wird, etwas zu animieren, Bewegung hinzuzufügen, eine Komponente lebendig wirken zu lassen oder einen Übergang zu bauen. Für Kritik an bestehender Bewegung review-animations verwenden; für die Prüfung einer gesamten Codebasis improve-animations verwenden.
animate-expo
emilkowalski
Erstellt Animationen in React Native und Expo und trifft die Entscheidungen in der Reihenfolge, die darüber bestimmt, ob sie sich richtig anfühlen: Soll etwas animiert werden, auf welchem Thread läuft die Animation, welche Eigenschaften werden animiert, Spring oder Timing, wie wird die Geste übergeben und wie verhält sich die Animation bei eingeschränkten Bedingungen? Schreibt die Implementierung mit Reanimated, Gesture Handler, Expo Router und expo-haptics. Verwenden, wenn in einer Expo-App etwas animiert, Gesten hinzugefügt, Sheets, Bildschirmübergänge, Feedback beim Drücken oder haptisches Feedback umgesetzt oder ruckelnde Animationen auf dem Gerät behoben werden sollen. Für...
developmentdesign
animation-performance
emilkowalski
Keep web animations inside the frame budget — animate composite-only properties, keep motion off the main thread when the page is busy, and find the cause when an animation drops frames. Use when an animation is janky, choppy, stutters, or drops frames; when choosing which property to animate; when deciding between CSS and JS animation on performance grounds; or when reaching for `will-change` or GPU layers. For choosing easing, duration, or whether to animate at all use animate; for...
developmentdesign
animation-vocabulary
emilkowalski
Umgekehrtes Nachschlageglossar, das eine vage Beschreibung einer Web-Animation oder Bewegungswirkung in den genauen Begriff umwandelt („das Hüpfende, wenn ein Popover aufgeht“ → Pop in; „das iOS-Gummiband-Scrollen“ → Rubber-banding). Verwenden, wenn der Benutzer fragt: „Wie heißt das, wenn…“ oder eine Bewegungswirkung beschreibt, ohne deren Namen zu kennen, und das richtige Wort für eine KI oder einen Designer benötigt. Zum Benennen einer Wirkung, nicht zum Entwerfen oder Erstellen.
researchdesigncreative
apple-design
emilkowalski
Apples Ansatz für Interface-Design und flüssige, physikalische Bewegung, für das Web übersetzt. Verwenden beim Erstellen oder Überprüfen von gestengesteuerten Benutzeroberflächen, Federanimationen, Drag-/Swipe-/Sheet-Interaktionen, Momentum und unterbrechbaren Übergängen, transluzenten Materialien und Tiefe, Typografie (optische Größenanpassung, Laufweite, Zeilenabstand), reduzierter Bewegung oder den Design-Grundlagen (Feedback, räumliche Konsistenz, Zurückhaltung) hinter Apple-ähnlichen Oberflächen.
ask-emil
emilkowalski
Frage, welcher Skill oder Flow zu deiner Situation passt. Ein Router für die Skills in diesem Repo.
developmentproductivity
break-ui
emilkowalski
Versuche, ein UI-Element mit Worst-Case-Daten zu überfordern – langen Namen, nicht umbrechbaren E-Mail-Adressen, einbuchstabigen Namen, fehlenden Feldern, riesigen Zahlen, null Elementen, langen Beschriftungen, nichtlateinischem Text, Emojis und extremen Zahlen. Zeige es anschließend hinter einem Schalter „Demodaten / Worst Case“ an und melde alles, was kaputtgegangen ist, samt jeweiliger Lösung. Verwende dies, wenn der Nutzer einen Stresstest durchführen, eine Komponente oder einen Bildschirm kaputtmachen oder Grenzfälle finden lassen möchte oder darum bittet, „den Worst Case auszuprobieren“. Für Kritik am visuellen Design verwende emil-design-eng; für Animationen …
testingdesigndevelopment
choreograph
emilkowalski
Mehrere Elemente koordinieren, die sich gemeinsam bewegen: festlegen, was sich bewegt, in welcher Reihenfolge, wie stark sich die Bewegungen überlappen und was stillsteht – damit eine Gruppe wie eine einzige, bewusst gestaltete Bewegung wirkt und nicht wie eine Ansammlung einzelner Animationen. Verwenden, wenn eine gestaffelte Liste, ein Hero-Einstieg, ein Ansichtswechsel innerhalb eines Containers, ein mehrstufiger Ablauf, ein Element, das verschwindet, während seine Geschwister die Lücke schließen, eine Verwandlung zwischen komplexen Zuständen oder eine Interaktion mit mehreren beweglichen Teilen (Symbol + Hintergrund + Linien, Panel + …) erstellt oder repariert wird.
designdevelopment