fix(website): hydration issues due to rendering on the server of client-side logic

This commit is contained in:
Elian Doran
2025-09-28 00:58:15 +03:00
parent bd2eb6fdbb
commit 5b673e753b
4 changed files with 22 additions and 13 deletions

View File

@@ -11,11 +11,11 @@ export function usePageTitle(title: string) {
}
export function useColorScheme() {
if (typeof window === "undefined") return;
const [ prefersDark, setPrefersDark ] = useState((window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches));
const defaultValue = (typeof window !== "undefined" && (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches));
const [ prefersDark, setPrefersDark ] = useState(defaultValue);
useEffect(() => {
if (typeof window === "undefined") return;
const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
const listener = () => setPrefersDark((window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches));