Wires the script step and preview server into the build

The build now moves inline scripts and fails on a violation. Lighthouse audits
/404.html, because it refuses a page with a real 404 status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 18:25:41 +01:00
co-authored by Claude Opus 5.5
parent 0b964b5466
commit fe1ec5db3d
8 changed files with 36 additions and 14 deletions
@@ -388,7 +388,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
## Part F: Integration (batch B5; after CP2)
### Step 24: Wire the build, preview and configuration [ ]
### Step 24: Wire the build, preview and configuration [x]
- Executor: Haiku.
- Implements: BR-BLD-01, 03, 04, 09, 10 (client path); BR-SRV-08; BR-SEC-01; CP3.
@@ -29,9 +29,9 @@ Notes:
| 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) | 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). | OK |
| 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`. | 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 |
| 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 |
@@ -63,3 +63,12 @@ From the scratch run; positions are offsets in the rewritten HTML. A classic scr
| React completion runtime (845 chars, ends in `$RC("B:0","S:0")`) | Last element of the body, after the hidden form segment (about 14 KB after the bootstrap), just before `</body>` | `/contact` |
On `/contact` the lazy `ContactForm` is a streamed Suspense boundary: its place in `<main>` is `<!--$?--><template id="B:0">` and the form HTML sits in a hidden `S:0` div at the end of the body. It becomes visible only when the completion script runs. That script was inline before the move and is now an external classic script, so the form appears one request later than in the raw Start output, and not at all without JavaScript. Relevant for V8 and for the measurement (CLS and LCP of `/contact`).
## Lighthouse on the new preview server (Step 24)
Command: `pnpm exec lhci collect --config=lighthouserc.cjs --numberOfRuns=1 --url=<URL>` on a fresh `dist/client`; `lhci` starts `pnpm preview --port 4173 --strictPort` itself and stops it again. Port 4173 was free before the run. Only `collect` runs, so assertions and targets are not checked here.
- `/over-mij`: exit 0, no runtime error. Performance 0.77, accessibility 1, best practices 1, SEO 1. LCP 6.2 s (score 0.11). Target for a photo page is 0.85 (see `lighthouserc.cjs`, to be checked in Step 34 under the measurement conditions).
- `/bestaat-niet` (before the change): exit 1, `Runtime error encountered: Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Status code: 404)`. Cause: the preview server answers 404 for the path. The fix is in the step: `notFoundPath` is now `/404.html`.
- `/404.html` (after the change): exit 0, no runtime error. Performance 0.80, accessibility 1, best practices 0.96, SEO 0.58. Failing audits: `errors-in-console` (score 0): React error #418 (hydration mismatch) in `index-*.js` on this page; `is-crawlable` (score 0, expected, the page is noindex); `meta-description` (score 0, expected, `404.html` has no description by design); LCP score 0.22 (5.3 s). The #418 belongs to V12 (404 hydration); Step 27 must check it again. The `assertMatrix` entry for `notFoundPath` requires best practices 1, so this URL fails that assertion until V12 is fixed; this step only checks that `collect` works.
- `notFoundPath` change: `lighthouserc.cjs` line 22 is now `'/404.html'`. The guard test `loopt gelijk met de URLs van Lighthouse CI` in `src/app.test.tsx` now also checks it.