ask-sonner

작성자: emilkowalski

Sonner(React 토스트 라이브러리) 사용 가이드 — Toaster 설치 및 연결, 올바른 toast() 호출 선택, promise 및 로딩 토스트, 토스트 업데이트·해제·유지, 스타일링, 테마 및 아이콘, 위치 지정 및 다중 toaster 설정. Sonner로 작업하거나 문제를 해결할 때 사용 — 토스트가 표시되지 않거나, 두 번 표시되거나, 스타일이 사라지거나, Tailwind 클래스를 무시하거나, 모달 뒤에 위치하거나, 다크 모드를 따르지 않는 경우.

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

Working With Sonner

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 mounted Toaster 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 }. Dismisstoast.dismiss(id), or toast.dismiss() for all. Read active toastsuseSonner() in React, toast.getActiveToasts() 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' }). Without toasterId, every toaster renders the toast.

Close callbacksonDismiss fires on close button or swipe; 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; jumping to the top rung too early is fine (it's the recommended end state), lingering in the middle is not.

  1. Defaults — plus richColors on the Toaster for colorful success/error, invert to flip against the theme.
  2. Inline tweakstoastOptions={{ style: {…} }} on the Toaster for all toasts, or style per toast() call.
  3. Classes on partstoastOptions={{ 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. Headlesstoast.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.

Themetheme 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, 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, dismissible: false, 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 32px) and mobileOffset (<600px, default 16px) — numbers, CSS strings, or per-side objects.

emilkowalski의 다른 스킬

find-animation-opportunities
emilkowalski
코드베이스나 UI에서 애니메이션이 있어야 하지만 없는 곳을 검색하고, 있으면 안 되는 모든 것은 거부합니다. 읽기 전용이며, 정확한 값으로 모션을 제안할 뿐 구현하지는 않습니다. 사용자가 "여기서 무엇을 애니메이션할 수 있을까?"라고 묻거나 "이것을 더 생동감 있게 만들고 싶다"고 할 때 사용하세요. 기존 애니메이션 수정은 improve-animations 또는 review-animations를 대신 사용하세요.
developmentdesigncreative
animate
emilkowalski
애니메이션을 처음부터 구축하되, 그것이 자연스럽게 느껴지는지를 결정하는 순서대로 판단을 내린다 — 애니메이션을 적용할지 여부, 목적, 도구, 속성, 곡선과 지속 시간, 인터럽트 방식, 종료 방식을 결정한다. 구현을 작성한다. 무언가를 애니메이션으로 만들고, 모션을 추가하고, 컴포넌트에 생동감을 부여하거나, 전환을 구축하라는 요청이 있을 때 사용한다. 기존 모션을 비평할 때는 review-animations를 사용하고, 전체 코드베이스를 감사할 때는 improve-animations를 사용한다.
pick-ui-library
emilkowalski
주어진 프론트엔드 작업에 적합한 라이브러리를 선별된 의견 기반 목록에서 고릅니다 — 숫자, OTP 입력, 차트, 명령 메뉴, 가상화, 드래그 앤 드롭, 토스트, 상태, 스타일링 등. 명시적으로 호출될 때만 실행되며, 자체적으로 트리거되지 않습니다.
prototype
emilkowalski
설명하는 UI 요소의 서로 다른 여러 버전을 만들고, 시각적 선택기 뒤에 렌더링하여 실시간으로 넘겨보며 마음에 드는 버전을 선택할 수 있게 합니다. 명시적으로 호출될 때만 실행되며, 자체적으로 트리거되지 않습니다.
developmentdesigncreative
emil-design-eng
emilkowalski
이 스킬은 Emil Kowalski의 UI 폴리시, 컴포넌트 디자인, 애니메이션 결정, 그리고 소프트웨어를 훌륭하게 만드는 보이지 않는 세부 사항에 대한 철학을 인코딩합니다.
designdevelopmentcreative
review-animations
emilkowalski
에밀 코왈스키의 디자인 엔지니어링 철학에서 비롯된 높은 장인 기준에 따라 애니메이션 및 모션 코드를 검토합니다. 기본적으로 플래그를 지정하며, 승인은 획득해야 합니다.
animation-vocabulary
emilkowalski
웹 애니메이션이나 모션 효과에 대한 모호한 설명을 정확한 용어로 바꿔주는 역방향 검색 용어집입니다("팝오버가 열릴 때 통통 튀는 효과" → Pop in; "iOS 고무줄 스크롤" → Rubber-banding). 사용자가 "이런 걸 뭐라고 부르죠?"라고 묻거나, 모션 효과의 이름을 모르고 설명만 하면서 AI나 디자이너에게 지시할 정확한 단어를 원할 때 사용합니다. 효과의 이름을 찾는 용도이며, 설계나 구현을 위한 것이 아닙니다.
creativedesignresearch
improve-animations
emilkowalski
코드베이스의 애니메이션 및 모션 코드를 시니어 모션 어드바이저로서 조사한 후, 우선순위가 매겨진 감사 보고서와 다른 에이전트(또는 저렴한 모델)가 실행할 수 있는 자체 포함된 구현 계획을 생성합니다. 소스 코드는 읽기 전용이며 개선 계획을 수립할 뿐 적용하지는 않습니다. 사용자가 "애니메이션 개선", "모션 감사", "이 앱의 느낌 개선"을 요청하거나 단일 diff 검토가 아닌 애니메이션 수정 로드맵을 원할 때 사용하세요.