Repository navigation
fix(ui): repair hydration and the frozen experience total (#582, #590) - #599
Merged
Merged
Conversation
#582 — ScaffaldLogo derived its SVG gradient id from Math.random(), so the server-rendered id could never equal the client-rendered one. React discarded the tree and re-rendered the whole page. The logo lives in the app shell, so this fired on every SSR route, not just one screen. Now useId(), with the colons stripped because useId() returns ":r0:"-style values that are not usable inside an SVG url(#id) reference. ImageUpload had the same shape — Math.random() for an id that lands in the DOM as an input id and a label's htmlFor — and is fixed the same way. The remaining Date.now() calls in that file build upload filenames inside event handlers, not during render, so they are fine. #590 — "Total Years Experience" was memoised on react-hook-form's `watch`, which is referentially stable, so the memo ran once per mount and never again. The form is populated by reset() in an effect after first render, so the value was computed against experienceProfileDefaults and reported "0 years 0 months" for the life of the component — including for users with a full work history — and never moved when entries were added or edited. Now useWatch, with the arithmetic extracted to calculateTotalExperience so it can be tested without rendering a 700-line form. That extraction turned up a second defect: the calculation read date-only strings ("2018-06-01", parsed as UTC midnight) back with local getters, so in any negative-offset timezone it landed on the previous day and sometimes the previous month. Two users with identical histories saw totals a month apart depending on where they were sitting. Now UTC throughout. Concurrent roles still count twice. That is long-standing behaviour and changing it is a product decision, not a bug fix — it is preserved and noted. Tests: 6 for the logo, built on the actual hydration invariant (two independent renderToStaticMarkup calls must be byte-identical, which is exactly what the server and client renders are), plus distinctness of two logos in one tree and a guard that ids stay url()-safe. 10 for the duration arithmetic, including the regression case and the timezone case. Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Aug 12, 2026
thinkclay
added a commit
that referenced
this pull request
Aug 12, 2026
…it clean (#504, #593) (#606) I un-excluded scf-core from test:unit in #604 on the strength of a JSON report showing 957 passed / 0 failed. That was the wrong signal. `vitest run` exits 1 regardless, so `pnpm test` went red on main for anyone running it locally. Two things were wrong with how I checked. The OOM is real. I grepped the background task's output file for "heap out of memory" and got nothing, because that file held only my own echo lines — vitest's stderr went elsewhere and I never read it. #504 is not stale: at --max-old-space-size=4096 the main process dies with "Ineffective mark-compacts near heap limit" at ~4GB. Raising it to 8192 does not fix it either; with the two collection failures below repaired, more files collect, more memory is retained, and it OOMs again at 8GB. Every test passes and the report says success: true — the failure is entirely the parent process at teardown, not the tests. My pass/fail summary could not see a broken file. A file that fails to *collect* contributes zero passed and zero failed, so it is invisible to a count of assertions. Two files were failing that way and I shipped both: - ScaffaldLogo.test.tsx (mine, #599) — "Unexpected token 'typeof'". react-native-svg's untransformed source. A mock for it has existed at tests/infrastructure/vitest/mocks/react-native-svg.tsx since it was written but was never aliased in vitest.config.ts, unlike the react-native, lucide and expo-updates mocks. Now aliased, which fixes any test rendering an SVG. - ProfileWizard.test.tsx (mine, #605) — the commit hook I added pulled @scf/core/provider, and through it UniversalThemeProvider -> expo-router/react-navigation, which does not resolve under vitest. Mocked in the test; the commit path keeps its own unit tests. The logo test also asserted something false: that two separate render() calls produce byte-identical markup. They are two React roots, and useId is only required to be deterministic by position within a root, so a correct implementation fails that. It now asserts what actually regresses if the id goes random again — not drawn from a random source, stable across re-renders, distinct between two logos in one tree, and referenced by the url(#id) that fills the mark. scf-core goes back in the exclude list. Making it runnable is #504's job and it needs the parent-process retention fixed, not a bigger ceiling. Co-authored-by: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #582, #590. Part of #594.
#582 —
Math.random()in a render path broke hydration app-wideScaffaldLogoderived its SVG gradient id fromMath.random(), so the server-rendered id could never match the client-rendered one. React discarded the tree and re-rendered the whole page. The logo sits in the app shell, so this fired on every SSR route, not just one screen — it is what the dev overlay reported on/profile.Now
useId(), with colons stripped:useId()returns":r0:"-style values, which are not usable inside an SVGurl(#id)reference.ImageUploadhad the identical shape —Math.random()for an id that lands in the DOM as an inputidand a label'shtmlFor— so it is fixed the same way. The remainingDate.now()calls in that file build upload filenames inside event handlers, not during render, and are fine.Worth re-testing #450 (public pages non-interactive on first load) once this lands — a discarded hydration tree loses its server-attached handlers until the client re-render completes, which matches that report.
#590 — the experience total was computed once and never again
useMemo(..., [watch]), and react-hook-form'swatchis referentially stable. The form is populated byreset()in an effect after first render, so the memo ran againstexperienceProfileDefaultsand reported0 years 0 monthsfor the life of the component — including for users with a full work history — and never moved when entries were added or edited.Now
useWatch, with the arithmetic extracted tocalculateTotalExperienceso it can be tested without rendering a 700-line form.A second defect the extraction exposed
The calculation read date-only strings back with local getters.
new Date('2018-06-01')parses as UTC midnight;getMonth()in any negative-offset timezone lands on the previous day and therefore sometimes the previous month. Two users with identical histories saw totals a month apart depending on where they were sitting. Now UTC throughout — which is also why the test expectations here are stable rather than machine-dependent.Concurrent roles still count twice. That is long-standing behaviour, changing it is a product decision rather than a bug fix, so it is preserved and documented.
Tests
Logo (6) — built on the actual hydration invariant rather than a proxy for it: two independent
renderToStaticMarkupcalls must be byte-identical, which is precisely what the server render and the client render are. Plus distinctness of two logos in one tree (a shared id would make one gradient win for both) and a guard that ids stayurl()-safe.Duration (10) — the regression case, the timezone case, unparseable dates, and a backwards range clamping to zero rather than subtracting.
Full profile suite: 335 assertions across 44 files, 0 failures.
scf-coretypechecks at 0 errors.CI checks will show red without running — Actions billing block, see #375.
🤖 Generated with Claude Code