Skip to content

[Repo Assist] Migrate theme colors to CSS light-dark() function#1059

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-css-light-dark-colors-1004-da3d063179db6e97
Draft

[Repo Assist] Migrate theme colors to CSS light-dark() function#1059
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-css-light-dark-colors-1004-da3d063179db6e97

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 1, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #1004

As requested by @nojaf in #1004.

Summary

Migrates all theme color variables from a separate [data-theme=dark] override block to CSS light-dark(light-value, dark-value) syntax in :root. This is a clean, self-contained refactor that:

  • Reduces the CSS size by ~50 lines
  • Makes color intent explicit at the point of declaration (both values in one place)
  • Automatically honours prefers-color-scheme without any JS when no user preference is saved

Changes

docs/content/fsdocs-default.css

  • Add color-scheme: light dark; to :root so the browser knows the page supports both schemes
  • Replace 25 color variables that differed between light and dark with light-dark(light-val, dark-val) inline
  • Remove the 43-variable [data-theme=dark] override block; replace with a minimal:
    [data-theme=dark] { color-scheme: dark; }
    [data-theme=light] { color-scheme: light; }
    The color-scheme property on the root element drives light-dark() resolution throughout the page.
  • Keep the existing [data-theme=dark] { ::backdrop { opacity: 0.75 } } rule unchanged (non-color properties can't use light-dark())

docs/content/fsdocs-theme-set-dark.js

Simplify the early-load script:

  • Before: Read localStorage + matchMedia("@media (prefers-color-scheme: dark)") (the @media prefix was actually a bug; matchMedia doesn't use it), then only set data-theme=dark for dark preference
  • After: If localStorage has a saved preference, set data-theme to that value. If no preference, do nothing — CSS light-dark() with color-scheme: light dark will automatically follow the OS preference with zero JS overhead.

RELEASE_NOTES.md

Added entry under ## [Unreleased] / ### Changed.

Behaviour

Scenario Before After
User has no saved preference, OS is light :root — light colours :root with color-scheme: light darklight-dark() resolves to light ✅
User has no saved preference, OS is dark JS reads media query → sets data-theme=dark → dark colours CSS light-dark() resolves to dark automatically ✅ (no JS needed)
User explicitly chose dark data-theme=dark set → CSS overrides data-theme=dark set → color-scheme: darklight-dark() resolves to dark ✅
User explicitly chose light, OS is dark data-theme not set (only dark was set) → light colours data-theme=light set → color-scheme: lightlight-dark() resolves to light ✅

The last row is actually an improvement: previously if a user explicitly saved 'light' theme but their OS switched to dark, the old code wouldn't set data-theme at all, which with light-dark() would have defaulted to OS dark. The new code sets data-theme=light explicitly, overriding the OS preference as intended.

Test Status

This is a CSS and minor JS change with no F# code impact.

  • ✅ No build artefacts changed
  • ✅ Visual verification needed: test light/dark toggle, system preference, and localStorage persistence

Generated by Repo Assist for issue #1004

Generated by Repo Assist

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@da02dddebe71d9a937665abdcd1f5214dab852a7

Replace the separate [data-theme=dark] block of variable overrides with
light-dark(light-val, dark-val) syntax in :root, so the browser resolves
colors automatically based on the active color-scheme.

- Add color-scheme: light dark to :root (enabling automatic system-preference
  following when no explicit theme is chosen)
- Replace 25 color variables that differed between light/dark with light-dark()
- Reduce [data-theme=dark] to only color-scheme: dark (activates dark values)
- Add [data-theme=light] { color-scheme: light } to support explicit light
  override when OS is dark
- Simplify fsdocs-theme-set-dark.js: apply saved localStorage preference early
  (removes the now-redundant prefers-color-scheme JS check, since CSS handles
  the system default automatically)
- Keep [data-theme=dark] ::backdrop rule unchanged (opacity cannot use light-dark())

Closes #1004

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve theme with light-dark()

0 participants