diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 5a71206..d5a47fa 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -2,9 +2,31 @@ import "./globals.css"; export const metadata = { title: "Mercury" }; +// Runs before paint (in , ahead of hydration) to set the Seed +// color-mode attribute from the persisted preference, avoiding a +// flash-of-incorrect-theme: the server always renders "system" (no +// localStorage access during SSR), so without this the client would briefly +// paint light/system before this script could run post-hydration. +const THEME_INIT_SCRIPT = ` +(function () { + try { + var v = localStorage.getItem("mercury.theme"); + var mode = v === "light" ? "light-only" : v === "dark" ? "dark-only" : "system"; + document.documentElement.setAttribute("data-seed-color-mode", mode); + } catch (e) {} +})(); +`; + export default function RootLayout({ children }: { children: React.ReactNode }) { return ( - + // suppressHydrationWarning: the inline script below intentionally + // rewrites data-seed-color-mode before hydration (to the persisted + // preference), so it will legitimately differ from this "system" + // server-rendered value — React should not warn about or "fix" that. + + +