File tree Expand file tree Collapse file tree 1 file changed +19
-20
lines changed
Expand file tree Collapse file tree 1 file changed +19
-20
lines changed Original file line number Diff line number Diff line change @@ -7,28 +7,27 @@ import {
77} from "~/lib/constants"
88
99export const ColorSchemeInjector = ( ) => {
10+ const scriptContent = `
11+ (() => {
12+ const STORAGE_KEY = "${ DARK_MODE_STORAGE_KEY } ";
13+ const storedValue = localStorage.getItem(STORAGE_KEY);
14+
15+ // Determine color scheme
16+ if (storedValue === null || storedValue === undefined) {
17+ const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
18+ const colorScheme = prefersDark ? "${ COLOR_SCHEME_DARK } " : "${ COLOR_SCHEME_LIGHT } ";
19+ document.documentElement.classList.add(colorScheme);
20+ } else {
21+ const isDark = storedValue === "true";
22+ document.documentElement.classList.add(isDark ? "${ COLOR_SCHEME_DARK } " : "${ COLOR_SCHEME_LIGHT } ");
23+ }
24+ })();
25+ ` . trim ( )
26+
1027 return (
1128 < script
1229 suppressHydrationWarning
13- dangerouslySetInnerHTML = { {
14- __html : `(() => {
15- let DARK_MODE_STORAGE_KEY = "${ DARK_MODE_STORAGE_KEY } ";
16-
17- let data = {}
18- const isDark = localStorage.getItem(DARK_MODE_STORAGE_KEY)
19- if (typeof isDark === "undefined") {
20- const currentColorScheme = window.matchMedia("(prefers-color-scheme: dark)")
21- .matches
22- ? "${ COLOR_SCHEME_DARK } "
23- : "${ COLOR_SCHEME_LIGHT } "
24- document.documentElement.classList.add(currentColorScheme)
25- } else {
26- document.documentElement.classList.add(
27- isDark === "true" ? "${ COLOR_SCHEME_DARK } " : "${ COLOR_SCHEME_LIGHT } ",
28- )
29- }
30- })();` ,
31- } }
32- > </ script >
30+ dangerouslySetInnerHTML = { { __html : scriptContent } }
31+ />
3332 )
3433}
You can’t perform that action at this time.
0 commit comments