Documents the CMS-host-serves-everything decision and proposes the host injection plan
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
# Plan (proposal, not approved): the CMS host injects CMS data into the prerendered ASF pages
|
||||
|
||||
Status: PROPOSAL for Bryan. Nothing is built. It starts as a separate feature after the current merges (contact-form-cms, then asf-packages-cms), not through them. To be agreed with SLP Modular CMS - SMC - Main, who owns the host side.
|
||||
|
||||
## Why
|
||||
|
||||
Hosting decision (2026-11-15): the CMS host is the one entry of the website and serves the prerendered pages, `/admin` and `/api/v1/*`; IIS passes everything to it. A CMS change (packages, banners, later gallery and hero) must then be visible to search engines at once, with no rebuild. The host injects the current data into the prerendered HTML through markers (as on SLP, 60 s cache).
|
||||
|
||||
## What is CMS data on the pages today
|
||||
|
||||
Packages: the price cards (home), the shoot list and shoot blocks, the "welke shoot" choices of the contact form, the `?pakket=` check, the offer price in the JSON-LD of the shoot pages. Banners: the slim top bar and the band under the cards. See [docs/cms-integration.md](../../../docs/cms-integration.md).
|
||||
|
||||
## Proposal
|
||||
|
||||
### 1. Three kinds of markers (built into the page by the ASF build, filled by the host)
|
||||
|
||||
- **Data block**, one per page: `<script type="application/json" id="cms-data">…</script>` holding the raw answers of `GET /api/v1/offerings` and both banners. The host replaces its content with the current answers (JSON-escaped: `<`, `>`, `&`, U+2028/2029). It is a non-executable block, so the CSP stays as it is and the build step that moves inline scripts treats it as data (as it does for `ld+json`).
|
||||
- **Region**, for lists that differ in length (the cards, the banners): a wrapper `<div data-cms-region="offerings">` whose content is the neutral HTML. The host replaces everything between `<!--cms:offerings-->` and `<!--/cms:offerings-->` (written into the wrapper by the build; React cannot emit comments, so the build writes them through `dangerouslySetInnerHTML`).
|
||||
- **Inline value**, for a single price or name inside a sentence: `<span data-cms-price="newborn">€ 185</span>`. The host replaces the text.
|
||||
- **JSON-LD price** of a shoot page: the `ld+json` block gets `data-cms-offer="newborn"`; the host sets `offers.price` from the live package (or removes `offers` when the package is gone or has no readable price).
|
||||
- The same marker format as SLP, if SLP already has one (to be confirmed by SMC).
|
||||
|
||||
### 2. Neutral HTML in the markers
|
||||
|
||||
The build puts crawlable, simple semantic HTML between the markers (package name, price, features, a plain link to `/?pakket=<slug>#contact`; the banner as an `aside`), written from the baked data by one pure function (`web/src/lib/neutralHtml.ts`, all text escaped). The host produces the same markup from live data (template in C#; the ASF repo delivers the spec and golden files, SMC implements, a contract test in each repo checks both sides against the same fixtures). Light static CSS in the page makes it look acceptable (the section is below the fold).
|
||||
Why not exact copies of the styled cards: Chakra/Emotion class names and styles are generated at build time, a C# template cannot reproduce them.
|
||||
|
||||
### 3. Hydration: read the JSON, do not fetch
|
||||
|
||||
- `PackagesProvider` takes its initial state from the data block (reusing `mapOfferings`, `mapBanner`, `mapTopBanner`), not from the baked import and not from a fetch after hydration. Without a block (preview, tests, a host that does not inject) it falls back to the baked data plus the live fetch it has today, so nothing is lost.
|
||||
- Regions are not hydrated by React (`dangerouslySetInnerHTML` with `suppressHydrationWarning`, so React keeps the server DOM). After hydration (`useHydrated`) the styled React components render into the region and replace the neutral HTML. So the first paint is the neutral HTML, and a brief change of look follows; the cards are below the fold, and the region keeps a minimum height to avoid a layout shift.
|
||||
- Inline values hydrate directly from the same data (`suppressHydrationWarning` for the formatting difference).
|
||||
- The contact form choices and `?pakket=` read the same state, so they agree with what the host injected.
|
||||
|
||||
### 4. Hydration and contract tests (per marker, before anything ships)
|
||||
|
||||
- Build test: every expected marker exists exactly once per page, in the final `dist/` (after the script-moving step), and the neutral HTML equals what the pure function gives.
|
||||
- E2E in real Chrome with a stand-in injector in the preview server (same algorithm as the host, fixtures with more, fewer and different packages, with and without banners, an unreadable price, a hostile text such as `<script>`): no hydration or console error, the final DOM shows the injected data, the layout shift stays under the CLS limit.
|
||||
- Fail-safe tests: marker missing, data block empty or invalid, host injection off: the page shows the baked data.
|
||||
- Contract tests with golden fixtures shared with the CMS repo (marker format, escaping, the neutral HTML, the JSON-LD price edit).
|
||||
- Security: all CMS text is HTML-escaped by the host; the data block is escaped as above; no executable inline script appears.
|
||||
|
||||
### 5. Build and deploy consequences
|
||||
|
||||
- The build no longer needs the CMS: the baked data is only the fallback, so `build-test` with `OFFERINGS_URL` and the nightly content build can go. One artifact can serve test and production.
|
||||
- Optional: the test address (`VITE_SITE_URL`) could become a host replacement like SLP's `Website:AuthoredBaseUrl`, which would make the artifact identical for test and production. Needs the injector on ASF's prerendered-pages host; to ask SMC.
|
||||
- Production deploy changes with the hosting: `dist/` goes to the CMS host's prerendered-pages folder (as on test). The generated IIS config reduces to redirects and pass-through. See the Hosting section of the CMS integration doc.
|
||||
- The safety net of AI-DLC: a pipeline option (debounced rebuild after a CMS change) stays possible for build-processed gallery images later.
|
||||
|
||||
### 6. Hero and gallery later (separate plans, same mechanism)
|
||||
|
||||
- **Hero (LCP):** the first slide must be in the first HTML, with the image preloaded. The host injects the slide markup and a `<link rel="preload" as="image">` into a head marker; the client slider starts from the same first slide so nothing swaps. Own plan, because the carousel is interactive.
|
||||
- **Gallery:** `figure` list with image URLs, sizes and alt texts in a region (crawlable), React adds lazy loading and the lightbox after hydration. Images are served same-origin by the CMS host (CSP `img-src 'self'`).
|
||||
|
||||
## Order of work (after approval)
|
||||
|
||||
1. Marker spec and golden fixtures (ASF repo), agreed with SMC.
|
||||
2. Pure neutral-HTML function, build writes the markers, build tests.
|
||||
3. `PackagesProvider` reads the data block, regions, inline values, JSON-LD price; stand-in injector in the preview server; e2e and fail-safe tests.
|
||||
4. SMC implements the injector with the same fixtures; test on ASF test.
|
||||
5. Hosting switch for production (separate), then remove the nightly content build.
|
||||
|
||||
## Open questions
|
||||
|
||||
- For SMC: the marker format SLP uses today; how the injector reads and edits JSON and `ld+json`; behaviour when data or a marker is missing (must fail open: serve the baked page); caching and ETag; whether `AuthoredBaseUrl` can also run on the prerendered-pages host.
|
||||
- For Bryan: accept a brief look change of the cards on first paint (neutral HTML, then styled)? The alternative is one set of cards styled by plain CSS and owned by the host, with no React in those regions; that makes first paint exact but gives up the router links and the Reveal animation of the cards, and puts every design change in two places.
|
||||
Reference in New Issue
Block a user