Skip to content

fix(ssr): the logo's gradient id named its tree position, not its gradient - #678

Merged
thinkclay merged 1 commit into
mainfrom
fix/ssr-logo-gradient-id
Sep 1, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/ssr-logo-gradient-id

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #625.

The issue's diagnosis was wrong, and the difference matters

#625 read the mismatch as "the server renders the logged-out tree, the client hydrates the logged-in tree, the trees differ" and concluded the whole page is thrown away on every authenticated load. Measuring says otherwise, in two ways.

React's message is the attribute warning, not the tree-regeneration error:

A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up.

Hydration succeeds. The DOM matches. Nothing is regenerated.

And the server does not render a logged-out tree. A plain curl /dashboard with no session comes back with the drawer nav and the logo in it. The only thing React names in the whole diff is the id:

+  id="logo-gradient-_R_2qjaqb9_"        (client)
-  id="logo-gradient-_R_badb9d6_"        (server)

Why useId was the wrong key

useId was the right fix for #582, where the id came from Math.random(). But useId encodes the component's position in the React tree, and server and client don't agree on that position here.

Position is the wrong thing to key on regardless of that disagreement:

  • Two logos with the same colours want the same gradient. Sharing one <linearGradient> is the correct output, not a collision — the two defs would be byte-identical.
  • Two logos with different colours must not share one. The gradient colours are props, so a single hardcoded id would have been wrong.

So the id now names the gradient, derived from its colours — logo-gradient-76EAFF-239CB2. Deterministic on both sides, no tree dependence, distinct exactly when the gradients differ.

Verified

Against the running app, logged in:

Route Before After
/dashboard 1 mismatch 0
/office/applications 1 mismatch 0
/office/ats/metrics 1 mismatch 0

scripts/audit/smoke-hydration.mjs now reports VERDICT: no hydration errors in either case — it was failing its logged-in leg, and it is the release gate for this.

Server and client now emit the identical id: logo-gradient-76EAFF-239CB2.

Tests get the invariant they couldn't express

The old file said explicitly that it could not assert byte-identity across two separate render() calls, because two roots legitimately produce different useId values — and two roots is exactly the situation the server render and the client render are in. Position is no longer an input, so that assertion is now both possible and the whole point:

What this does NOT fix

I checked rather than assumed. The underlying server/client tree-position divergence is real and still there. Emitting a throwaway useId alongside the fixed id still shows:

+  data-probe="_R_2qjaqb9_"     (client)
-  data-probe="_R_badb9d6_"     (server)

ScaffaldLogo was the only useId consumer in the shell — packages/ui's useId is exported but used by no component — so nothing depends on position any more and it has no way to show itself today. A future useId in the shell brings it straight back. Filed separately with the evidence and the probe technique.

Typecheck 12/12. test:unit 7/7 with --skip-nx-cache.

🤖 Generated with Claude Code

…dient

Closes #625.

Every SSR route in the app shell reported a hydration mismatch on the logo's
gradient id. #625 read that as "server renders logged-out, client hydrates
logged-in, the trees differ". Measuring says otherwise, in two ways.

React's message is "A tree hydrated but some attributes ... didn't match ...
This won't be patched up" — the attribute warning, not the tree-regeneration
error. Hydration SUCCEEDS; the DOM matches. And the only thing it names is
the gradient id:

  + client  id="logo-gradient-_R_2qjaqb9_"
  - server  id="logo-gradient-_R_badb9d6_"

`useId` was the right fix for #582, where the id came from `Math.random()`.
But `useId` encodes the component's POSITION in the React tree, and server and
client do not agree on that position here. Position is the wrong key anyway:

  - Two logos with the SAME colours want the same gradient. Sharing one
    `<linearGradient>` is the correct output, not a collision.
  - Two logos with DIFFERENT colours must not share one — and the colours are
    props, so a single hardcoded id would have been wrong.

So the id now names the gradient, derived from its colours:
`logo-gradient-76EAFF-239CB2`. Deterministic on both sides, no tree
dependence, distinct exactly when the gradients differ.

Verified against the running app, logged in, three routes:

  /dashboard             hydration messages: 0
  /office/applications   hydration messages: 0
  /office/ats/metrics    hydration messages: 0

and scripts/audit/smoke-hydration.mjs now reports "no hydration errors in
either case" instead of failing the logged-in leg.

The tests get the invariant they previously could not express. The old file
noted it could NOT assert byte-identity across two separate `render()` calls,
because two roots legitimately produce different `useId` values — two roots
being exactly the situation the server and client render are in. Position is
no longer an input, so that assertion is now both possible and the point.

One thing this does NOT fix, and I checked rather than assumed: the underlying
server/client tree-position divergence is real and still there. Emitting a
throwaway `useId` alongside the fixed id still shows `+ _R_2qjaqb9_` against
`- _R_badb9d6_`. Nothing in the shell depends on position any more, so it has
no way to show itself today — but a future `useId` in the shell would bring it
straight back. Filed separately with the evidence and the probe technique.

Typecheck 12/12. test:unit 7/7 with --skip-nx-cache.
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.

fix(ssr): every authenticated page fails hydration — server renders logged-out, client hydrates logged-in

1 participant