Skip to content

Fix color mode: only persist explicit choice, follow system theme - #380

Open
Edward-Deakin wants to merge 2 commits into
mainfrom
fix/color-mode-url-theme-override
Open

Edward-Deakin wants to merge 2 commits into
mainfrom
fix/color-mode-url-theme-override

Conversation

@Edward-Deakin

Copy link
Copy Markdown
Collaborator

Problem

Auto theme switching defaulted to a stale value in `localStorage`. The provider wrote the resolved mode to `localStorage.theme` on every load, so the system `prefers-color-scheme` default (or a `?docusaurus-theme=` URL param) became a stored "choice" that overrode later system changes.

Fix (`packages/docs-ui/src/providers/ColorMode`)

  • Persist to `localStorage` only on explicit user set/toggle
  • Priority on load: URL param (this view only, not persisted) → stored explicit choice → system preference
  • Follow live `prefers-color-scheme` changes while no explicit choice is stored
  • Guard storage access with try/catch; validate stored values

Notes

  • Users who already have a `theme` value saved from the old behaviour keep it until they toggle or clear it.
  • Verified: `tsc --noEmit` clean, Prettier clean. ESLint still reports only quote/semicolon rule conflicts that also fire on the untouched file (ESLint config expects double quotes; repo Prettier uses single).
  • Not tested in a browser.

🤖 Generated with Claude Code

The resolved mode was written to localStorage on every load, freezing the
system default (or a URL param theme) into a stored choice that overrode
later system preference changes. Persist only on explicit user set/toggle,
don't persist the URL param, and follow live prefers-color-scheme changes
when no choice is stored.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Edward-Deakin
Edward-Deakin force-pushed the fix/color-mode-url-theme-override branch from 5bd1352 to 0a5b1be Compare September 21, 2026 16:55
@gitguardian

gitguardian Bot commented Nov 26, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
39294187 Triggered Generic CLI Secret 2a94475 apps/docs/content/references/pulumi.mdx View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

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