From 758cb39baf42a45492ccbe89aa874b4622440138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olle=20M=C3=A5nsson?= <31876997+ollema@users.noreply.github.com> Date: Mon, 12 Feb 2024 00:58:00 +0100 Subject: [PATCH] fix: localStorage key (#51) --- .changeset/green-panthers-bow.md | 5 +++++ src/lib/mode.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/green-panthers-bow.md diff --git a/.changeset/green-panthers-bow.md b/.changeset/green-panthers-bow.md new file mode 100644 index 0000000..9caa092 --- /dev/null +++ b/.changeset/green-panthers-bow.md @@ -0,0 +1,5 @@ +--- +'mode-watcher': patch +--- + +Fix incorrect localStorage key diff --git a/src/lib/mode.ts b/src/lib/mode.ts index 5f161cf..68d9eb4 100644 --- a/src/lib/mode.ts +++ b/src/lib/mode.ts @@ -23,6 +23,7 @@ export function resetMode(): void { userPrefersMode.set('system'); } +/** Used to set the mode on initial page load to prevent FOUC */ export function setInitialMode(defaultMode: Mode, themeColors?: ThemeColors) { const rootEl = document.documentElement; const mode = localStorage.getItem('mode-watcher-mode') || defaultMode; @@ -40,7 +41,7 @@ export function setInitialMode(defaultMode: Mode, themeColors?: ThemeColors) { } } - localStorage.setItem('mode', mode); + localStorage.setItem('mode-watcher-mode', mode); } export { localStorageKey, userPrefersMode, systemPrefersMode, derivedMode as mode, themeColors };