Moves the app to TanStack Start with prerendering

Every page is now built as HTML from sitePages.ts, with a catch-all route for
404.html. Hooks that read the browser during render are safe for prerendering.
The script step that keeps the CSP intact follows, so this build still has
inline scripts and is not deployable yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 17:58:54 +01:00
co-authored by Claude Opus 5.5
parent 65c850e949
commit c1e90f0768
33 changed files with 746 additions and 269 deletions
@@ -0,0 +1,33 @@
# Proof report: Start on the real app (Steps 3 to 6)
Date 2026-10-31. Details and evidence per point: [verification-log.md](verification-log.md).
## Outcome
`pnpm build` (tsc, Vite with Start, prerender) is green and writes 12 HTML files plus `sitemap.xml` into `dist/client`. `pnpm test` is green (113 files, 888 tests, same counts as the baseline). `pnpm lint`, `pnpm format:check` and `pnpm audit:deps` are green. V1, V2, V5, V6 and V7 are OK; there is no blocker for the parallel batches.
## Per point
- **V1 client entry**: Start uses `src/client.tsx` by file name; it calls `startSentry()` and then `hydrateRoot(document, <StrictMode><StartClient/></StrictMode>)`. Pages hydrate in Chrome without console errors (`/`, `/over-mij`, `/contact`, `/contact?pakket=gezin`).
- **V2 shell in jsdom**: Router does render `shellComponent`, but React 19 keeps `html`/`head`/`body` out of the container; it does set `lang` on the test document and double-wraps `ChakraProvider`. `renderApp` therefore gives its router a test shell (`HeadContent` + children). All old tests pass.
- **V3 inline scripts**: every page has the scroll-restoration script (613 chars), Start's bootstrap (`data-tsr-stream-part`, 916 to 1349 chars) and the boundary script (56 chars); `/contact` also has `<script id="_R_">requestAnimationFrame(...)` and the React completion runtime (845 chars). No `<!--`, no `async`/`defer` on inline scripts, no inline module scripts. JSON-LD blocks are data and stay.
- **V5 pages**: exactly the 11 pages plus `404.html`; `autoSubfolderIndex: false`, `crawlLinks: false`, `autoStaticPathsDiscovery: false`.
- **V6 splitting**: built into Start's plugin (one chunk per route); `@tanstack/router-plugin` removed as direct dependency.
- **V7 sitemap**: `this.environment.name === 'client'` works; one `sitemap.xml` in `dist/client`.
## Resolved dependency versions
`@tanstack/react-start` 1.169.4, `@tanstack/react-router` 1.170.46, `@tanstack/router-core` 1.171.39, `@tanstack/start-plugin-core` 1.171.55, `playwright-core` 1.55.0, vite 8.3.1, zod 4.6.7 (override).
## Deviations from the design text (for the main session to confirm)
1. `pnpm-workspace.yaml`: new scoped override `zod@4: ^4.6.6` because `pnpm audit:deps` reported a high advisory (zod < 4.6.6) in Start's dependency tree. Patch bump only.
2. `@tanstack/react-router` raised from `^1.170.39` to `1.170.46` (the plan's fallback) to avoid two router copies.
3. `src/navigation.ts`: `RoutePath` excludes `/$`, otherwise the page register would need an entry for the catch-all.
4. `renderApp` uses a test shell instead of dropping `shellComponent` (the shell is rendered by Router in jsdom without error, so the plan's "variant" is a variant of the shell, not of the route tree).
5. Old tests changed (BR-TST-02): `usePageLoaded.test.tsx` and `DeferredImage.test.tsx` (the mocked `readyState` stays `interactive` when the `load` event is dispatched; with a store-based hook the snapshot must change too, as it does in a real browser), `useReveal.test.tsx` (the first render now assumes no reduced motion, so an observer starts and is stopped again at once; the test now expects all observers disconnected instead of none created), `app.test.tsx` (register test ignores the catch-all `/$`).
## Things seen that later steps must handle
- Before Step 16, `/soorten-fotoshoots/onbekend` and `/portfolio?shoot=gezin` give React error #418 in Chrome (expected, those are Step 16 changes); the former also ends with two `<title>` and two robots metas after the client re-render.
- The e-mail address is in all 12 HTML files until Step 17.
@@ -0,0 +1,51 @@
# Verification log (V1 to V18)
Unit 1 start-migration. Rows are filled in the step named in the plan (section 3.2). Status: OK, BLOCKED, DEVIATION, open.
## Resolved versions (Step 4, 2026-10-31)
| Package | Version | Note |
|---|---|---|
| `@tanstack/react-start` | 1.169.4 | added exact (pnpm wrote no caret) |
| `@tanstack/react-router` | 1.170.46 | was `^1.170.39` (resolved 1.170.39); raised to Start's own version, see note 1 |
| `@tanstack/router-core` | 1.171.39 | one copy for router and Start |
| `@tanstack/start-plugin-core` | 1.171.55 | transitive |
| `@tanstack/router-plugin` | 1.168.48 | transitive only (inside Start); the direct devDependency was removed |
| `playwright-core` | 1.55.0 | devDependency, exact |
| `zod` (4.x, transitive) | 4.6.7 | via override, see note 2 |
| `vite` | 8.3.1 | unchanged |
Notes:
1. With only `@tanstack/react-start` added, pnpm kept two router copies (`react-router` 1.170.39 for the app and 1.170.46 for Start). The plan's fallback (raise `@tanstack/react-router` to the spike's 1.170.46) removes the second copy. No peer conflict was reported.
2. `pnpm audit:deps` failed after adding Start: high advisory GHSA-mrhx-c7xc-m3w5 (zod < 4.6.6) through `@tanstack/start-plugin-core` and `router-generator`. Fixed by a patch bump only, with a scoped override in `web/pnpm-workspace.yaml` (`zod@4: ^4.6.6`, same pattern as the existing seroval overrides); zod 3 (Chakra CLI, Lighthouse) is not touched. Afterwards `pnpm audit:deps`: no known vulnerabilities. The main session should decide whether it accepts this extra override (BR-BLD-11 only names the seroval overrides as "stay").
3. `seroval` and `seroval-plugins` overrides still apply (`pnpm why seroval`: 1.7.3, both router-core copies).
## Table
| V# | Point | Step | Outcome | Evidence | Status |
|---|---|---|---|---|---|
| V1 | Custom `src/client.tsx` hydrates with Start; `startSentry()` before hydration | 4 | Start picks `src/client.tsx` by name (default entry `client` in `srcDirectory`); it replaces the default entry, whose body is `startTransition(() => hydrateRoot(document, <StrictMode><StartClient /></StrictMode>))`. `startSentry()` runs at module level before that call. | Build output `dist/client/assets/index-*.js` contains `hydrateRoot` and the Sentry loader (`sentryClient-*.js` dynamic import). Chrome (playwright-core, system Chrome, static server, no CSP yet): `/`, `/over-mij`, `/contact`, `/contact?pakket=gezin` hydrate with no console error or warning. Not proven here: that Sentry initialises (only on the test and production hostnames, so a no-op on 127.0.0.1); unit tests of `monitoring/` cover that. | OK |
| V2 | `RouterProvider` in jsdom renders `shellComponent` | 5 | Yes, Router calls the root `shellComponent` (`Match.js`: `ShellComponent = route.isRoot && route.options.shellComponent`). React 19 treats `html`/`head`/`body` as singletons, so no `<html>` lands in the RTL container (container has 0 html/head/body), but it sets `lang="nl"` on `document.documentElement` and wraps `ChakraProvider` a second time. Variant used: `renderApp` replaces the root route's `shellComponent` by a test shell (`HeadContent` + children) on its router instance; production code untouched. | Probe test (removed) printed `shellComponent: function`, `html=0 head=0 body=0`, `document.documentElement lang=nl`. All 888 tests pass with the test shell (with the real shell, 45 of 46 in `app.test.tsx` passed; the one failure was the `/$` register test). | OK |
| V3 | Inline scripts per real page | 4 (first look), 13 (final) | Per page (12 files) the inline executable scripts are: (a) router scroll restoration, 613 chars, no attributes, same body everywhere; (b) Start bootstrap `data-tsr-stream-part=""`, 916 to 1349 chars, differs per page; (c) boundary `document.currentScript.remove();/*$tsr-stream-boundary*/`, 56 chars, same everywhere. `/contact` has two more (lazy form Suspense): `<script id="_R_">requestAnimationFrame(function(){$RT=performance.now()});</script>` (57 chars) and the React completion runtime `$RB=[];$RV=function(a){...` (845 chars). No `$RC` seen on other pages. External: `<script type="module" async src="/assets/index-*.js">` only (not touched by the runner). JSON-LD blocks (`application/ld+json`) are data and stay. BR-SCR-05: no inline body contains `<!--`, no classic inline script has `async`/`defer`, no inline `module` script exists. | `scratchpad/scripts.mjs` over `dist/client` (first look, to be repeated in Step 13 with the real runner). | OK (first look) |
| V4 | Minimum moved scripts | 13 | open (first look: every page has at least 3 inline executable scripts, so a minimum of one is far below what Start emits) | | open |
| 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). | 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`. | 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 | open | | open |
| V10 | Placeholder sizes, CLS below 0.01 | 17, 34 | open | | 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 |
| V13 | Timestamps and build paths | 4, 13 | No build timestamp (`YYYY-MM-DDT..`) in any text file of `dist/client`, no `lastmod` in the sitemap. No repository path (`SlpSoftware`, `Projects/Andrea...`, `K:\`, worktree name) in any text file, no `.map` file. | `grep -rI` over `dist/client`. Re-check on the moved scripts in Step 13. | OK (first look) |
| 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 | None in the 12 HTML files (` on[a-z]+=` and `javascript:` both 0 matches). Step 13 repeats it on the runner output; Step 27 under the CSP. | `scripts.mjs` | OK (first look) |
| V18 | CI artifact layout | 28 | open | | open |
## 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.
- The route tree gets a `/$` route, so `RoutePath = keyof FileRoutesByTo` would force a `/$` entry in `sitePages`. `src/navigation.ts` now uses `Exclude<keyof FileRoutesByTo, '/$'>`; the test "bevat precies de routes van de route tree" ignores `/$`. Not in the design text; needed for `tsc` (see proof-report).
- Start's `client.base` default is `/_build`, but it is not used in this build: assets stay under `/assets/` (needed for `/assets/inline-<hash>.js` of the runner).