feat: system-aware color mode with browser-mode tests#2
Merged
Conversation
useColorMode and the inline pre-paint script now resolve "system" against the OS prefers-color-scheme, and the hook tracks OS changes live while in system mode. Previously "system" always rendered light because the apply step only checked for an explicit "dark" value. Add functional tests under test/functional that run in a real browser via Vitest Browser Mode + Playwright, covering both entry points: the npm hook (src/index.ts) and the inline IIFE script (src/initial.ts). Set up project tooling (Biome, tsdown lib + IIFE build, tsconfig, Vitest browser config, CI workflows) and document usage, styling, and the window.__COLOR_MODE__ runtime contract in the README. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Install Chromium via `playwright install --with-deps` before the test step so the browser-mode functional suite can run in CI. Switch the release workflow trigger from pull_request events to push on main. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Preview releaseLatest commit: Some packages have been released:
Note Use the PR number as tag to install any package. For instance: |
useColorMode now returns { colorMode, setColorMode } instead of
{ mode, setMode }. Update the hook internals, the functional tests, and
the README usage example accordingly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 3eeea85 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
systemmode now follows the OS. BothuseColorMode(src/index.ts) and the inline pre-paint script (src/initial.ts) resolvesystemagainstmatchMedia("(prefers-color-scheme: dark)"). The hook also tracks OS changes live while insystemmode. Previouslysystemalways rendered light, because the apply step only checked for an explicitdarkvalue and fell through to removing the class otherwise.test/functionalruns via Vitest Browser Mode + Playwright (headless Chromium), covering both entry points: the npm hook and the inline IIFE script.window.__COLOR_MODE__runtime contract.The bug
A user on
systemwith an OS dark preference saw the light theme. The same gap existed ininitial.tsfor a persistedsystemvalue (thematchMediabranch only ran on first visit). Both sites now resolvesystemviaprefers-color-scheme.Note: the inline script's first-visit default is now
system(resolved against the OS) instead of baking a concretedark/lightinto storage — sosystemkeeps following the OS over time.Tests
localStorage, invalid-value fallback +console.error,setModeside effects (class /localStorage/CustomEvent), andsystemfollowing the OS both statically and on a live change.system+ OS dark→dark / light, first-visit defaults, unavailable media query, and thewindow.__COLOR_MODE__contract. The side-effectful module is re-evaluated per case via a cache-busting dynamic import (vi.resetModules()does not re-run native modules in Browser Mode).Run locally with
pnpm test.🤖 Generated with Claude Code