Skip to content

Commit e2cd7f4

Browse files
authored
fix: Fixed errorOverlay theme toggle bug. (#10661)
* fix: save `localStorage.astroErrorOverlayTheme` when detected dark mode * add changeset * Fix theme toggle in ErrorOverlay * update changeset
1 parent 0fec72b commit e2cd7f4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/short-flies-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Fixed errorOverlay theme toggle bug.

packages/astro/src/core/errors/overlay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,14 @@ class ErrorOverlay extends HTMLElement {
593593
window.matchMedia('(prefers-color-scheme: dark)').matches)
594594
) {
595595
this?.classList.add('astro-dark');
596+
localStorage.astroErrorOverlayTheme = 'dark';
596597
themeToggle!.checked = true;
597598
} else {
598599
this?.classList.remove('astro-dark');
599600
themeToggle!.checked = false;
600601
}
601602
themeToggle?.addEventListener('click', () => {
602-
const isDark = localStorage.astroErrorOverlayTheme === 'dark';
603+
const isDark = localStorage.astroErrorOverlayTheme === 'dark' || this?.classList.contains('astro-dark');
603604
this?.classList.toggle('astro-dark', !isDark);
604605
localStorage.astroErrorOverlayTheme = isDark ? 'light' : 'dark';
605606
});

0 commit comments

Comments
 (0)