Skip to content

Commit 2b3c8bc

Browse files
authored
fix: Sync favicon to browser theme preference on initial load (#11518)
## Summary - Fixes favicon always showing the dark variant regardless of browser theme preference on non-docs routes - The `useColorScheme` hook now syncs the initial value on mount, since SSR defaults to "light" and React preserves that state during hydration The `useEffect` previously only listened for **changes** to `prefers-color-scheme`, but never set the correct value after hydration when the browser was already in dark mode.
1 parent 362e09d commit 2b3c8bc

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

docs/site/components/use-color-scheme.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export function useColorScheme(): ColorScheme {
2121

2222
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
2323

24+
// Set initial value on mount (SSR defaults to "light", so we need to sync)
25+
setColorScheme(mediaQuery.matches ? "dark" : "light");
26+
2427
const handleChange = (event: MediaQueryListEvent): void => {
2528
setColorScheme(event.matches ? "dark" : "light");
2629
};

0 commit comments

Comments
 (0)