Coming from SvelteKit

Svelte 5 stays on the frontend; V replaces the Node backend. File names look familiar on purpose — runtimes, data flow, and a few conventions differ.

SvelteKitSwelteNotes
+page.svelte+page.svelte or about.svelteSame component, two spellings: about.svelte ⇔ about/+page.svelte (both → /about). One triple per URL — mixing foo.* + foo/+page.* is a build error.
+page.ts / +page.server.ts+page.v + +page.ts (or flat about.v + about.ts)Server @[load] = page load cascade; universal sibling = sync view-model transform (async only when ssr=false). .svelte/.v pair by mod path — no cross-pairing.
+layout.svelte+route.svelteWrapper per subtree, children snippet + {@render} outlet. SSR composes the chain server-side; client hydrates it in place.
+layout.server.ts+route.v (@[load])Same cascade slot. (req) at level 0, (req, parent T) deeper — typed value instead of parent() directly.
+server.tsSwelteResponse in the leaf .vNo standalone file. Verbs on the route file; full header/cookie/status/binary control.
+error.svelte (per-dir)inherited directory +error.svelteNearest physical ancestor, including route groups; retains wrappers strictly above its directory. Props { status?, message? }, matching SSR/client selection and parent fallback.
params/*.tssrc/matchers.v @[matcher]Central file + codegen'd JS mirrors. [id=integer] builtin.
hooks.server.ts+route.v + src/app.vSubtree middleware stays local; @[startup]/@[reroute] handle boot + rewrite (ticks live in @swelte/plus).
src/lib/server/*src/lib/**/backend/Physical: backend-only files are a build error from browser/WASM imports.

Data loading

  • @[load] runs server-side for HTML, navigation and refresh. Interaction data also comes from stubs (@[get]/@[rpc]). Components must not call stubs at top level during SSR (build error) — move load-time data into $props(), keep stubs for handlers.
  • Universal sibling <basename>.ts (admin.ts for admin.svelte) exports load({ params, props, url }) — a sync view-model transform inside render (async only when ssr = false). No parent() — the parent value arrives as a typed fn param.
  • Cache tags: depends(...tags) registers tags; invalidate(...tags) / invalidateAll() refresh affected active loads and resolve after page state is committed.
  • Load envelope: SwelteLoadResult{ status, headers, cookies, body } opts into status/headers/cookies on the HTML navigation. Non-200 renders +error. Throw with status via swelte_error(status, msg) (V) / swelteError(status, msg) (TS); isRedirect(e) narrows 3xx.
  • No fail(422, …) helper — throw !T with a { ok: false, fieldErrors } body, narrow with isFail(e).

Client router

  • History-driven: link-click interception (incl. data-sveltekit-reload/data-swelte-reload full-reload, ...-noscroll/...-noreplace/...-preload-data/...-preload-code off honored) + hover prefetch + popstate.
  • goto(url, { replaceState?, noPreload?, noPreloadCode? }), preloadData(url) (JSON probe, no DOM write), preloadCode(url) (chunk warm, no DOM write), pushState(url, { 'page-state' }) / replaceState(url, { 'page-state' }) (shallow — no reload, no load re-run; page.state survives traversal, never sent to the server).
  • captureSnapshot(fn) / restoreSnapshot(fn) (manual export const snapshot lite — captured on goto, replayed on popstate); beforeNavigate (cancellable via cancel()) / afterNavigate / onNavigate; page/navigating/updated stores (checkUpdated() flips updated by polling the X-Swelte-Version header).
  • Layout composition (export const layout = false | true | 'dir' in the sibling .ts — no @ files): admin/login/+page.ts with layout = false renders bare; 'admin' keeps wrappers down to admin; true pins the full chain back on. Composition-only — skipped wrappers' @[load]/@[before]/@[after] still run.

Rendering

  • SSR is runtime-only (embedded QuickJS / sidecar), 50ms + 16MB budgets, optional strict failures instead of SPA fallback. SSG is additive (prerender.entries).
  • Per-route ssr = false (SPA shell, async universal load client-side) and csr = false (SSR HTML only — the client mount/hydrate is a no-op). Independent corners, same sibling .ts carrier.
  • Per-page prerender = true | false | 'auto' (leaf wins, else nearest explicit wrapper, else global prerender.entries).
  • Service worker opt-in + offline fallback; ordinary API/SSE requests stay network-only. Explicit mutations can use the persistent offline outbox. Native ISR caches public HTML and regenerates it in the background with atomic replacement. Build-time images produce resized WebP variants and #app/images metadata.
  • serializedHeaders = [...] allowlists which load-envelope headers land on the HTML navigation (Set-Cookie untouched, Location always passes). Per-route RouteId + Params types (the $types-lite). Per-route limits override the global hardening knobs (single binary, no regions/runtime).

Errors & platform

  • Directory +error.svelte boundaries inherit through physical ancestry, with matching server/client selection and parent fallback. handleFetch(hook) intercepts stub fetches (auth headers/retries).
  • Aliases are #routes / #lib (hash style). $app/stores|state|navigation adapt Swelte state and navigation. Compatibility mode also supplies $app/forms; $env/* is unsupported.
  • Single artifact: dist/server + dist/. No Node at runtime.

Opt-in page compatibility

swelte.compat: 'sveltekit' enables nested data/form props, request-local SSR page state, reactive $app/state, and the forms callback adapter. swelte.actionQuery selects named or legacy actions independently. See page lifecycle and forms for hydration, invalidation and mutation behavior.