Site / foldkit-site
Activating Surfaces on a route
Attach a foldkit-surface Surface directly to a route node so route navigation
activates its data reads automatically:
const People = Site.route(peopleRouter, AppRoute.People, {
surface: {
surface: PeoplePage,
params: route => ({ searchText: route.searchText }),
},
})Site.sources(site, App.owner, App.model.route) turns every node with a
Surface into a keyed record of Surface.when sources for Data.wiring,
Data.subscriptions, Data.satisfy, or an SSR plan's surfaces (refusing
Surfaces from another application). On a Person route, only Person's
Surface is active; People's stays inactive. Site.sourcesFor(site, owner, place, target.route)
returns only the sources on target.route's ancestor chain for prefetching and
SSR.
When a route's Surface also depends on the signed-in user (such as a home feed),
supply viewer so the Surface activates only once the viewer resolves to
Option.some(me):
const viewerOf = (model: Model): Option.Option<{ readonly id: string }> =>
RemoteData.match(Surface.read(Session, model).me, {
Initial: () => Option.none(),
Loading: () => Option.none(),
Ready: me => Option.some(me),
Refreshing: me => Option.some(me),
Failed: () => Option.none(),
NotFound: () => Option.none(),
})
const Home = Site.route(homeRouter, AppRoute.Home, {
surface: { surface: HomeFeed, viewer: viewerOf, params: (_, me) => ({ ownerId: me.id }) },
})If viewerOf returns Option.none() (while loading or after sign-out),
HomeFeed stays inactive without custom gating in update. Data.satisfy on
the server resolves Session first and HomeFeed in the next pass so SSR
renders the feed complete.