Repository navigation
Description
Found while building an authenticated smoke harness (scripts/audit/smoke-authed.mjs, added in #624).
Every SSR page load for a logged-in user appears to fail hydration and re-render the entire tree on the client. React reports it against ScaffaldLogo, but the logo is the symptom, not the cause.
What the overlay says
Hydration failed because the server rendered HTML didn't match the client.
As a result this tree will be regenerated on the client.
packages/scf-core/assets/ScaffaldLogo.tsx (54:5)
<Svg width={width} height={height} viewBox={viewBox} style={style}>
<Defs>
<LinearGradient id={gradientId}
Why the logo is not the bug
ScaffaldLogo already does the right thing — useId(), which is exactly the #582 fix, and the comment above it says so:
const gradientId = `logo-gradient-${useId().replace(/:/g, '')}`useId() only produces matching ids across server and client if the two render trees have the same shape. Ours do not:
- the session lives in localStorage, which the server cannot read
- so the server renders the logged-out tree
- the client hydrates with a session and renders the logged-in tree
- the trees differ, the
useIdcounters drift, and the first component with a generated id — the logo in the app shell — is where React notices
Because the logo sits in the shell, this fires on every SSR route, not one screen. And "this tree will be regenerated on the client" means the entire page is thrown away and re-rendered, which is the whole cost of SSR paid and then discarded.
Confidence, stated honestly
I reached the authenticated screens by injecting a session into localStorage rather than by logging in through the form, so I cannot fully separate "the harness causes this" from "real auth causes this".
But the mechanism is identical either way: supabase-js persists to localStorage, the SSR server has no visibility into it, and there is no cookie handoff. A real login should produce the same divergence on the next SSR navigation. Worth confirming with a real session before investing in a fix.
Why it matters beyond the console noise
- Every authenticated page pays for SSR and then discards it — slower first interaction, and a visible flash on slower devices.
- It masks real hydration bugs. Once a mismatch is expected on every page, the next genuine one is invisible.
- It is very likely related to getServerSnapshot infinite-loop error spams the console on every page #438 (
getServerSnapshotinfinite-loop spam) — both are server/client state-divergence symptoms.
Directions worth considering
- Cookie-backed session so the server can render the authenticated tree — the real fix, and the largest change.
- Suspend the auth-dependent subtree until hydration completes, so both sides render the same placeholder shape.
- Give the logo a static gradient id. Cheapest, and it silences the reported error — but it only moves the mismatch to the next component with a generated id. Not a fix.
Reproducing
pnpm supa start
pnpm supa functions serve api
# start a dev server, then:
EXPO_PUBLIC_SUPABASE_ANON_KEY=... [email protected] \
SMOKE_PASSWORD=password123 node scripts/audit/smoke-authed.mjsThe overlay appears on /office/applications, /office/ats/metrics and /dashboard alike — the harness strips it so screenshots stay usable, so read the console output rather than the images.
Activity
fix(ssr): the app shell's width made every authenticated page re-hydr…
thinkclay commentedon Aug 31, 2026
One layer fixed (#669,
d20382c1c; submodule Scaffald/ui#26,a720d0b). Leaving this open — the mismatch moved rather than disappeared.The uncertainty in the original report is resolved
I flagged that I injected a session rather than logging in, so I could not separate harness from real bug. Checked: the web client uses localStorage with
persistSession: trueand there is no cookie handoff anywhere — no SSR code reads auth at all. The server can never see a session however it arrived, so the divergence is real.Confirmed by comparison, with a logged-out public page as the control:
But the cause was not what this issue names
The component stack put it in
DrawerContent, on aflex: 1, width: '100%'div — nowhere near the logo.useWindowDimensionswas a bare re-export from react-native, which readsDimensionswith nogetServerSnapshot;DrawerContentcomputesisSmall = width < 1024from it, so the app shell diverged on every authenticated page. ~18 files used that hook.Fixed by moving it onto the same
useSyncExternalStoreasuseResponsive, whosegetServerSnapshotReact uses for both the server render and the hydration render.So this report was right, about a different layer
The remaining mismatch is the logo's
useIdgradient, exactly as described here. This issue was not wrong — it named a layer that was still there underneath a second one that had become dominant. Fixing the width let React get far enough to reach the logo again.Next step for whoever picks this up:
scripts/audit/smoke-hydration.mjsreproduces it in one command, and prints the full component stack.Two traps it now documents, both of which I fell into:
/hydrat/ifilter matches react-native-web's harmless{rootTag: #root, hydrate: true}startup log. That made a clean logged-out load look like a failure and nearly produced the verdict that this issue blamed the wrong thing entirely.fix(ssr): the logo's gradient id named its tree position, not its gra…
thinkclay commentedon Sep 1, 2026
Two things in this issue's diagnosis turned out to be wrong, and both mattered.
React was reporting the attribute warning, not tree regeneration. The message is "A tree hydrated but some attributes … didn't match … This won't be patched up". Hydration succeeds and the DOM matches — nothing is thrown away, so "the whole cost of SSR paid and then discarded" overstated it.
The server does not render a logged-out tree. A plain
curl /dashboardwith no session returns the drawer nav with the logo inside it. The premise that the server renders logged-out and the client hydrates logged-in is not what happens.What was actually wrong is narrower:
useIdencodes the component's position in the React tree, and the id was the only thing in the whole diff.Position is the wrong key here regardless of the disagreement. Two logos with the same colours want the same gradient — sharing one
<linearGradient>is correct output, not a collision — and two with different colours must not share one. The colours are props, so option 3 in this issue (a static id) would have been wrong rather than merely incomplete. The id now names the gradient:logo-gradient-76EAFF-239CB2.smoke-hydration.mjsnow reportsno hydration errors in either case; it was failing its logged-in leg.The cause is still open as #679. I checked instead of assuming: a throwaway
useIdemitted alongside the fixed id still shows+ _R_2qjaqb9_against- _R_badb9d6_, so server and client really do disagree on tree position.ScaffaldLogowas the onlyuseIdconsumer in the shell (packages/ui'suseIdis exported but used by no component), so nothing expresses it today — adding one anywhere in the shell brings it back. #679 carries the evidence and the probe technique, including the two traps that make naive probing report a false match.Also worth recording against the note in this issue about not being able to separate harness from real auth: it makes no difference. The divergence reproduces the same way, and it is not auth-shaped.
thinkclay commentedon Sep 1, 2026
Correction worth recording against my previous comment.
I said the server does not render a logged-out tree, on the strength of
curl /dashboardreturning the drawer nav. That observation was right, and the conclusion I drew from it was too broad.Continuing to verify after #678 merged turned up a second, more severe hydration failure that is still present — the tree-regeneration variant, not the attribute warning:
It is intermittent. Three runs of
smoke-mobile-navon worker/dashboardwith identical code: fails, clean, fails. And it does not reproduce in an isolated probe matching the smoke's setup exactly — 0 failures at every width from 1440 down to 390.Same inputs, different outcomes. That is a race, and it means this issue's original hypothesis was closer to right than my correction gave it credit for: the session is loaded asynchronously from localStorage, so whether the first client render is logged-in depends on whether that load wins the race. When it wins, the trees genuinely differ in structure and React discards the render.
So the accounting is:
useIdany more.#678 stands on its own merits and its verification holds. But "hydration is clean" was too strong a claim from me, and #681 is the one that carries the cost this issue was originally about.