Skip to content

feat(theme): restore dark resolution behind a flag, and give the smoke pass its dark run (#833) - #954

Merged
thinkclay merged 1 commit into
mainfrom
feat/833-dark-mode
Oct 2, 2026
Merged

thinkclay merged 1 commit into
mainfrom
feat/833-dark-mode

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Part 1 of #833. #840 is part 2: fix what the audit found and remove the gate.

Dark mode had been off since 78caa00 (2026-04-21) because of one line in useThemeSetting:

const resolvedTheme = 'light' as 'light' | 'dark'

Everything else already worked. The provider resolves a preference, persists it, stamps data-theme on <html>, and bridges to @scaffald/ui's ThemeProvider as a controlled prop — so that single line governed the entire app's theme.

What lands

  • provider/theme/dark-mode-flag.ts — isDarkModeEnabled() reads EXPO_PUBLIC_DARK_MODE === '1'; resolveThemePreference() does the resolution. Split out so it is testable without React: the line that was wrong for five months had no test on it. 10 tests.
  • useRootTheme had the same resolution open-coded, and was never gated — it could already return a dark theme while the hook returned light. Both now go through the one helper.
  • The resolution returns 'light' for anything unresolvable. The commented-out line it replaces fell back to context.current ?? 'system', which could hand 'system' back as a resolved theme. There is no colors.bg.system, so the first token lookup would have read undefined.
  • DrawerFooter's toggle is restored, rendering only when the flag is on — a toggle that renders while resolution is gated is a control that visibly does nothing.
  • smoke-authed.mjs --scheme light|dark|both, and the theme assertion it was written with is now an exit code rather than a line in the summary.

Why an env flag and not __DEV__

__DEV__ is false in release builds, so it would be safe. But it would also flip every developer's app to follow their OS appearance from the next pnpm web, and a half-audited palette is a bad thing to meet by surprise during unrelated work. One line in .env makes "am I looking at dark on purpose?" answerable.

Verified against the running app

By computed background colour, not by eye, on a freshly wiped Metro cache for each case:

flag stored preference OS prefers rendered data-theme body background
on system dark dark dark rgb(22,17,13) — bg.dark.default
on light dark light light rgb(255,255,255)
off system dark light light rgb(255,255,255)

The last row is the one that matters: production stays light even with a dark OS and a stored dark preference.

The cache wipe is not incidental. My first off-run reported dark and looked like a broken gate. Both dev servers share one Metro cache, env changes don't bust it, and the off-server was handed the flagged bundle. Wiping between runs is required, and the smoke script now says so where someone will hit it.

The --scheme parsing and the theme-assertion logic are exercised directly rather than eyeballed — a dark pass that renders light produces wrong: ["desktop-dark/light"] and a non-zero exit.

The token audit — 3 findings filed

Scored all 320 foreground/background token pairs with the WCAG 2.1 formula, in both themes, so a pair that already fails in light is not reported as a dark-mode finding. 17 fail in dark and pass in light.

The audit script is in the issue bodies' reach; it reads colors.ts directly so it can be re-run after any token change.

What is not done, and why

Two of the three acceptance boxes need an authenticated session, which needs a local Supabase, which needs Docker — not running on this machine.

  • Flag-gated resolution, verified by computed background colour — done, table above.
  • smoke-authed.mjs --scheme dark produces captures whose data-theme reads dark — implemented, not run. The code path is exercised; the pass itself needs the stack.
  • A dark capture of every screen touched in sprints 1–2, with per-screen findings — not done.

So the per-screen half of the audit is outstanding; what is delivered is the token-level half, which is where 15 of the 17 findings turned out to live anyway. Start Docker and I'll run the dark pass and produce the captures.

Verification

2147 tests, 0 failures — scf-core 1282 (+10), ui 714, app 98, schemas 53. scf-core:typecheck clean. pnpm prepush green.

One local-only wrinkle worth recording: copying .env into the worktree to run the dev server un-skips office-role-access.test.ts, which guards on SUPABASE_SERVICE_ROLE_KEY and then needs a live database. Three failures, entirely my local artefact — the numbers above are from a clean run without it.

🤖 Generated with Claude Code

…e pass its dark run (#833)

Part 1 of 2. #840 fixes what the audit found and removes the gate.

Dark mode had been off since 78caa00 (2026-04-21) because of one line in
`useThemeSetting`:

    const resolvedTheme = 'light' as 'light' | 'dark'

Everything else already worked — the provider resolves a preference, persists
it, stamps `data-theme` on <html>, and bridges to @scaffald/ui's ThemeProvider
as a controlled prop, so that single line governed the whole app.

- `provider/theme/dark-mode-flag.ts` — `isDarkModeEnabled()` reads
  `EXPO_PUBLIC_DARK_MODE === '1'`, and `resolveThemePreference()` does the
  resolution. Split out so it is testable without React: the line that was
  wrong for five months had no test on it.
- `useRootTheme` had the same resolution open-coded and was NOT gated, so it
  could already return a dark theme while the hook returned light. Both now go
  through the one helper.
- The resolution returns 'light' for anything unresolvable. The commented-out
  line it replaces fell back to `context.current ?? 'system'`, which could hand
  'system' back as a resolved theme — there is no colors.bg.system, so the first
  lookup would have read undefined.
- `DrawerFooter`'s toggle is restored, rendering only when the flag is on. A
  toggle that renders while resolution is gated is a control that visibly does
  nothing.
- `smoke-authed.mjs` gains `--scheme light|dark|both`, and the theme assertion
  it was written with is now an exit code rather than a line in the summary.

Chose an env flag over `__DEV__`: `__DEV__` would flip every developer's app to
follow their OS appearance from the next `pnpm web`, and a half-audited palette
is a bad thing to meet by surprise during unrelated work.

Verified against the running app, by computed background colour rather than by
eye, on a freshly wiped Metro cache for each case:

    flag  stored     OS      rendered
    on    system     dark    dark   data-theme=dark   bg rgb(22,17,13)
    on    light      dark    light  data-theme=light  bg rgb(255,255,255)
    off   system     dark    light  data-theme=light  bg rgb(255,255,255)

The off case is the one that matters: production stays light even with a dark
OS and a stored preference. Both servers share one Metro cache and env changes
do not bust it, so the first off-run served the flagged bundle and reported
dark — wiping between runs is required and is now documented in the smoke
script.

2147 tests, 0 failures (scf-core 1282, ui 714, app 98, schemas 53).

Co-Authored-By: Claude Opus 5 <[email protected]>
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