Skip to content

fix: fixes theme management when page reloads due to navigation - #2

Open
edfrias wants to merge 1 commit into
midudev:mainfrom
edfrias:main
Open

fix: fixes theme management when page reloads due to navigation #2
edfrias wants to merge 1 commit into
midudev:mainfrom
edfrias:main

Conversation

@edfrias

@edfrias edfrias commented Jul 23, 2026

Copy link
Copy Markdown

What changed

Improves light/dark theme handling in the global layout.

  • Fixes initial page load and Astro internal navigation behavior where the preference could be lost or rendered incorrectly.
  • Reads localStorage from HTML and immediately applies it to document.documentElement.dataset.theme and document.documentElement.style.colorScheme.
  • Synchronizes the theme toggle so its aria-label always matches the current theme action.
  • Reapplies the theme on Astro events (astro:before-swap, astro:after-swap, astro:page-load) to avoid flashes and preserve the user’s choice across route changes.

Official sources used to verify

Visual impact

Ensures the selected theme stays consistent across reloads and transitions, and the UI no longer briefly reverts to the wrong theme during navigation.

Checks run

  • pnpm check
  • pnpm build

@edfrias edfrias changed the title feat: enhance theme management with improved local storage handling fix: enhance theme management with improved local storage handling Jul 29, 2026
@edfrias edfrias changed the title fix: enhance theme management with improved local storage handling fix: fixes theme management when page reloads due to navigation Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant