Skip to content

fix: respect system dark mode preference in ThemeToggle - #588

Merged
gopaljilab merged 3 commits into
gopaljilab:mainfrom
nyxsky404:fix/theme-toggle-system-preference
Jun 2, 2026
Merged

gopaljilab merged 3 commits into
gopaljilab:mainfrom
nyxsky404:fix/theme-toggle-system-preference

Conversation

@nyxsky404

@nyxsky404 nyxsky404 commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Updates the ThemeToggle component to respect the user's operating system dark mode preference (prefers-color-scheme: dark) when no explicit theme choice is saved in localStorage. Previously, first-time visitors with dark mode enabled at the OS level would always see the light theme.

Related Issue

Fixes #579

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Style / UI improvement
  • ♻️ Refactor (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update
  • 🔧 Chore / Tooling / Config

Changes Made

  • Added fallback to window.matchMedia('(prefers-color-scheme: dark)').matches when no localStorage theme value exists
  • Existing behavior preserved: if user has explicitly toggled the theme, their choice is still respected

Testing

  • I have tested these changes locally
  • All existing tests pass

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have updated the documentation if needed

@github-actions github-actions Bot added gssoc:approved level:intermediate Requires standard familiarity with the codebase. type:bug Something isn't working or throwing errors. labels Jun 2, 2026
@gopaljilab
gopaljilab merged commit f42d796 into gopaljilab:main Jun 2, 2026
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved level:intermediate Requires standard familiarity with the codebase. type:bug Something isn't working or throwing errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ThemeToggle ignores system dark mode preference (prefers-color-scheme)

2 participants