diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 4ea02b81..26fcc374 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -42,7 +42,7 @@ export default async function RootLayout({ children }: { children: ReactNode }) {/* Apply the saved/default theme before first paint to avoid a flash. */} diff --git a/src/components/navbar-color-picker.tsx b/src/components/navbar-color-picker.tsx index 42b99f8e..ff252948 100644 --- a/src/components/navbar-color-picker.tsx +++ b/src/components/navbar-color-picker.tsx @@ -22,12 +22,8 @@ const COLORS = [ export function NavbarColorPicker() { const [open, setOpen] = useState(false); - const [active, setActive] = useState(() => { - if (typeof document === "undefined") return 0; - const current = getComputedStyle(document.documentElement).getPropertyValue("--color-navbar").trim(); - const idx = COLORS.findIndex((c) => c.value === current); - return idx >= 0 ? idx : 0; - }); + const [active, setActive] = useState(0); + const [mounted, setMounted] = useState(false); function apply(index: number) { const c = COLORS[index]; @@ -45,12 +41,15 @@ export function NavbarColorPicker() { useEffect(() => { const saved = localStorage.getItem("navbarColor"); const savedText = localStorage.getItem("navbarTextColor"); - if (saved && savedText) { - document.documentElement.style.setProperty("--color-navbar", saved); - document.documentElement.style.setProperty("--color-navbar-text", savedText); + if (saved) { const idx = COLORS.findIndex((c) => c.value === saved); if (idx >= 0) setActive(idx); + document.documentElement.style.setProperty("--color-navbar", saved); } + if (savedText) { + document.documentElement.style.setProperty("--color-navbar-text", savedText); + } + setMounted(true); }, []); return ( @@ -71,7 +70,7 @@ export function NavbarColorPicker() { - {open && ( + {mounted && open && (