From 195c4e5ef457e79596207644cd95e8180097da3b Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Fri, 6 Feb 2026 16:49:16 +0000 Subject: [PATCH] fix(ui): follow OS dark/light mode changes after manual toggle Only persist theme to localStorage when the user's choice differs from the OS preference. Clear it when they match so the prefers-color-scheme listener remains active and automatically tracks system theme changes. --- templates/partials/nav.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/partials/nav.html b/templates/partials/nav.html index da3179e..be093af 100644 --- a/templates/partials/nav.html +++ b/templates/partials/nav.html @@ -48,12 +48,16 @@ const toggleTheme = () => { const html = document.documentElement; const isDark = html.getAttribute("data-theme") === "dark"; + const osDark = matchMedia("(prefers-color-scheme: dark)").matches; if (isDark) { html.removeAttribute("data-theme"); - localStorage.setItem("theme", "light"); + // Only persist if this choice differs from OS preference + if (osDark) localStorage.setItem("theme", "light"); + else localStorage.removeItem("theme"); } else { html.setAttribute("data-theme", "dark"); - localStorage.setItem("theme", "dark"); + if (!osDark) localStorage.setItem("theme", "dark"); + else localStorage.removeItem("theme"); } updateThemeIcons(); };