diff --git a/.changeset/short-flies-itch.md b/.changeset/short-flies-itch.md new file mode 100644 index 000000000000..929bdec522aa --- /dev/null +++ b/.changeset/short-flies-itch.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixed errorOverlay theme toggle bug. diff --git a/packages/astro/src/core/errors/overlay.ts b/packages/astro/src/core/errors/overlay.ts index 282c79cd6a21..9bfc562ba46f 100644 --- a/packages/astro/src/core/errors/overlay.ts +++ b/packages/astro/src/core/errors/overlay.ts @@ -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'; });