Skip to content

Commit

Permalink
fix: Fixed errorOverlay theme toggle bug. (#10661)
Browse files Browse the repository at this point in the history
* fix: save `localStorage.astroErrorOverlayTheme` when detected dark mode

* add  changeset

* Fix theme toggle in ErrorOverlay

* update  changeset
  • Loading branch information
liruifengv authored Apr 10, 2024
1 parent 0fec72b commit e2cd7f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/short-flies-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixed errorOverlay theme toggle bug.
3 changes: 2 additions & 1 deletion packages/astro/src/core/errors/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,14 @@ class ErrorOverlay extends HTMLElement {
window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
this?.classList.add('astro-dark');
localStorage.astroErrorOverlayTheme = 'dark';
themeToggle!.checked = true;
} else {
this?.classList.remove('astro-dark');
themeToggle!.checked = false;
}
themeToggle?.addEventListener('click', () => {
const isDark = localStorage.astroErrorOverlayTheme === 'dark';
const isDark = localStorage.astroErrorOverlayTheme === 'dark' || this?.classList.contains('astro-dark');
this?.classList.toggle('astro-dark', !isDark);
localStorage.astroErrorOverlayTheme = isDark ? 'light' : 'dark';
});
Expand Down

0 comments on commit e2cd7f4

Please sign in to comment.