Forms + fail + deserialize
No actions{} namespace. One default fn per verb per file, ?q qualifiers for many-per-file. Same handler serves no-JS and fetch — content-negotiated.
Verbs + ?q
<form action="?delete" method="post">@[post('delete')]
pub fn delete_account(req SwelteRequest) !string { ... }No-JS
Browser navigations (Accept: text/html) bypass JSON: success → 303 + Location, failure → the target page rendered with form data and its failure status.
Fetch keeps JSON. GET loads may independently redirect through their load envelope.
Fail-lite
save_name({ name }).catch((e) => { if (isFail(e)) showInline(e) })Convention: throw !T with a { ok: false, fieldErrors } JSON
body; narrow client-side with isFail(e, status?).
use:enhance
<script>import { enhance } from '@swelte/core';</script>
<form method="post" use:enhance>…</form>No-JS untouched. With JS, the submit replays as fetch and folds into page.form (failure stays inline, never page.error). applyAction(result) is also usable
standalone.
Named actions and compatibility
Set swelte.actionQuery: 'named' to use ?/save. Named actions preserve search parameters such as q; ?/save&q=hello redirects to ?q=hello on no-JS success. Legacy mode retains ?q=save and ?save. swelte.compat: 'sveltekit' selects named actions by default and supplies nested data/form props, reactive $app/state and the $app/forms adapter.
Submission lifecycle
Enhancement prevents native submission synchronously. Cancellation stops submission; submitter overrides and multipart file bytes are retained. Failures stay inline. Success can reset the form and awaits the current page's load refresh, preserving component state. Cross-page submissions do not overwrite unrelated form state. The native callback API remains available; the compatibility adapter supplies result and update fields.