SSR / foldkit-ssr
Checking what the browser will read
List surfaces that the browser may activate and local fields that start
from the baseline Model on purpose so SSR.render catches mismatches before
serving:
const Post = SSR.plan(App, {
id: 'post',
state: Projection.pick(App.model.route, App.model.post.id, App.model.post.liked),
local: [App.model.menuOpen], // intentionally starts from baseline
surfaces: [
Surface.when(PostActions, App.model.route, AppRoute.Post, route => ({ id: route.id })),
Surface.at(Menu, undefined),
],
})SSR.render refuses the plan if any active Surface reads or is activated by a
field missing from state, restored, and local, or if activation differs
between server and client Models. SSR.inspect(plan, model) returns the
same coverage report for tests, inspecting each Surface.each instance by key
(Member[u1]).
Fields the browser reads again
Fields owned by foldkit-mirror (URL or cookie mirrors) can be omitted from
the JSON envelope by listing them in restored and reading them in restore:
const SearchPlan = SSR.plan(App, {
id: 'search',
state: Projection.pick(App.model.route, App.model.results),
restored: [App.model.query, App.model.tld],
restore: model => SearchInUrl.reduce(model, window.location.href),
surfaces: [Surface.at(SearchFilters, undefined)],
})restore runs in the browser before adoption (throwing marks the page
Invalid); listing a field in both state and restored is refused.