Adds the step that moves inline scripts to files
TanStack Start writes inline scripts into each page, which the strict CSP blocks. This step moves them to hashed files and checks the output: every page is present, no executable inline script remains and the e-mail address appears nowhere. It is not part of the build yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+18
-4
@@ -27,8 +27,8 @@ Notes:
|
||||
|---|---|---|---|---|---|
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
@@ -37,11 +37,11 @@ Notes:
|
||||
| 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) |
|
||||
| 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 | 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) |
|
||||
| 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 |
|
||||
| V18 | CI artifact layout | 28 | open | | open |
|
||||
|
||||
## Other findings in Steps 3 to 5
|
||||
@@ -49,3 +49,17 @@ Notes:
|
||||
- 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).
|
||||
|
||||
## Script positions per page (Step 13)
|
||||
|
||||
From the scratch run; positions are offsets in the rewritten HTML. A classic script that was inline now loads from `/assets/inline-<hash>.js` and blocks the parser at that point until fetched and run; that is a finding for the measurement (BR-MEA-03), not a design change.
|
||||
|
||||
| Script | Where it sits | Pages |
|
||||
|---|---|---|
|
||||
| Scroll restoration (613 chars) | Last child of `<main>`, after the last section and before `</main>` and the footer; about 78 to 92% into the document, so it blocks the parsing of the footer and everything after | all 12 |
|
||||
| Start bootstrap (`data-tsr-stream-part`) | After the footer, end of body, before the external `<script type="module" async src="/assets/index-*.js">` | all 12 |
|
||||
| Boundary (56 chars) | Directly after the module entry script, end of body | all 12 |
|
||||
| `_R_` requestAnimationFrame (57 chars) | After the boundary script, directly before the streamed `<div hidden id="S:0">` with the contact form | `/contact` |
|
||||
| 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`).
|
||||
|
||||
Reference in New Issue
Block a user