From 280a5843848eea4bfb4ecefe82f83ed02cdf7fe8 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 22 Feb 2024 11:48:56 -0800 Subject: [PATCH] Check actual `.matches` result with `matchMedia` calls Fixes #211 --- src/partials/head-styles.hbs | 2 +- src/partials/header-content.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/partials/head-styles.hbs b/src/partials/head-styles.hbs index 72cc7e5..e731b64 100644 --- a/src/partials/head-styles.hbs +++ b/src/partials/head-styles.hbs @@ -2,7 +2,7 @@ !function (theme, navWidth) { if (theme === 'dark') document.documentElement.classList.add('dark-theme') if (navWidth) document.documentElement.style.setProperty('--nav-width', `${navWidth}px`) -}(localStorage && localStorage.getItem('theme') || (matchMedia('(prefers-color-scheme: dark)') && 'dark'), +}(localStorage && localStorage.getItem('theme') || (matchMedia('(prefers-color-scheme: dark)')?.matches && 'dark'), localStorage && localStorage.getItem('nav-width')) diff --git a/src/partials/header-content.hbs b/src/partials/header-content.hbs index 43c6a5c..15f70b4 100644 --- a/src/partials/header-content.hbs +++ b/src/partials/header-content.hbs @@ -216,5 +216,5 @@ if (theme === 'dark') { document.getElementById('switch-theme-checkbox').parentElement.classList.add('active') } -}(localStorage && localStorage.getItem('theme') || (matchMedia('(prefers-color-scheme: dark)') && 'dark')) +}(localStorage && localStorage.getItem('theme') || (matchMedia('(prefers-color-scheme: dark)')?.matches && 'dark'))