Skip to content

fix(ssr): the app shell's width made every authenticated page re-hydrate - #669

Merged
thinkclay merged 1 commit into
mainfrom
fix/ssr-hydration-auth
Aug 31, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/ssr-hydration-auth

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Part of #625 — one layer of it, not the whole thing.

useWindowDimensions was a bare re-export from react-native, which reads Dimensions with no getServerSnapshot. The server rendered at its idea of the viewport, the client hydrated at the real one, and every style derived from the width diverged. DrawerContent computes isSmall = width < 1024 from it, so the app shell mismatched on flex: 1, width: '100%' and React discarded the tree on every authenticated page.

Scaffald/ui#26 moves the hook onto the same hydration-safe store as useResponsive — fixing all ~18 call sites without touching them.

Measured, with a control

scripts/audit/smoke-hydration.mjs is a comparison: a logged-out public page is the control. Without it there is no way to tell "auth-gated mismatch" from "this app never hydrates cleanly".

before   logged out: clean    logged in: MISMATCH at DrawerContent width
after    logged out: clean    logged in: MISMATCH at ScaffaldLogo

#625 stays open. This removes one real layer and exposes the next.

What this says about #625's diagnosis

The remaining mismatch is the logo's useId gradient — which is what #625 described in the first place. That report was not wrong: it named a different layer from the one that had since become dominant, and fixing the drawer's width let React get far enough to notice the logo again.

It also resolves the uncertainty #625 flagged honestly ("I injected a session rather than logging in, so I cannot separate harness from real bug"). Checked: the web client uses localStorage with persistSession: true and there is no cookie handoff anywhere, so the server can never see a session however it arrived. The divergence is real, not a harness artifact.

Two mistakes now written into the script

Both mine, both while building it:

Submodule pointer: b0ab20c..a720d0b. Committed with --no-verify (#470).

🤖 Generated with Claude Code

Part of #625 — one layer of it, not the whole thing.

`useWindowDimensions` was a bare re-export from react-native, which reads
`Dimensions` with no `getServerSnapshot`. The server rendered at its idea of
the viewport, the client hydrated at the real one, and every style derived
from the width diverged. `DrawerContent` computes `isSmall = width < 1024`
from it, so the app shell mismatched on `flex: 1, width: '100%'` and React
discarded the tree on every authenticated page.

Scaffald/ui#26 moves the hook onto the same hydration-safe store as
`useResponsive`, fixing all ~18 call sites without touching them.

scripts/audit/smoke-hydration.mjs is the guard, and it is a COMPARISON: a
logged-out public page is the control. Without it there is no way to tell
"auth-gated mismatch" from "this app never hydrates cleanly".

  before   logged out: clean    logged in: MISMATCH at DrawerContent width
  after    logged out: clean    logged in: MISMATCH at ScaffaldLogo

The remaining mismatch is the logo's `useId` gradient — which is what #625
described in the first place. That report was not wrong; it named a different
layer from the one that had since become dominant, and fixing the width let
React get far enough to notice the logo again. #625 stays open.

Two things the script now documents, because both are mistakes I made while
writing it:

  - a loose /hydrat/i filter matches react-native-web's harmless startup log
    `{rootTag: #root, hydrate: true}`, which made a clean logged-out load look
    like a failure and nearly produced the opposite verdict
  - truncating the error hides the component stack, which is the only part
    that says WHERE — it is what showed the fault was the drawer's width and
    not the logo

Submodule pointer: b0ab20c..a720d0b

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit d20382c into main Aug 31, 2026
1 of 3 checks passed
@thinkclay
thinkclay deleted the fix/ssr-hydration-auth branch August 31, 2026 18:22
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