Foundation 05
Load the first page on the server
Use the active session and tenant context in a SvelteKit server load. Return serializable rows. Give control to the browser only when the page must stay live.
Web collection
Server loadHydrationSSEIndexedDBSync
Keep initial reads in server load
The server can use the database, signed session, tenant, and permission snapshot directly. Return only the fields the page needs. Collections come from the runtime that src/lib/server/smrt.ts exports; runtime.getCollection() is request-scoped, so call it inside the load and never keep the result.
- Generated API routes resolve collections the same way: each embeds a prelude that imports $lib/server/smrt and calls its runtime.getCollection(). A legacy getCollection or getSmrtConfig export there still wins for one release, with a deprecation warning; do not add one.
src/routes/+page.server.ts
typescript
import { runtime } from '$lib/server/smrt';
export const load = async ({ depends, locals }) => {
depends('smrt:items');
if (!locals.permissions.includes('items.read')) return { items: [] };
const items = await runtime.getCollection<Item>('Item');
const rows = await items.list({ limit: 50 });
return { items: rows.map(({ id, title, status }) => ({ id, title, status })) };
};Add a browser collection when the page needs it
Pass the server rows as initialData. The collection can then handle live invalidation, ETags, persistence, or offline writes without delaying the first render.