Repository navigation
feat(theme): restore dark resolution behind a flag, and give the smoke pass its dark run (#833) - #954
Merged
Merged
Conversation
…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]>
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.
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:Everything else already worked. The provider resolves a preference, persists it, stamps
data-themeon<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()readsEXPO_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.useRootThemehad 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.'light'for anything unresolvable. The commented-out line it replaces fell back tocontext.current ?? 'system', which could hand'system'back as a resolved theme. There is nocolors.bg.system, so the first token lookup would have readundefined.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 nextpnpm web, and a half-audited palette is a bad thing to meet by surprise during unrelated work. One line in.envmakes "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:
data-themesystemdarkrgb(22,17,13)—bg.dark.defaultlightlightrgb(255,255,255)systemlightrgb(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
darkand 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
--schemeparsing and the theme-assertion logic are exercised directly rather than eyeballed — a dark pass that renders light produceswrong: ["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.
bg.dark.mutedcauses 15 of the 17. Every status and interaction colour lands at 2.62–2.96:1 against the 3:1 that WCAG 1.4.11 requires, on that one ground; the same pairs score 4.3–4.8 in light. The ramps are fine, the ground is wrong.border[dark].focusat 2.62 is the one with teeth — a focus indicator below 3:1 is a 2.4.11 failure. One token change clears all 15, and it is the first thing feat(theme): ship dark mode — every redesigned screen verified dark, toggle in Settings and the drawer #840 should do.'#fff'it replaced scores about 1.9:1.needs-design). Measured on/: bodyrgb(22,17,13)with sections atrgb(255,255,255)andrgb(3,69,80)from the fixedmarketing/theme.ts. Needs a decision — pin the ground on marketing routes, or make that palette dark-aware. I'd take the first.The audit script is in the issue bodies' reach; it reads
colors.tsdirectly 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.
smoke-authed.mjs --scheme darkproduces captures whosedata-themereadsdark— implemented, not run. The code path is exercised; the pass itself needs the stack.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:typecheckclean.pnpm prepushgreen.One local-only wrinkle worth recording: copying
.envinto the worktree to run the dev server un-skipsoffice-role-access.test.ts, which guards onSUPABASE_SERVICE_ROLE_KEYand 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