Skip to content

Commit 24d9da6

Browse files
Rotate localStorage key for color scheme
1 parent fb0a78c commit 24d9da6

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default async function RootLayout({
115115
dangerouslySetInnerHTML={{
116116
__html: js`
117117
try {
118-
_updateTheme(localStorage.theme)
118+
_updateTheme(localStorage.currentTheme)
119119
} catch (_) {}
120120
121121
try {
@@ -175,7 +175,7 @@ export default async function RootLayout({
175175
);
176176
}
177177

178-
const FAVICON_VERSION = 3;
178+
const FAVICON_VERSION = 4;
179179
function v(href: string) {
180180
return `${href}?v=${FAVICON_VERSION}`;
181181
}

src/components/theme-toggle.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) {
1717
let [theme, setTheme] = useState<Theme>(null);
1818

1919
useEffect(() => {
20-
setTheme((localStorage.getItem("theme") ?? "system") as Theme);
20+
setTheme((localStorage.getItem("currentTheme") ?? "system") as Theme);
2121
}, []);
2222

2323
let themeValue = useMemo(() => ({ theme, setTheme }), [theme]);
@@ -27,9 +27,9 @@ export function ThemeProvider({ children }: { children: React.ReactNode }) {
2727

2828
function onChange(theme: Theme, setTheme: (theme: Theme) => void) {
2929
if (theme !== null) {
30-
localStorage.setItem("theme", theme);
30+
localStorage.setItem("currentTheme", theme);
3131
} else {
32-
localStorage.removeItem("theme");
32+
localStorage.removeItem("currentTheme");
3333
}
3434
(window as any)._updateTheme(theme);
3535
setTheme(theme);

src/docs/dark-mode.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ Here's a simple example of how you can support light mode, dark mode, as well as
174174
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
175175
document.documentElement.classList.toggle(
176176
"dark",
177-
localStorage.theme === "dark" ||
177+
localStorage.currentTheme === "dark" ||
178178
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches),
179179
);
180180

181181
// Whenever the user explicitly chooses light mode
182-
localStorage.theme = "light";
182+
localStorage.currentTheme = "light";
183183

184184
// Whenever the user explicitly chooses dark mode
185-
localStorage.theme = "dark";
185+
localStorage.currentTheme = "dark";
186186

187187
// Whenever the user explicitly chooses to respect the OS preference
188188
localStorage.removeItem("theme");

0 commit comments

Comments
 (0)