Skip to content

shadcn/ui Sonner toast not showing: five causes and fixes

toast() firing with nothing on screen? Check the five causes: missing <Toaster />, wrong import, next-themes in Vite/Astro, Server Components, and CSS tokens.

Updated 3 December 2026Tested with
  • shadcn 4.23.0
  • Tailwind CSS 4.3.5
  • Vite 8
  • React 19.3
  • sonner 2.0

When you call toast("Saved") in a shadcn/ui project and nothing appears — with no console error — one of five things is wrong: <Toaster /> is missing from your root layout, sonner.tsx imports useTheme from next-themes without a provider, the wrong toast function was imported, or a modal's z-index or CSS import is hiding it.

Check these five things in order

  1. Step 1: Render <Toaster /> once in your root layout

    Running npx shadcn@latest add sonner adds components/ui/sonner.tsx, but does not mount it. Add <Toaster /> inside your root layout so it stays mounted across routes:

    app/layout.tsxTSX
    import { Toaster } from "@/components/ui/sonner"; export default function RootLayout({ children }: { children: React.ReactNode }) {  return (    <html lang="en">      <body>        {children}        <Toaster />      </body>    </html>  );}
  2. Step 2: Import toast from "sonner", not from components/ui/sonner

    components/ui/sonner.tsx only exports the themed Toaster component. The trigger function always comes from the sonner package itself:

    save-button.tsxTSX
    "use client";import { toast } from "sonner"; export function SaveButton() {  return <button onClick={() => toast.success("Changes saved")}>Save</button>;}
  3. Step 3: Vite or Astro without next-themes

    The default shadcn sonner.tsx calls useTheme() from next-themes. In a Vite or Astro project without ThemeProvider, theme can be undefined or throw at runtime. Pass a static theme (or your own hook) instead:

    src/components/ui/sonner.tsxTSX
    <Sonner theme="system" className="toaster group" {...props} />

    In Astro, remember to hydrate the island with <Toaster client:load /> — without a client:* directive, Astro renders static HTML and the toast listener never attaches.

  4. Step 4: Calling toast inside a Server Component or Server Action

    toast() only runs in the browser. Trigger it from a Client Component (with "use client" at the top) after your Server Action resolves, never inside the server function itself.

  5. Step 5: Toast renders in the DOM but is invisible or behind a Dialog

    Inspect the bottom of <body> in DevTools for <ol data-sonner-toaster>. If it exists but has transparent background or no border, your Tailwind v4 colour tokens (--popover, --popover-foreground, --border) are missing — check shadcn/ui not working with Tailwind v4. If a modal covers it, pass className="z-[100]" or render <Toaster /> after your portal container.

Questions

Should I use Sonner or the old shadcn Toast component?

Use Sonner. shadcn/ui deprecated its Radix-based toast component in favour of sonner, which needs no hook boilerplate, stacks cleanly and supports promise toasts out of the box.

Why do toasts appear twice in development?

You either mounted <Toaster /> in both a root layout and a nested layout, or called toast() directly inside a useEffect under React Strict Mode. Keep a single <Toaster /> at the root and fire toasts from event handlers.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.