Skip to content

Commit 8661051

Browse files
committed
fix: detemine theme in localstorage on first time visit
fixes themetoggle button being the wrong one on first time visit with a (prefers-color-scheme: dark) browser setting
1 parent b44523c commit 8661051

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
<title>jumpyjacko | Home</title>
88

99
<script>
10-
document.documentElement.classList.toggle(
11-
"dark",
12-
localStorage.theme === "dark" ||
13-
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches),
14-
);
10+
if (
11+
!("theme" in localStorage) &&
12+
window.matchMedia("(prefers-color-scheme: dark)")
13+
) {
14+
localStorage.theme = "dark";
15+
}
1516
</script>
1617
</head>
1718
<body class="bg-cream text-midnight dark:bg-midnight dark:text-cream">

0 commit comments

Comments
 (0)