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.
| SvelteKit | Swelte | Notes |
|---|---|---|
+page.svelte | +page.svelte or about.svelte | Same 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.svelte | Wrapper 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.ts | SwelteResponse in the leaf .v | No standalone file. Verbs on the route file; full header/cookie/status/binary control. |
+error.svelte (per-dir) | inherited directory +error.svelte | Nearest physical ancestor, including route groups; retains wrappers strictly above its
directory. Props { status?, message? }, matching SSR/client
selection and parent fallback. |
params/*.ts | src/matchers.v @[matcher] | Central file + codegen'd JS mirrors. [id=integer] builtin. |
hooks.server.ts | +route.v + src/app.v | Subtree 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.tsforadmin.svelte) exportsload({ params, props, url })— a sync view-model transform inside render (async only whenssr = false). Noparent()— 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 viaswelte_error(status, msg)(V) /swelteError(status, msg)(TS);isRedirect(e)narrows 3xx. - No
fail(422, …)helper — throw!Twith a{ ok: false, fieldErrors }body, narrow withisFail(e).
Client router
- History-driven: link-click interception (incl.
data-sveltekit-reload/data-swelte-reloadfull-reload,...-noscroll/...-noreplace/...-preload-data/...-preload-codeoffhonored) + 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.statesurvives traversal, never sent to the server).captureSnapshot(fn)/restoreSnapshot(fn)(manualexport const snapshotlite — captured ongoto, replayed onpopstate);beforeNavigate(cancellable viacancel()) /afterNavigate/onNavigate;page/navigating/updatedstores (checkUpdated()flipsupdatedby polling theX-Swelte-Versionheader).- Layout composition (
export const layout = false | true | 'dir'in the sibling.ts— no@files):admin/login/+page.tswithlayout = falserenders bare;'admin'keeps wrappers down toadmin;truepins 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) andcsr = false(SSR HTML only — the client mount/hydrate is a no-op). Independent corners, same sibling.tscarrier. - Per-page
prerender = true | false | 'auto'(leaf wins, else nearest explicit wrapper, else globalprerender.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/imagesmetadata. serializedHeaders = [...]allowlists which load-envelope headers land on the HTML navigation (Set-Cookieuntouched,Locationalways passes). Per-routeRouteId+Paramstypes (the$types-lite). Per-routelimitsoverride the global hardening knobs (single binary, no regions/runtime).
Errors & platform
- Directory
+error.svelteboundaries 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|navigationadapt 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.