SSR / foldkit-ssr
foldkit-ssr
Server rendering for a Foldkit application that hands the browser the Model
the server reached, not the inputs to rebuild it. init runs once, on the
server. The browser adopts the server's HTML and starts from the slice of the
Model it owns.
Early. The API below is built and tested; as a 0.x package it may still change between minor versions.
bash
pnpm add foldkit-ssr foldkit-surface foldkit effectts
// Which part of the Model the browser owns.
const Post = SSR.plan(App, {
id: 'post',
state: Projection.pick(App.model.route, App.model.draft),
})
// Server: render, and write that slice into the page.
const html = SSR.page(template, await Effect.runPromise(SSR.render(config, Post, { buildId, url })))
// Browser (from 'foldkit-ssr/client'): take the page over from the slice, without running init.
SSR.hydrate(config, Post, { buildId })