diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f615869..07da032 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -14,9 +14,24 @@ export default function RootLayout({ }: Readonly<{ children: React.ReactNode; }>) { + const initDarkModeDetection = ` +(function () { +const isDarkModePreferred = window.matchMedia('(prefers-color-scheme: dark)').matches; +const themeChosen = localStorage.theme; +if ((!themeChosen && isDarkModePreferred) || themeChosen === "dark") { + document.documentElement.classList.add("dark"); + localStorage.theme = 'dark'; +} +})()`; + return (
+ (null); useEffect(() => { - if ( - localStorage.theme === "dark" || - (!("theme" in localStorage) && - window.matchMedia("(prefers-color-scheme: dark)").matches) - ) { - document.documentElement.classList.add("dark"); + if (localStorage.theme === "dark") { setDarkMode(true); - } else { - document.documentElement.classList.remove("dark"); - setDarkMode(false); } + }, []); + useEffect(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 0); };