From 1d09fcfcf87472d2564ce05c3a59cca6bdf25e3f Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 13 Aug 2025 16:43:34 +0200 Subject: [PATCH] docs: llm docs for await + remote functions --- .../routes/llms-small.txt/content-svelte.md | 66 +++++ .../llms-small.txt/content-sveltekit.md | 230 ++++++++++++++++++ 2 files changed, 296 insertions(+) diff --git a/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md b/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md index 175b7e3de0..34dcb781e9 100644 --- a/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md +++ b/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md @@ -294,6 +294,72 @@ let { a, b, ...others } = $props(); - Do **NOT** use this unless you are explicitly tasked to create a custom element using Svelte components +### Using await in Svelte + +- **Where you can use await** + + - **Top-level ` + + +``` + +- Alternative props exist (`loading`, `error`, `current`) if you don’t use `await`. + +### form: mutation via forms + +Define: + +```js +import { form } from '$app/server'; +import * as db from '$lib/server/database'; +import * as auth from '$lib/server/auth'; +import { error, redirect } from '@sveltejs/kit'; + +export const createPost = form(async (data) => { + const user = await auth.getUser(); + if (!user) error(401, 'Unauthorized'); + + const title = data.get('title'); + const content = data.get('content'); + db.insertPost(title, content); + + redirect(303, `/blog/${title}`); +}); +``` + +Use: + +```svelte + + +
+ +