Moves the hydration test out of the routes folder

The route generator scans that folder and warned about the test file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 20:25:58 +01:00
co-authored by Claude Opus 5.5
parent a68e84c3bb
commit d6f8eb6c8e
3 changed files with 5 additions and 5 deletions
@@ -30,13 +30,13 @@ Notes:
| V3 | Inline scripts per real page | 4 (first look), 13 (final) | Final list from the real runner on a scratch copy of the Step 4 output (12 HTML files): every page has 3 moved scripts, `/contact` has 5, 16 distinct files in total. (1) router scroll restoration, 613 chars, no attributes, same file on all pages; (2) Start bootstrap `data-tsr-stream-part=""`, 916 to 1349 chars, one file per page; (3) boundary `document.currentScript.remove();/*$tsr-stream-boundary*/`, 56 chars, same file everywhere; only `/contact`: (4) `<script id="_R_">requestAnimationFrame(...)` 57 chars and (5) React completion runtime `$RB=[];$RV=...;$RC("B:0","S:0")` 845 chars. No `<!--`, no `async`/`defer` on an inline script, no inline module, so no UNSUPPORTED_SCRIPT or UNTERMINATED_SCRIPT. Positions (see Script positions below): scroll restoration is the last child of `<main>` (before the footer); bootstrap, the external module entry and boundary sit after the footer at the end of body; on `/contact` `_R_` is followed by the streamed form (`<div hidden id="S:0">`) and the completion runtime is the last element before `</body>`. | `node config/externalizeInlineScripts.ts <scratch copy>` printed only EMAIL_IN_OUTPUT (12 files) and wrote nothing; a throwaway script in the scratch folder (`b2-scratch/tools/run.mjs`) ran `planExternalization` with `address: null`: no violations, 16 script files plus 12 changed HTML files planned, applied, and a second plan had 0 writes and 0 violations. | OK |
| V4 | Minimum moved scripts | 13 | Keep the minimum of one (BR-SCR-17 unchanged). Every real page has at least 3 moved scripts (5 on `/contact`), so the minimum of one is far below what Start emits and cannot fail on today's output; its job is to catch a step that silently moves nothing, which one reference also catches. Demanding more than one adds nothing on current output and would break on a Start version that bundles scripts differently. A stricter check (for example requiring the bootstrap with `data-tsr-stream-part`) would be a design change; not made. | Counts per page in V3. | OK (recommendation: keep one) |
| V5 | `index.html` written, crawling off | 4 | `/` is written as `index.html` with `autoSubfolderIndex: false`; `/x` as `x.html`, `/soorten-fotoshoots/x` as `soorten-fotoshoots/x.html`. Option names (from the `start-plugin-core` schema): `prerender.crawlLinks: false` and `prerender.autoStaticPathsDiscovery: false` (the latter stops Start adding static routes by itself), page list from `Object.keys(sitePages)` plus `{ path: '/404', prerender: { outputPath: '/404.html' } }`. | Prerender log: "Prerendered 12 pages". `find dist/client -name '*.html'` gives exactly 404, index, over-mij, portfolio, privacyverklaring, contact, soorten-fotoshoots and five `soorten-fotoshoots/<shoot>.html` (12 files, no others). Step 24: `pnpm build` (tsc, vite build, runner) exits 0 with the same 12 pages; `vite.config.ts` now takes `NOT_FOUND_PATH` and `NOT_FOUND_FILE` from `config/pageFiles.ts`. | OK |
| V6 | Code splitting; router plugin unused | 4 (30 later) | Start's plugin includes `tanstackRouterGenerator` and `tanStackRouterCodeSplitter` itself (client and server environments), so route code splitting is on without an option and `@tanstack/router-plugin` is not needed as a direct dependency. Removed with `pnpm remove @tanstack/router-plugin`; only Start's own copy (1.168.48) remains. | Client build has one chunk per route (`over-mij-*.js`, `contact-*.js`, `portfolio-*.js`, `newborn-*.js`, ..., `_-*.js` for the catch-all), plus `ContactForm`, `Lightbox`, `TestimonialCarousel` chunks. Step 30 re-checks. | OK |
| V6 | Code splitting; router plugin unused | 4 (30 later) | Start's plugin includes `tanstackRouterGenerator` and `tanStackRouterCodeSplitter` itself (client and server environments), so route code splitting is on without an option and `@tanstack/router-plugin` is not needed as a direct dependency. Removed with `pnpm remove @tanstack/router-plugin`; only Start's own copy (1.168.48) remains. | Client build has one chunk per route (`over-mij-*.js`, `contact-*.js`, `portfolio-*.js`, `newborn-*.js`, ..., `_-*.js` for the catch-all), plus `ContactForm`, `Lightbox`, `TestimonialCarousel` chunks. Step 30 re-checks. Step 30 (re-check): `grep -rn router-plugin` in `web/` (excluding node_modules, dist, lockfile) finds only a comment in `vite.config.ts`; `package.json` has no `@tanstack/router-plugin`; `pnpm install --frozen-lockfile` exit 0. Step 31 build: per-route chunks present (`over-mij-*.js`, `contact-*.js`, `portfolio-*.js`, `newborn-*.js`, `ContactForm-*.js`, `Lightbox-*.js`, `TestimonialCarousel-*.js`). | OK (re-checked in Step 30) |
| V7 | Sitemap in the client environment only | 4 | `this.environment.name === 'client'` identifies the client build in `generateBundle` (Vite 8.3.1, Start environments `client` and `ssr`). | `dist/client/sitemap.xml` exists once (10 `<loc>`, no `/privacyverklaring`, no `/404`); `find dist -name sitemap.xml` gives only that file; `public/` has no `sitemap.xml`. Step 24: the same build gives the runner line `Inline scripts verplaatst: 12 pagina's gecontroleerd, 16 scripts verplaatst, 28 bestanden geschreven` (no violations), and `dist` keeps the sitemap in the client build only. | OK |
| V8 | Lazy `ContactForm` in HTML and hydration | 27 | What is true (differs from the plan text and BR-LZY-01 "the form fields are in the HTML inside the gate"): the prerender waits for the lazy chunk, so the form and its fields (`data-testid="contact-form"`, `contact-form-shoot`, ...) are in the bytes of `contact.html`, but as a streamed Suspense segment, not in place. In `<main>` the gate holds `<!--$?--><template id="B:0"></template>` plus the empty `FORM_PLACEHOLDER_HEIGHT` box; the form sits in `<div hidden id="S:0">` at the end of the body, and React's completion runtime (`$RC("B:0","S:0")`, moved to an external script by the runner) moves it into place. Without JavaScript the form is therefore in the HTML but not visible (`isVisible` false); FR-PR-13 allows that. With JavaScript, under the production CSP and the moved scripts, the form appears inside `main`, there is no `securitypolicyviolation` and no console message or hydration error. A late chunk is safe too (BR-LZY-05): with the `ContactForm-*.js` request held back 1500 ms, the page hydrates without any message and the form appears. | `e2e/hydration.e2e.ts` "contactformulier op /contact (V8)", 3 tests, pass; also the 390 and 1280 px page tests of `/contact`. | OK (BR-LZY-01 text to be corrected: fields are in the HTML only as the hidden streamed segment) |
| V9 | Testimonials in HTML, hidden slides | 21, 27 | Code part (step 18, 21): `renderToString` of `Testimonials` holds the quote of every visible review; the copies besides the longest sit in a `VisuallyHidden` wrapper with `aria-hidden` and `inert`; axe has no violations in jsdom with the placeholder showing. Browser part (step 27): the raw HTML of `/` contains the quote and author of every visible review. Measured at 390 px with and without JavaScript: the longest review is 350 x 533 px in the flow, the other copy is 1 x 1 px, `aria-hidden` and `inert`; the testimonials section is 840 px high in both cases (no layout change at hydration while the carousel has not loaded). Reading order: the hidden copies are out of the accessibility tree, so each review is read once. | `Testimonials.test.tsx` (4 new tests); `e2e/rawHtml.e2e.ts` "reviews op de homepage"; `e2e/interaction.e2e.ts` "reviews voor het laden van de carrousel (V9)" | OK |
| V10 | Placeholder sizes, CLS below 0.01 | 17, 34 | First estimates (step 17), not measured: footer item `minH` 44px below `lg`, `1lh` from `lg` (one line of the list item); contact card item `minH` 44px; gate notice inline block `38ch` (lead " Mail me voor nu op " 20 + address 18 characters, from the parts without assembling) plus a hidden button with the recipe and label. To be measured in 27 and 34. | `Footer.tsx`, `ContactDetails.tsx`, `ContactFormGate.tsx` | open |
| V11 | One title, one noindex meta | 4 (normal pages), 27 (`404.html`) | Normal pages in the prerendered HTML: one `<title>`, one `description`, one `canonical`, no `data-fallback`, a robots meta only on `/privacyverklaring`. `404.html`: one `<title>` ("Pagina niet gevonden \| Andrea Slop Fotografie") and one `<meta name="robots" content="noindex">`, no description or canonical. React writes `<meta charSet="utf-8">` with a capital S (valid, attribute names are case-insensitive). | `scripts.mjs` counts per file. After hydration in Chrome: `/`, `/over-mij`, `/contact` still 1 title. Caution for Step 27: `/soorten-fotoshoots/onbekend` showed 2 titles and 2 robots metas after React error #418 (the two extra 404 buttons render before hydration; Step 16 fixes that); `/onbekend` is clean. | OK (final check in Step 27, see the V11 paragraph below the table) |
| V12 | 404 hydration with real shell | 27 | Found and fixed. With the real shell (navigation, footer, e-mail placeholders) the 404 HTML for `/404` hydrated at another URL gave React #418 in a race, reproducible below 1024 px width and under CPU or network delay (Lighthouse). Root cause and fix: "404 hydration error #418" below the table (`pendingComponent` of the catch-all route equals its component). After the fix `/404.html`, `/404`, `/onbekend`, `/soorten-fotoshoots/onbekend` give no console message, no CSP violation, one title and one robots meta at 390 and 1280 px, and also with the route chunk delayed by 800 ms; `/soorten-fotoshoots/onbekend` shows one button without JavaScript and two extra after hydration. | `e2e/hydration.e2e.ts` (48 tests); `src/routes/hydration.test.tsx` (4 new tests with `hydrateAppAsStart`). Without the fix 5 e2e tests and 4 unit tests fail. | OK |
| V12 | 404 hydration with real shell | 27 | Found and fixed. With the real shell (navigation, footer, e-mail placeholders) the 404 HTML for `/404` hydrated at another URL gave React #418 in a race, reproducible below 1024 px width and under CPU or network delay (Lighthouse). Root cause and fix: "404 hydration error #418" below the table (`pendingComponent` of the catch-all route equals its component). After the fix `/404.html`, `/404`, `/onbekend`, `/soorten-fotoshoots/onbekend` give no console message, no CSP violation, one title and one robots meta at 390 and 1280 px, and also with the route chunk delayed by 800 ms; `/soorten-fotoshoots/onbekend` shows one button without JavaScript and two extra after hydration. | `e2e/hydration.e2e.ts` (48 tests); `src/hydration.test.tsx` (4 new tests with `hydrateAppAsStart`). Without the fix 5 e2e tests and 4 unit tests fail. | OK |
| V13 | Timestamps and build paths | 4, 13 | Repeated on the final output of the runner (HTML plus the 16 moved script files plus all JS/CSS/XML/TXT/JSON): no build timestamp (`YYYY-MM-DDTHH:MM`) in any text file, no `.map` file, no repository root path (forward slashes, backslashes or doubled backslashes) in any text file. File names are content hashes, so they cannot carry a timestamp. | Scan in the scratch run (`repoPathFiles: 0`, `timestampFiles: 0`, `maps: 0`); the runner's own BUILD_PATH_LEAK check reported nothing. | OK |
| V14 | Focus on first load, tidy navigation | 27 | Focus: on a first load of `/` (after hydration plus 500 ms) `document.activeElement` is not `main`; after a client navigation to `/over-mij` it is `main`; on `/contact?pakket=gezin` the tidy navigation (search removed) does not move focus either. Tidy navigation: `/contact?pakket=gezin` ends on `/contact` with the same `history.length` as before (replace, no extra entry) and `scrollY` 0, one render later than before as BR-HYD-11 expects. `/?pakket=gezin#contact` scrolls the contact section into view after hydration. | `e2e/interaction.e2e.ts` ("zet de focus op main...", "verandert de focus niet...", "tidy navigatie op de contactpagina", "/?pakket=...#contact"), pass. | OK |
| V15 | Emotion/Chakra flicker | 4 (styles in HTML), 27 (screenshots) | Styles are in the HTML: `<style data-emotion` x69 in `/over-mij`, x120 on `/`, plus the bundled stylesheet `<link rel="stylesheet" href="/assets/index-*.css">` (fonts and Chakra base). After hydration in Chrome `/over-mij` has 70 emotion style tags (one added by the client); no console warning. Step 27 screenshots (`/over-mij`, JavaScript off versus on, 390 and 1280 px; reviewed by eye): without JavaScript the header, navigation (desktop links or hamburger), eyebrow "Andrea Slop Fotografie" and the heading "Over mij" are fully styled, with the Jost and Marcellus fonts, in the same positions as with JavaScript; below the heading the page is empty (the `Reveal` content is hidden in the HTML, by design until unit 2) and with JavaScript the photo and text appear in that space (390 px: photo 237 to 499, then text; 1280 px: photo and two-column text). No unstyled flash, no moved header or heading; measured: position and width of `h1` and the top of `main` are equal within 0.5 px with and without JavaScript at both widths. No console warning about styles. | `scripts.mjs`; Chrome probe; `e2e/interaction.e2e.ts` "stijlen zonder en met JavaScript (V15)"; screenshots in the scratch folder (`shots/over-mij-{390,1280}-{zonder,met}-js.png`). | OK |
@@ -58,7 +58,7 @@ Evidence for the mechanism:
3. React hydrates that Suspense boundary on its own, later than the root. If the router has not yet finished loading the match (a status update replaces the pending match with the loaded one, which then renders the same page as the HTML), the boundary is hydrated with the empty client render: mismatch, #418, client re-render, and the hoisted `<title>` and robots meta of the server HTML stay next to the new ones. If the match loads first, nothing is reported. So it is a race, which is why the outcome depends on viewport width and on CPU and network speed (Lighthouse throttles both). Why width matters is only a timing effect (below 1024 px the page reproduced every time on this machine, from 1024 px not); it was not traced further. With the route chunk `_-*.js` held back 400 ms, 1280 px fails too; with it held back 0 ms, 1280 px passes.
4. A plain pending component is also not an option left to chance: `pendingComponent` is not in the default split groups, so it stays in the route file, and the code splitter drops the `NotFound` import there when `NotFound` is also used by the split `component` (build error `NotFound is not defined`).
Why `hydration.test.tsx` missed it: `hydrateApp` creates the client router and awaits `router.load()` before hydrating, so every match is already loaded and the dehydrated-id comparison and the `ssr: false` pending presentation never occur. The browser has the router in the state Start's `hydrate()` leaves it in. The new `hydrateAppAsStart` (in `src/test/hydrate.tsx`) sets up `window.$_TSR.router.matches` with the server's ids, lets the router's own `hydrate()` run against a client router that has not loaded, and then hydrates. Four new tests in `src/routes/hydration.test.tsx` (`/onbekend`, `/404.html`, `/over-mij/x`, `/soorten-fotoshoots/onbekend`) fail without the fix with the same mismatch and pass with it. The e2e tests also fail without the fix (5 of 48 hydration tests: `/404.html`, `/onbekend`, `/soorten-fotoshoots/onbekend` at 390 px, plus the two delayed-chunk tests at both widths).
Why `hydration.test.tsx` missed it: `hydrateApp` creates the client router and awaits `router.load()` before hydrating, so every match is already loaded and the dehydrated-id comparison and the `ssr: false` pending presentation never occur. The browser has the router in the state Start's `hydrate()` leaves it in. The new `hydrateAppAsStart` (in `src/test/hydrate.tsx`) sets up `window.$_TSR.router.matches` with the server's ids, lets the router's own `hydrate()` run against a client router that has not loaded, and then hydrates. Four new tests in `src/hydration.test.tsx` (`/onbekend`, `/404.html`, `/over-mij/x`, `/soorten-fotoshoots/onbekend`) fail without the fix with the same mismatch and pass with it. The e2e tests also fail without the fix (5 of 48 hydration tests: `/404.html`, `/onbekend`, `/soorten-fotoshoots/onbekend` at 390 px, plus the two delayed-chunk tests at both widths).
Fix (inside BR-HYD, no design change; BR-404-01 still holds): `src/routes/$.tsx` sets `pendingComponent` to the same page as `component`, through one shared `CatchAll = () => <NotFound />` (needed because of the splitter issue in point 4). The first browser render of the unknown-URL match is then identical to the prerendered page, whether React hydrates the boundary before or after the match has loaded. After the fix, `/404.html`, `/404`, `/onbekend`, `/soorten-fotoshoots/onbekend` are clean in the production build at 412 and 1280 px, also with the route chunk held back 0, 400, 600 and (development build) 2500 ms. Side effect to know: when the chunk takes longer than `pendingMs` (1 s), Router shows the pending component next to the hydrated HTML (the server copy is hidden by React with `display: none`), so the page briefly holds two copies of the 404 content until the chunk arrives; invisible to the visitor, but a test that counts headings in that window would see two.