Let the server set the theme based on the cookie sent at request time, which should stop flashing

This commit is contained in:
2025-10-17 13:39:25 +01:00
parent 8e687fe176
commit 052b14ca40
4 changed files with 28 additions and 24 deletions

View File

@@ -25,13 +25,13 @@ export default function ThemeDropdown() {
const apply = useCallback((t: Theme) => {
const effective = t === "auto" ? (prefersDark() ? "dark" : "light") : t;
document.documentElement.setAttribute("data-bs-theme", effective);
}, []);
useEffect(() => {
setMounted(true);
const v = getCookie(COOKIE);
console.log("Cookie:", v);
const initial: Theme = v === "light" || v === "dark" || v === "auto" ? (v as Theme) : "auto";
setTheme(initial);
// Important: apply immediately so “auto” reflects system after hydration