Site / Creating a site
Data fetching: declare, then plan
Routes declare no loader callbacks. A page's Surface declares what it reads,
and Remote fetches only what the store lacks when model.route changes:
const OwnerPage = App.surface('OwnerPage', {
params: { ownerId: Schema.String },
model: ({ params }) => ({
projects: Data.query(
ProjectsByOwner,
{ ownerId: params.ownerId },
{ select: ProjectSummary, first: 10 },
),
}),
})When model.route leaves Owner, OwnerPage becomes inactive and its
retention requirements drop automatically.
Preparing a destination: prefetch and preload are one composition
To warm a route ahead of navigation (or before SSR rendering), construct a
hypothetical Model with target.route, collect its chain's active sources with
Site.sourcesFor, and call Data.satisfy:
const prepare = Effect.gen(function* () {
const target = Site.target(OwnerNode, { ownerId: 'u1' })
const there = { ...model, route: target.route }
const active = Site.sourcesFor(AppSite, App.owner, App.model.route, target.route)
return yield* Data.satisfy(there, active)
})On the server, Data.satisfy prepares the Model before a synchronous render.
In the browser, Data.preload(there, active) runs as a Command and merges
fetched rows into the current Model via a Preloaded Message. Wire
Site.routing's preload option with pointedLinks() from
foldkit-primitives/dom to preload same-origin links on hover or focus
(examples/cms/src/apps/siteApp.ts).
Why there are no waterfalls
Three design choices eliminate route waterfalls:
- Declarative requirements: Sibling Surfaces plan together and Remote batches and deduplicates concurrent reads rather than running sequential route handlers.
- Bounded fixed-point passes: When a parent read reveals child IDs (like a
document revealing its blocks),
Data.satisfyfetches each dependency level concurrently in one pass. - Synchronous navigation: Setting
model.routetransitions immediately without awaiting loaders;InitialandLoadingstates render inline witharia-busyand reserved layout space (Utilities.busyReveal).
Mutations that move items between lists name the affected active list pages on
the write so the server returns updated pages in the same round trip (see
foldkit-remote's README and examples/chirp/test/requests.test.ts).