From 8bf00005316406fc32780d2003fdb14564874dcc Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Sat, 31 Oct 2026 19:03:07 +0100 Subject: [PATCH] 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 --- .../start-migration-code-generation-plan.md | 6 +- .../start-migration/code/verification-log.md | 40 ++- web/e2e/hydration.e2e.ts | 328 ++++++++++++++++++ web/e2e/interaction.e2e.ts | 262 ++++++++++++++ web/e2e/rawHtml.e2e.ts | 157 +++++++++ web/e2e/smoke.e2e.ts | 30 ++ web/e2e/support/browser.ts | 136 ++++++++ web/e2e/support/globalSetup.ts | 12 + web/e2e/support/server.ts | 24 ++ web/src/prerender.test.tsx | 70 ++++ web/src/routes/$.tsx | 17 +- web/src/routes/hydration.test.tsx | 32 +- web/src/test/hydrate.tsx | 71 +++- web/src/test/setup.ts | 60 ++-- web/vitest.e2e.config.ts | 19 + 15 files changed, 1216 insertions(+), 48 deletions(-) create mode 100644 web/e2e/hydration.e2e.ts create mode 100644 web/e2e/interaction.e2e.ts create mode 100644 web/e2e/rawHtml.e2e.ts create mode 100644 web/e2e/smoke.e2e.ts create mode 100644 web/e2e/support/browser.ts create mode 100644 web/e2e/support/globalSetup.ts create mode 100644 web/e2e/support/server.ts create mode 100644 web/src/prerender.test.tsx create mode 100644 web/vitest.e2e.config.ts diff --git a/aidlc-docs/features/prerendering/construction/plans/start-migration-code-generation-plan.md b/aidlc-docs/features/prerendering/construction/plans/start-migration-code-generation-plan.md index 2bd458e..c37604b 100644 --- a/aidlc-docs/features/prerendering/construction/plans/start-migration-code-generation-plan.md +++ b/aidlc-docs/features/prerendering/construction/plans/start-migration-code-generation-plan.md @@ -402,7 +402,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o - Done when: **CP3**: `pnpm build` succeeds, the runner prints its success line (this requires Steps 17 and 21 done, otherwise EMAIL_IN_OUTPUT fails the build, which is the check working). Port 4173 and CPU rules of Step 2 apply to item 5. - Record: verification log notes under V5, V7, and the lighthouse finding. -### Step 25: Prerender-safety test (BR-TST-07) [ ] +### Step 25: Prerender-safety test (BR-TST-07) [x] - Executor: Sonnet. - Implements: BR-TST-07; FR-PR-05; NFR-PR-Q-03 (fast feedback). @@ -410,7 +410,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o - Do: for every key of `sitePages` plus an unknown path, create a router with memory history from `routerOptions()`, await `router.load()`, render with `react-dom/server` inside `ChakraProvider`, and expect no throw and a non-empty string containing the page's `

`. This catches `window`/`document` use in render paths. If it cannot be made to work with the shell, drop the shell from the test as in Step 5. Feasibility is the open point: if the Chakra provider or the router cannot render in a Node environment at all, record "not feasible, the build's own prerender is the guard" in the verification log and replace the test by a documented skip-free alternative (a test that scans nothing is not acceptable): in that case STOP and report instead of deleting the step. Add the assertion that the server HTML of `/contact` has no assembled address. - Done when: `pnpm exec vitest run src/prerender.test.tsx` passes. -### Step 26: e2e harness and smoke test [ ] +### Step 26: e2e harness and smoke test [x] - Executor: Sonnet. - Implements: BR-TST-05 (harness); D11; NFR-PR-Q-03; V1 (browser side), V8 early. @@ -422,7 +422,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o - `smoke.e2e.ts`: `/` and `/contact` and `/onbekend`: page loads under the production CSP, the heading is visible, zero console errors/warnings and zero CSP violations. This is the first real-browser proof; if it fails with hydration or CSP errors, analyse; failures that need a design change: STOP. - Done when: `pnpm build && pnpm e2e` passes locally (Chrome must be installed or `CHROME_PATH` set; if no browser is available on this machine, STOP and ask the main session instead of skipping). -### Step 27: Full e2e tests (BR-TST-05, BR-TST-06; V8, V9, V10, V11, V12, V14, V15, V16, V17) [ ] +### Step 27: Full e2e tests (BR-TST-05, BR-TST-06; V8, V9, V10, V11, V12, V14, V15, V16, V17) [x] - Executor: Sonnet. - Implements: BR-TST-05, 06; BR-HYD-17, 20, 21; BR-LZY-01, 05; BR-404-03, 04, 05, 07; BR-ENT-06; BR-MAIL-10; FR-PR-05 to 08, 14, 15, 22; NFR-PR-S-02, SEC-01, Q-03, Q-04; PBT: "No PBT properties identified" (browser flows). diff --git a/aidlc-docs/features/prerendering/construction/start-migration/code/verification-log.md b/aidlc-docs/features/prerendering/construction/start-migration/code/verification-log.md index 6100509..eca8c2b 100644 --- a/aidlc-docs/features/prerendering/construction/start-migration/code/verification-log.md +++ b/aidlc-docs/features/prerendering/construction/start-migration/code/verification-log.md @@ -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/.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 ``, 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 `
` the gate holds `` plus the empty `FORM_PLACEHOLDER_HEIGHT` box; the form sits in `