Let the server set the theme based on the cookie sent at request time, which should stop flashing
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user