From 70890231c0f765da7b993e165f10ddc203033949 Mon Sep 17 00:00:00 2001 From: scopewu Date: Sat, 14 Sep 2024 19:58:01 +0800 Subject: [PATCH] Fix theme switching failure caused because missing values --- src/components/Head.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Head.astro b/src/components/Head.astro index 3a49d548..58a86e28 100644 --- a/src/components/Head.astro +++ b/src/components/Head.astro @@ -102,7 +102,7 @@ const { title, description, image = "/nano.png" } = Astro.props; window.matchMedia("(prefers-color-scheme: dark)") .addEventListener("change", event => { - if (localStorage.theme === "system") { + if (localStorage.theme === "system" || !localStorage.theme) { toggleTheme(event.matches); } } @@ -178,4 +178,4 @@ function toggleTheme(dark) { document.addEventListener("DOMContentLoaded", () => init()); document.addEventListener("astro:after-swap", () => init()); preloadTheme(); - \ No newline at end of file +