- Updated `tibi-project-setup` skill to clarify project initialization goals and steps. - Improved `tibi-ssr-caching` skill to detail SSR architecture, responsibilities, and caching mechanisms. - Introduced `website-solution-architecture` skill for translating website requirements into coherent solutions. - Refined `AGENTS.md` to provide a structured roadmap for project development phases. - Added `ADMIN_ASSET_VERSION` to `api/config.yml.env` for asset versioning. - Updated SSR request flow and cache invalidation logic in `api/hooks/ssr/AGENTS.md`. - Removed obsolete `esbuild.config.admin.js` and integrated asset versioning into the main `esbuild.config.js`. - Adjusted `api/collections/content.yml` to utilize asset versioning for admin scripts.
10 KiB
name, description
| name | description |
|---|---|
| tibi-ssr-caching | Implement and debug server-side rendering with goja (Go JS runtime) and dependency-based HTML cache invalidation for tibi-server. Use when working on SSR hooks, cache clearing, or the server-side Svelte rendering pipeline. |
tibi-ssr-caching
This skill should teach the SSR architecture and implementation pattern used in this repo family, not just describe one demo content setup. The important question is: how is SSR built here, where is responsibility split, and which parts must be adapted per project?
SSR request flow
ssr/get_read.jsreceives a page request and callslib/ssr-server.js.ssr/get_read.jsloadslib/app.server.jsand callsapp.default.render({ url }).frontend/src/ssr.tsonly initializes i18n and delegates rendering tosvelte/server.frontend/src/App.svelteowns the actual data loading for both browser and SSR.- During SSR, the app calls its normal page-loading path directly inside a
typeof window === "undefined"guard. - During browser navigation, the same page-loading path is triggered from
$effect. - API calls made during SSR are tracked as dependency strings (
col:idorcol:*) and cached inwindow.__SSR_CACHE__. - The rendered HTML + dependency list are stored in the
ssrcollection.
Responsibility split
frontend/src/ssr.tsshould stay minimal.frontend/src/ssr.tsis responsible for SSR bootstrapping only: locale setup, SSR-safe render wrapper, and callingrender(App, { props: { url } }).- The app component should own data loading.
- Hooks under
api/hooks/ssr/should own caching, cache lookup, and cache persistence. api/hooks/lib/ssr.jsshould own the shared API helper that works in both browser and SSR.
If these responsibilities get mixed together, SSR usually becomes harder to reason about and harder for an LLM to modify safely.
Building the SSR bundle
yarn build:server
- Output:
api/hooks/lib/app.server.js - The project no longer uses Babel for SSR.
- The goja-compatible transform happens in
esbuild.config.server.jsviasupported:async-await: falseasync-generator: falsedynamic-import: false
- The SSR build writes directly to
api/hooks/lib/app.server.js. - Remove splitting-related frontend options (
outdir,splitting,entryNames,chunkNames,outExtension) from the server build, otherwise esbuild will fail withoutfile/outdirconflicts.
Core design rule
- Prefer one shared data-loading path for browser and SSR.
- The browser should trigger it reactively.
- SSR should call that same path explicitly before rendering completes.
- Avoid maintaining a separate SSR-only content-loading implementation unless there is no viable alternative.
In this repo family, the practical pattern is:
- browser:
$effect(() => loadContent(...)) - SSR: call the same
loadContent(...)once inside a server guard
The main trap is assuming $effect alone is enough for SSR. It is not.
Dependency-based cache invalidation
When content changes, clear_cache.js only invalidates SSR entries that depend on the changed collection/entry:
// Each SSR cache entry stores dependency strings:
{
path: "/de/ueber-uns",
content: "...",
dependencies: ["content:abc123", "navigation:*", "medialib:*"]
}
col:idmeans a detail dependency.col:*means a list dependency.clear_cache.jsmust handleDELETErobustly, becausecontext.data.idand route params may be missing. Fallback to the last path segment if needed.utils.clearSSRCache()must clear:col:*onPOSTcol:idORcol:*onPUT/DELETE- everything on manual clear (
POST /ssr?clear=1with no collection context)
How SSR data loading is supposed to work
- Keep
frontend/src/ssr.tsthin. It should set up locale state and callrender(App, { props: { url } }). - Do not move application-specific prefetch logic into
ssr.tsunless absolutely necessary. - The app itself should own the page-loading behavior.
- In projects using this starter architecture, the correct pattern is:
- browser:
$effect(() => loadContent(...)) - SSR: call the same
loadContent(...)once insidetypeof window === "undefined"
- browser:
- This keeps SSR and client navigation on one shared code path.
loadContent(...)must load all data required for a fully rendered page. In this repo that includes both navigation and page content. SSR is incomplete if only the main content entry is loaded.- Because goja runs the transformed async path synchronously enough for this setup, the direct SSR call works. The problem was the reactive
$effect, not the shared async loader itself.
What is project-specific vs. architecture-specific
Architecture-specific rules:
- SSR entry goes through
api/hooks/ssr/get_read.js - HTML caching lives in the
ssrcollection - SSR API calls are tracked through
context.ssrRequest - Client hydration reuses
window.__SSR_CACHE__ - The app owns its own data-loading logic
Project-specific rules that an LLM must inspect before changing SSR:
- which collections contribute to rendered pages
- which routes should SSR vs. skip SSR
- whether URLs are language-prefixed
- whether DB paths are stored with or without language prefix
- which lookups are required to make a page fully render
- which collections need publication-aware invalidation
- whether there are canonical/alias paths
Do not hardcode demo assumptions into the skill. Instead, use the architecture rules above and inspect the current project's route model, collections, and page-loading code.
SSR route validation
Route validation in config.js controls which paths get SSR treatment. Return:
1to render the requested path as-is- a string to rewrite to the canonical cache path
-1for not found
For projects following this setup, route validation must understand the public URL shape used by the frontend router:
/and/{lang}are valid SSR roots.- Public content URLs are language-prefixed (
/de/...,/en/...). - Content entries in the DB are stored without the language prefix in
content.path. ssrValidatePath()therefore needs to:- extract the language prefix from the URL
- strip it before querying
content.path - include
{ lang }in the content query - support
alternativePaths.path - return a canonical language-prefixed URL when the request matched via an alternative path
If this mapping is wrong, SSR may appear to work for root pages while returning 404 or empty content for real CMS pages.
Publication-aware SSR caching
config.jsexportspublishedFilterandssrPublishCheckCollections.ssrPublishCheckCollectionsshould include every collection whose publication window can make cached HTML stale.- In this starter,
contentis currently included. ssr-server.jsusespublication.from/publication.toto computecontext.ssrCacheValidUntil.get_read.jsmust reject expired cache entries and delete them before rendering anew.
Hydration cache behavior
api/hooks/lib/ssr.jsuses the same API helper for browser and SSR.- On the server,
apiRequest(...)delegates tocontext.ssrRequest(...). - On the client,
window.__SSR_CACHE__is checked first for GET requests. - This means SSR is not just HTML prerendering; it also primes client-side data access.
- If HTML renders but
window.__SSR_CACHE__is missing, the SSR pipeline is incomplete.
What an LLM should inspect first when changing SSR
api/hooks/ssr/get_read.jsto understand cache lookup, route validation, and template injection.api/hooks/lib/ssr-server.jsto understand dependency tracking and SSR-side API behavior.frontend/src/ssr.tsto confirm how the SSR render wrapper is bootstrapped.- The top-level app/page-loading surface (for example
frontend/src/App.svelte) to see where data is actually loaded. api/hooks/config.jsto understand route validation, canonicalization, and publication-aware collections.api/hooks/clear_cache.jsplusapi/hooks/lib/utils.jsto understand invalidation behavior.
This order helps an LLM separate infrastructure problems from app-loading problems.
How to verify SSR correctly
- Do not rely only on the BrowserSync/frontend proxy when debugging SSR.
- Test the SSR API endpoint directly, for example:
curl "http://tibiserver:8080/api/v1/_/<namespace>/ssr?url=/de/ueber-uns"
- Verify all of the following:
- HTTP status is correct
- expected page content is present in the HTML
- all page-critical content is present in the HTML
- navigation labels are present in the HTML when navigation is part of the app shell
window.__SSR_CACHE__exists- no
error:comment was injected into the template - second request returns
X-SSR-Cache: true POST /ssr?clear=1removes cache entries and the next request is a miss again
Common pitfalls
- Do not document Babel anymore: the current SSR build is esbuild-only.
- goja does not parse every modern syntax feature: dynamic import must be downlevelled in the server build.
- Do not leave frontend build options on the server build:
splitting/outdirinherited from the frontend config will breakbuild:server. - No browser globals:
window,document,localStorageetc. don't exist in goja. Guard withtypeof window !== "undefined". $effectdoes not solve SSR loading: server-side content must be loaded outside browser-only reactive effects.- SSR can look healthy while content is missing: a 200 response plus app shell is not enough; always verify actual DB content in the HTML.
- Navigation is part of SSR: if header/footer are missing, the SSR setup is still incomplete even when the page body renders.
- SSR cache can go stale: Always ensure
clear_cache.jscovers every collection that affects rendered output. - Do not overfit the skill to demo content: the skill should explain the architecture and where to inspect project-specific route/content rules, not freeze one content model as universal.