From add2317717448da42db20162fe49782baf5c2ecb Mon Sep 17 00:00:00 2001 From: kovakmedya Date: Thu, 30 Apr 2026 05:52:08 +0300 Subject: [PATCH] fix(ui): add 'use client' to sonner Toaster and chart components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both files use client-only hooks (useTheme in sonner; useState/useMemo/ useId in chart via React) but the shadcn CLI shipped them without the 'use client' directive. Mounting in the root server layout crashed in production with: Attempted to call useTheme() from the server but useTheme is on the client. Same risk on chart.tsx once any dashboard page renders . Verified all of src/components/ui/*.tsx — only these two needed the fix. Future shadcn additions: check 'head -1' for the directive before importing into server components. --- src/components/ui/chart.tsx | 2 ++ src/components/ui/sonner.tsx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/components/ui/chart.tsx b/src/components/ui/chart.tsx index e4589f0..97cc280 100644 --- a/src/components/ui/chart.tsx +++ b/src/components/ui/chart.tsx @@ -1,3 +1,5 @@ +"use client" + import * as React from "react" import * as RechartsPrimitive from "recharts" diff --git a/src/components/ui/sonner.tsx b/src/components/ui/sonner.tsx index 33d2d2a..b301ece 100644 --- a/src/components/ui/sonner.tsx +++ b/src/components/ui/sonner.tsx @@ -1,3 +1,5 @@ +"use client" + import { useTheme } from "next-themes" import { Toaster as Sonner, type ToasterProps } from "sonner"