Persist theme before hydration

This commit is contained in:
wuyang6
2026-06-12 19:58:16 +08:00
parent 4a268902bf
commit 611284b27a
3 changed files with 24 additions and 3 deletions
+14
View File
@@ -0,0 +1,14 @@
(() => {
try {
const stored = window.localStorage.getItem("claw.theme");
const mode =
stored === "light" || stored === "dark" || stored === "system"
? stored
: "system";
const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;
const shouldUseDark = mode === "dark" || (mode === "system" && prefersDark);
document.documentElement.classList.toggle("dark", shouldUseDark);
} catch (_) {}
})();