SSR / Pages that work without JavaScript
Everything shown is in the HTML
SSR.render renders the Model it is given and fetches nothing. A page whose
rows come from Remote reads them first, with Data.satisfy, which reads what
every active Surface needs, pass after pass, through a reader in the same
process (foldkit-remote-server/fetch's pageReader). The entry's
prepare makes that read, from the Model init gave, for a page and for a
post alike, so one entry is made once:
const readPage = (model: Model, request: Request): Effect.Effect<Model> =>
Data.satisfy(model, actives).pipe(Effect.provide(readPrices(request)))
export const { renderPage } = SSR.entry({ Model, init, update, view, container: null }, plan, {
buildId,
origins: 'same-origin',
prepare: readPage,
})origins: 'same-origin' takes a form posted from the origin the request was
addressed to, for a site whose address is not known when the entry is made (a
dev server's port). Behind a proxy that terminates TLS or rewrites the host,
the server sees http://host while the browser sends Origin:
https://host, and every post is refused 403: deploy there with the public
origin, origins: ['https://example.com']. The same proxy makes the cart
cookie's secure: 'auto' leave out Secure, since the request looks like
http; set Mirror.cookie({ …, attributes: { secure: true } }) in production
behind it. A prepare that fails is answered 500; domains-plus
catches a failed read inside it and draws the page unread, which the browser
then reads.
The plan lists the reading Surfaces and sends their data with Remote's part, so the browser starts with the prices and reads none of them again:
SSR.plan(App, {
state: Projection.pick(App.model.query, App.model.resultsList, App.model.sortOrder),
surfaces: [Surface.at(SearchBox, undefined), actives.top, actives.visible, actives.whole],
parts: [Remote.resume(Data)],
})What a Surface's reads follow (the list's window, the filters) goes in
state, or the browser would read different rows from the ones the server
drew, and SSR.render refuses the plan.