Skip to content

fix(ssr): the server bundled @scaffald/ui from dist, the client from src — detail pages hydrated against the wrong icons - #790

Merged
thinkclay merged 1 commit into
mainfrom
fix/786-detail-hydration
Sep 17, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/786-detail-hydration

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

What

Fixes #786. Two mismatches, one root cause each.

1. The server bundled @scaffald/ui from dist/; the client bundled it from src/. The package's exports offer source (TypeScript) and import (a tsup bundle). Every client and native bundle picks source through metro.config.js's condition list, so Metro applies the platform forks in src/ — BreadcrumbIcons.web.tsx, the Checkbox/Radio/Stepper/Accordion icon .web files, useSidebarState.web.ts. The web server bundle does not: @expo/cli's withMetroMultiPlatform replaces the condition list with ['node'] for the server environment, which leaves only import, so the server rendered from dist/ — a bundle with no platform forks, i.e. the native files. The breadcrumb's Home icon was therefore lucide-react-native on the server and lucide-react on the client; they draw different SVG (two paths vs a path and a polyline), so React threw the server tree away on every load of the two pages that show a breadcrumb. /jobs hides its breadcrumb, which is why it was clean.

The fix pins @scaffald/ui (and its subpaths) to the source target in the resolver, before the condition list gets a say, so every bundle uses identical files. Verified in the exported server bundle: packages/ui/dist references went from 3 to 0 and packages/ui/src from 0 to 488, matching the client.

2. /jobs/<slug> built its JSON-LD url from window.location. getCanonicalUrl() returns undefined on the server (no window) and the origin on the client, so the <script type="application/ld+json"> text had a url field on the client only. Now built from SITE_ORIGIN, as generateMetadata and the profile route already do. The helper keeps its one legitimate caller (a share link built on press) and now says on the tin that it is client-only.

How it was found

React's diff only prints in a development build, and the dev server was no use: it answers SSR requests for these routes with a "Bundling…" placeholder, so the dev server never showed the failure. expo export --dev --no-minify gives a real server render with React's dev messages, and its diff named the <Home> icon's className and path data outright. The trace of that is in #786.

Also in this PR

  • scripts/audit/hydration-pages.mjs: loads each public page three times at phone (iPhone UA), tablet (iPad UA) and desktop, and counts hydration failures — including the minified codes #418/#423/#425. A production build says only Minified React error #418, and the word-based filter in smoke-hydration.mjs read that as clean; that matcher now catches the codes too. Run it against an expo serve of an export, not only the dev server — the two resolve modules differently, and this bug only existed in the export.

Verification

  • Production export (expo export, minified) served with expo serve: hydration-pages.mjs reports 15/15 clean (/, /jobs, /jobs/<slug>, /users/<slug>, /terms × phone/tablet/desktop, three loads each). On main's build the two detail pages failed every load at every width.
  • Same on the --dev --no-minify export, where React's message would carry the diff if any remained.
  • scaffald-app typecheck green, biome clean, pnpm prepush green. The Metro resolver change is exercised by every bundle the export produces.

Not changed

The nine .web.* forks in packages/ui/src stay as they are — with the server now on src/, they resolve the same way everywhere. Whether the package should keep shipping a fork-less dist/ at all is a Scaffald/ui question; nothing in this repo consumes it any more.

🤖 Generated with Claude Code

…web forks match the client

Fixes #786.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.

/jobs/<slug> and /users/<slug> throw React #418 (hydration failed, tree regenerated) on every anonymous load of a production build

1 participant