Skip to content

Dark mode on web: SSR renders light and hydration keeps the server's styles, so the whole shell stays white #970

Closed

Description

@thinkclay

With dark on, /office/applications renders half dark: the page ground, drawer, sidebar and the ScreenHeader title stay in light-mode colours, while the Lane rows, stage titles and the transparency strip render in dark-mode colours. Because the light ground stayed and the row text switched to text[dark].primary (white), every candidate name and stage title is white-on-white and invisible.

Measured, not a race

First seen in the first dark run of smoke-authed.mjs --scheme dark (#833). To rule out a mid-transition frame, the harness now waits until <html data-theme> is stamped and the loading overlay is gone, then settles 2.5 s, before it screenshots (fixed in the #966 PR). The re-run is pixel-identical: data-theme="dark" on all 8 routes, and the same split frame.

So two components in the same tree, under the same provider, are reading opposite themes at the same instant.

rendered light (stale) rendered dark (correct)
page ground (OfficeLayout) transparency strip (CANDIDATES CAN SEE IN)
drawer / sidebar (DrawerLayout, colors.bg[theme].default) Lane row titles (text[dark].primary → white)
ScreenHeader <H2> title (colors.text[theme].primary → near-black) stage names, stage dots, overdue amber
sidebar nav labels metric figures in the strip

The split is not by package — DrawerLayout (scf-core) is stale and Lane titles (composed in scf-core) are correct. It lines up with mount time: everything that mounts with the shell is stale; everything that mounts after the api responds (rows, strip) is right. That reads as "the provider's value changed from light to dark after first paint, and already-mounted consumers did not re-render".

One confirmed, one hypothesis

Confirmed, regardless of the above: packages/scf-core/components/layouts/OfficeLayout.tsx:233 paints the office content area with colors.gray[50] — a light-only literal with no theme dimension. Even once propagation is right, the office ground stays light. That is a one-line token fix.

Hypothesis, not tested — do not take it as the diagnosis: since #957, useThemeSetting() calls useSegments() and forces light when isLightOnlySurface(segments). segments is [] before the router has resolved the route, and [] is exactly the landing-page case that helper treats as light-only. If the first render of a protected route happens under [], the app starts light and flips to dark a tick later — which would explain when the flip happens, and would be a regression #957 introduced for every dark user, not just this screen. It would not by itself explain why mounted consumers fail to pick up the flip; that is a second question (memoisation somewhere between the ui ThemeProvider's controlled setResolved and the shell), and I have not looked for it. Verify before acting on either: log useSegments() on the first render of /office/applications, and check whether useThemeContext().theme changes for an already-mounted shell component when the provider flips.

Why #833's own verification did not catch it

That verification measured document.body background and data-theme on /, /terms and /auth — the auth screen rendered dark correctly. The body and the stamp are right here too; it is the component tree underneath that is split, and nothing measured a component. The lesson is already written into the smoke's theme assertion: a stamp is not a render.

Acceptance

  • useSegments() on the first render of a protected route is logged and the hypothesis confirmed or refuted on the issue
  • With dark on, every component on /office/applications reads the same theme — verified by computed colour on a ScreenHeader title and a Lane title in the same frame
  • OfficeLayout.tsx:233 uses colors.bg[theme].*, not colors.gray[50]
  • smoke-authed.mjs --scheme dark captures of the four ATS routes show no light shell

This is the first finding of #840's per-screen pass, and it is the blocking one: until the shell follows the theme, no other dark finding on these screens can be read.

Activity

  1. added
    bug
    agent-ready
    redesign
    on Oct 5, 2026
  2. thinkclay commented on Oct 6, 2026

    @thinkclay
    ContributorAuthor

    Correction on the hypothesis, measured. The useSegments() === [] lead is refuted. With a trace in useThemeSetting and the smoke's own session path on /office/applications, every call on the route reported segments: ["(admin)","office","applications"], lightOnly: false, and resolved dark. The [] readings I saw earlier all coincided with pathname: "/" — a seeding load and a redirect, not the route. So #957 is not the cause.

    What is measured, in one frame on the route:

    useThemeSetting   → dark
    ThemeBridge       → themeForUI: dark
    ui ThemeProvider  → controlled: true, propTheme: dark, resolved: dark   (the only one mounted)
    ScreenHeader <H2> → rgb(22, 17, 13)   ← text.light.primary
    

    The provider is right and the component under it is wrong — and only one ThemeProvider renders (src/index.ts and src/theme/index.ts export the same module; H2 renders style={[computedStyle, style]} so the caller's colour wins).

    Then the lead that matters: after adding a one-line console.log to ScreenHeader.tsx and DrawerLayout.tsx — nothing else — both logged sees dark and the title measured a dark token, on the same server, minutes apart. The only difference was that Metro re-transformed those two files. This worktree's packages/ui submodule pointer moved this morning (rebased onto main), and Metro keys its transform cache on path + content, so unchanged ui files could keep transforms from the previous ui commit while changed ones get fresh ones — a bundle stitched from two ui versions, which would produce two ThemeContext instances and exactly this symptom.

    Testing that now with a full cache wipe and a cold rebuild. If the split does not reappear, this issue narrows to the one confirmed code defect — OfficeLayout.tsx:233's colors.gray[50] — plus a harness rule: wipe Metro's cache whenever the ui submodule pointer moves, and record that in the smoke's prerequisites.

  3. changed the title [-]Dark mode: the office shell stays light while content mounted later goes dark — names render white-on-white[/-] [+]Dark mode on web: SSR renders light and hydration keeps the server's styles, so the whole shell stays white[/+] on Oct 6, 2026
  4. thinkclay commented on Oct 6, 2026

    @thinkclay
    ContributorAuthor

    Root cause, measured. Retitling. This is neither a theme-context split nor a Metro-cache artefact, and my two earlier leads (#957's useSegments, duplicate ThemeContext) are both refuted by measurement.

    The mechanism

    Web SSR renders the app light unconditionally, and React does not patch attribute mismatches on hydration.

    Three independent readings on /office/applications, dark preference, dark OS, warm bundle, fully wiped Metro cache:

    1. React believes it painted dark. Walking the fiber attached to each white DOM node: all six white divs — the ThemeProvider container, the navigator Background, the CustomDrawer sidebar, the OfficeApplicationsScreen stack — carry backgroundColor: rgba(22,17,13,1.00) in their React style prop. Their computed CSS is rgb(255,255,255). Every traced producer agrees: useThemeSetting → dark, ThemeBridge → dark, ui ThemeProvider → controlled, resolved: dark, (admin)/_layout → #16110d, DrawerLayout → #16110d, ScreenHeader sees dark.
    2. The server rendered it white. curl http://localhost:8094/office/applications: 11 inline background-color:rgba(255,255,255,1.00), 0 dark, no data-theme, and the loading overlay in the markup. The server has no storage and no window, so resolveThemePreference yields light there every time.
    3. React said so. Console, 3×: "A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up." — the documented hydration behaviour: server attributes are kept, only a dev warning is raised.

    So every node that exists in the server HTML keeps its white style; every node that mounts after hydration (Lane rows once the api responds, the transparency strip) is created client-side and gets dark. That is exactly the split in the capture, and it explains why touching a source file "fixed" that component — HMR remounted it client-side. It also means the Loading overlay in #967 is white for the same reason, not a resolution race.

    Scope

    Every SSR'd route, every dark user on web, every first load. Client-side navigation after the first load is fine (no SSR). The native app is unaffected (no SSR). Light users are unaffected (server and client agree), which is why nothing in release 3 caught it.

    Two fix shapes

    (a) Make the server render the right theme. The theme has to be known server-side: a cookie written by the client whenever the preference resolves (and on first visit from prefers-color-scheme via a tiny inline script), read in the root loader the way viewportLoader already renders per device (#785). Server and client then agree, hydration is clean, no flash. This is the correct fix and matches the repo's SSR architecture.

    (b) Force a client re-render after hydration when the themes disagree. e.g. key the themed subtree on resolvedTheme once mounted, so a client theme that differs from the server's remounts and rewrites every style. One-liner-ish, but it is a visible light→dark flash on every dark load and a full remount of the navigator — which .radium/app-expo.md's navigator-wrapper rule exists to forbid. A mitigation, not a fix.

    (c) Independent of both: OfficeLayout.tsx:233 paints colors.gray[50], a theme-less light literal; it stays light under either fix. One-line token change.

    Acceptance

    • curl of an SSR route with the dark cookie/preference returns dark inline grounds, or the server output is theme-agnostic
    • Zero "attributes … didn't match" hydration warnings on /office/applications in dark
    • Candidate names and stage titles legible in the dark capture; the harness assertion extended to a computed colour on a shell element and a content element
    • OfficeLayout.tsx:233 on a theme token

    Found by the #840 per-screen pass; this is the first thing it has to clear.

  5. thinkclay commented on Oct 6, 2026

    @thinkclay
    ContributorAuthor

    Independent verification of #999, with the instrument that found this. On main at 65e36341d, warm bundle, fully wiped Metro cache, dark preference + dark OS, /office/applications:

    divsWhite: 0   whiteDivsWhoseReactPropIsDark: 0   divsDark: 7
    screenHeaderTitle rgb(63,181,199)   candidate rgb(255,255,255)   stage rgb(255,255,255)
    hydration warnings: none
    

    Before #999 the same probe read six white divs all carrying the dark ground in their React style prop, and three "attributes … didn't match … won't be patched up" warnings. Fixed.

    What remains is a flash, not a bug. The server still renders light — the raw HTML carries 11 white inline grounds and 0 dark — and the body ground goes from unset at 60 ms to #16110d at 1,083 ms. So a dark visitor sees roughly one second of the light shell on every full page load (not on client-side navigation).

    Removing it means the server knowing the theme, and the only server-side channel is loader data, as the viewport hint does (#785). That reaches the public routes and /, which have loaders — and none of the 134 route files under (protected) and (admin), which have no loader and no layout-level equivalent in expo-router. Filing the flash separately so the cost is weighed on its own rather than under a closed bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrontendUXagent-readybugpriority: highredesign

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions