0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix: Fixed errorOverlay theme toggle bug. (#10661)

* fix: save `localStorage.astroErrorOverlayTheme` when detected dark mode

* add  changeset

* Fix theme toggle in ErrorOverlay

* update  changeset
This commit is contained in:
liruifengv 2024-04-10 18:58:19 +08:00 committed by GitHub
parent 0fec72b35c
commit e2cd7f4291
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fixed errorOverlay theme toggle bug.

View file

@ -593,13 +593,14 @@ class ErrorOverlay extends HTMLElement {
window.matchMedia('(prefers-color-scheme: dark)').matches) window.matchMedia('(prefers-color-scheme: dark)').matches)
) { ) {
this?.classList.add('astro-dark'); this?.classList.add('astro-dark');
localStorage.astroErrorOverlayTheme = 'dark';
themeToggle!.checked = true; themeToggle!.checked = true;
} else { } else {
this?.classList.remove('astro-dark'); this?.classList.remove('astro-dark');
themeToggle!.checked = false; themeToggle!.checked = false;
} }
themeToggle?.addEventListener('click', () => { themeToggle?.addEventListener('click', () => {
const isDark = localStorage.astroErrorOverlayTheme === 'dark'; const isDark = localStorage.astroErrorOverlayTheme === 'dark' || this?.classList.contains('astro-dark');
this?.classList.toggle('astro-dark', !isDark); this?.classList.toggle('astro-dark', !isDark);
localStorage.astroErrorOverlayTheme = isDark ? 'light' : 'dark'; localStorage.astroErrorOverlayTheme = isDark ? 'light' : 'dark';
}); });