Enabling SSR
Setssr: true in startApp:
src/server/app.ts
startApp({ ssr: true }) decides whether they
are used at runtime.
When
ssr is omitted or false, Modelence renders on the client only, exactly as
before. Nothing about your existing app changes until you opt in.Routing with SSR
For the server and client to resolve the same route, a location-driven router must be told which URL to render. Pass arouter function to renderApp. Modelence
calls it with the current location on the server and again on the client during
hydration, so both produce the same tree:
src/client/index.tsx
location passed to the router is path + search (the hash is never sent to
the server), matching what the browser sees on hydration. This avoids hydration
mismatches.
Data fetching and hydration
- Session is rendered on the server and hydrated on the client, so
useSession()returns the correct value on the very first render with no flash of logged-out UI. - Queries (
modelenceQuery) run on the server and their results are serialized into the HTML, so cached data is available immediately after hydration. - Live queries (
modelenceLiveQuery) are WebSocket subscriptions with no server snapshot — they stay pending during SSR and connect after hydration on the client.