# ADR 0018 — Server-rendered `document` and static export instead of SSR, for now

**Status:** accepted. **Date:** 2026-12-03.

## Context
Pages render in the browser over the Inertia protocol: a first visit returns the shell and the page object as
JSON. That is right for applications behind a login and wrong for content that crawlers, agents and browsers
without JavaScript must read: documentation, landing pages, public catalogues. Such pages are often hosted as
static files, with no server at all.

## Alternatives considered
- **Server-side rendering of Vue components with hydration.** The complete answer, and still missing. It needs a
  second (server) build of every page component, `renderToString` in the request path, hydration in
  `@fellowframework/vue`, and the same in `fellow dev` with HMR. Too large to do well in one step.
- **A separate static site generator for every content page.** Right for a whole site ([`fellow docs astro`](/docs/astro); https://fellow.run is built that way),
  but a few public pages inside an application would live outside contracts, `fellow check` and the tests.
- **`document` on the page contract, plus static export.** The contract returns the title, head tags and body HTML
  of the first response from the validated props. The client replaces the body when it mounts, without hydration.

## Decision
- `definePage` accepts `document({ props, request })`, returning `{ title?, head?, body? }`. `title` is escaped by
  the framework; `head` and `body` are trusted HTML and `escapeHtml` is exported for the values put in them. It
  runs on first visits only, after the props are validated.
- `fellow build --preset static` prerenders every page with `access: 'public'`, `tenant: 'none'` and no path
  parameters and follows the links in the rendered HTML, so pages with parameters are reached through the pages
  that link to them. A link that fails to render fails the build. A page is written as `<path>.html`, so its
  URL on a static host is its `path`, without a trailing slash.
- A page that needs the same markup on the server and in the component renders it once, on the server, and
  passes it as a prop shown with `v-html`.

## Risks
- Markup written twice (server string and Vue template) can drift. Mitigation: the single-renderer pattern above.
- `head` and `body` bypass Vue's escaping. Mitigation: `escapeHtml`, and the documentation says so where the
  option is described.
- A static site has no server for Inertia navigations: its links must be plain `<a href>`.

## Conditions for reassessment
When SSR with hydration lands, `document.body` becomes the fallback for pages that opt out of SSR, and
`document.title`/`head` remain the way to set head tags on the server.
