Adds browser tests and fixes hydration of the 404 page

The prerendered 404 page is served for other URLs, so its dehydrated match id
differs and the router renders the catch-all's pending component first. Without
one that render was empty, which gave React error 418 and duplicate head tags.
The tests run the built output in a real browser under the production CSP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 19:03:07 +01:00
co-authored by Claude Opus 5.5
parent 0c5d8b8f40
commit 8bf0000531
15 changed files with 1216 additions and 48 deletions
@@ -32,18 +32,42 @@ Notes:
| 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 |
| 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 | open (first look: `contact.html` contains `data-testid="contact-form"` and its fields; `/contact` hydrates in Chrome without console output) | | open |
| 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. Layout and reading order in a browser: step 27. | `Testimonials.test.tsx` (4 new tests) | open |
| 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 (normal pages); `404.html` source OK, final check in 27 |
| V12 | 404 hydration with real shell | 27 | open (first look, before Step 16: `/onbekend` hydrates clean; `/soorten-fotoshoots/onbekend` gives #418, which Step 16 `hydrated && isShootSectionPath` should remove) | | 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 |
| 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 | open | | open |
| 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. Visual check in Step 27. | `scripts.mjs`; Chrome probe. | OK (styles present); screenshots in 27 |
| V16 | `Intl` price text | 27 | open | | open |
| V17 | No `on*=` or `javascript:` | 13, 27 | Step 13 on the runner output: 0 HTML files with an `on*=` attribute and 0 HTML files with `javascript:`. The only `javascript:` in `dist/client` is two strings in `assets/index-*.js`: React's own guard text (`javascript:throw new Error('React has blocked a javascript: URL...`), which is not markup and not a URL in a page. Step 27 repeats it under the CSP. | Scratch run counts (`onAttrFiles: 0`); `grep -l javascript:` over the HTML and the bundle. | OK (Step 13); CSP check in 27 |
| 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 |
| V16 | `Intl` price text | 27 | The text nodes containing a euro sign are identical in the server HTML (JavaScript off) and after hydration in Chrome (production build) for `/` and the five shoot pages, and non-empty; no hydration error. Node and Chrome ICU give the same `nl-NL` text including the non-breaking space. | `e2e/hydration.e2e.ts` "prijstekst (V16)", 6 tests, pass. | OK |
| V17 | No `on*=` or `javascript:` | 13, 27 | Step 13 on the runner output: 0 HTML files with an `on*=` attribute and 0 HTML files with `javascript:`. The only `javascript:` in `dist/client` is two strings in `assets/index-*.js`: React's own guard text (`javascript:throw new Error('React has blocked a javascript: URL...`), which is not markup and not a URL in a page. Step 27: no attribute starting with `on` and no `javascript:` attribute value in any of the 11 pages or `404.html` (parsed with `DOMParser`), and no `securitypolicyviolation` on any of the 48 hydration page loads, the interaction flows and `/contact` with the reveal script, under `securityHeaders('production')`. | Scratch run counts (`onAttrFiles: 0`); `grep -l javascript:` over the HTML and the bundle; `e2e/rawHtml.e2e.ts` and `e2e/hydration.e2e.ts`. | OK |
| V18 | CI artifact layout | 28 | open | | open |
V11 step 27: in `e2e/rawHtml.e2e.ts` all 11 pages have exactly one `<title>` equal to `pageHead`, one `description`, one canonical; `404.html` has one `<title>` ("Pagina niet gevonden \| Andrea Slop Fotografie") and one `<meta name="robots" content="noindex">`, no `data-fallback`. In `e2e/hydration.e2e.ts` the same counts hold after hydration, at 390 and 1280 px, for the 11 pages and `/404`, `/404.html`, `/onbekend`, `/soorten-fotoshoots/onbekend` (one title; robots 1 on the 404 pages and `/privacyverklaring`, 0 elsewhere). The two titles and two robots metas seen on `/soorten-fotoshoots/onbekend` before Step 16 are gone. Status: OK. (Not covered: a URL the router matches but the server does not, see BR-404-07 below, ends with two titles.)
### 404 hydration error #418 on `404.html` (root cause, Step 27)
Symptom: Lighthouse (Step 24) reported React error #418 on `/404.html`. In Chrome it reproduced deterministically below 1024 px viewport width (`/404.html`, `/404`, `/onbekend`, `/soorten-fotoshoots/onbekend`; two titles and two robots metas afterwards) and was clean at 1280 px.
Evidence for the mechanism:
1. A build with development React and no minification (temporary config, deleted) gave the full message: the client rendered `<Suspense fallback={null}>` inside `MatchImpl routeId="/$"` where the server HTML has the `<section>` of the 404 page.
2. The HTML is made for `/404`. Start dehydrates match ids with `#` for `/`: the bootstrap script has `__root__#` and `#$#404`. The browser at `/404.html` or `/onbekend` computes `#$#404.html` or `#$#onbekend`, so `hydrate()` in `@tanstack/router-core` (`load-client.ts`: `dehydrated.i !== dehydrateSsrMatchId(candidate.id)`) stops at index 1, sets `pendingBoundary = 1` and presents that match as `{ status: 'pending', ssr: false }`. A match with `ssr: false` renders `<ClientOnly fallback={pendingElement}>`; `pendingElement` comes from the route's `pendingComponent` (none) or `defaultPendingComponent` (none), so the first browser render of the page body was empty, against server HTML that shows the page.
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).
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.
`/over-mij/x`-style URLs: the same mechanism applies to any match whose id differs from the dehydrated one. For the catch-all it is fixed. For a real page served as `404.html` (BR-404-07) it is not, see below.
### BR-404-07 observation (for unit 3)
`/Over-Mij`: the preview server on this machine (Windows, case-insensitive file system) maps it to `over-mij.html` with status 200 and the page hydrates cleanly, URL stays `/Over-Mij`. On a case-sensitive host the server would send `404.html` with 404; replayed through a route handler in Chrome (production build, 1280 px): the router matches `/over-mij`, the page shows "Over mij", the document ends with two titles ("Over mij ..." and "Pagina niet gevonden ...") and no #418 in this run (the match loaded before React hydrated the boundary, so the outcome is the race of point 3), only the console line for the 404 status. `/over-mij/`: `resolveRequest` gives `404.html` with 404 (BR-SRV-07 interim); in Chrome the router renders the real "Over mij" page at `/over-mij/` (no redirect), again with two titles and the 404 console line, no #418 in this run. Both are observations, not assertions (`e2e/hydration.e2e.ts` "URL die de server niet kent en de router wel"); unit 3 must decide the URL rules so that server and router agree, and the stale 404 title and `noindex` meta in the head are the SEO consequence to weigh.
## Other findings in Steps 3 to 5
- Email address: `info@andreaslop.nl` is in all 12 HTML files (footer link, contact details, gate notice) and nowhere in `dist/client/assets/*.js`, `robots.txt` or `sitemap.xml`. Expected until Step 17.