@@ -4,7 +4,7 @@ import Link from "next/link";
44import { usePathname } from "next/navigation" ;
55import { useTranslations , useLocale } from "@/lib/i18n" ;
66import { Github , Menu , X , Sun , Moon } from "lucide-react" ;
7- import { useState } from "react" ;
7+ import { useState , useEffect } from "react" ;
88import { cn } from "@/lib/utils" ;
99
1010const NAV_ITEMS = [
@@ -24,14 +24,13 @@ export function Header() {
2424 const pathname = usePathname ( ) ;
2525 const locale = useLocale ( ) ;
2626 const [ mobileOpen , setMobileOpen ] = useState ( false ) ;
27- const [ dark , setDark ] = useState ( ( ) => {
28- if ( typeof window !== "undefined" ) {
29- const stored = localStorage . getItem ( "theme" ) ;
30- if ( stored ) return stored === "dark" ;
31- return window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ;
32- }
33- return false ;
34- } ) ;
27+ const [ dark , setDark ] = useState ( false ) ;
28+ const [ mounted , setMounted ] = useState ( false ) ;
29+
30+ useEffect ( ( ) => {
31+ setMounted ( true ) ;
32+ setDark ( document . documentElement . classList . contains ( "dark" ) ) ;
33+ } , [ ] ) ;
3534
3635 function toggleDark ( ) {
3736 const next = ! dark ;
@@ -91,7 +90,7 @@ export function Header() {
9190 onClick = { toggleDark }
9291 className = "rounded-md p-1.5 text-zinc-500 hover:text-zinc-700 dark:text-zinc-400 dark:hover:text-white"
9392 >
94- { dark ? < Sun size = { 16 } /> : < Moon size = { 16 } /> }
93+ { mounted ? ( dark ? < Sun size = { 16 } /> : < Moon size = { 16 } /> ) : < span className = "w-4 h-4 inline-block" /> }
9594 </ button >
9695
9796 < a
@@ -148,7 +147,7 @@ export function Header() {
148147 onClick = { toggleDark }
149148 className = "flex min-h-[44px] min-w-[44px] items-center justify-center rounded-md text-zinc-500 hover:text-zinc-700 dark:text-zinc-400 dark:hover:text-white"
150149 >
151- { dark ? < Sun size = { 18 } /> : < Moon size = { 18 } /> }
150+ { mounted ? ( dark ? < Sun size = { 18 } /> : < Moon size = { 18 } /> ) : < span className = "w-[18px] h-[18px] inline-block" /> }
152151 </ button >
153152 < a
154153 href = "https://github.com/shareAI-lab/learn-claude-code"
0 commit comments