sveltekit-data-flow
SvelteKit data flow guidance. Use when working with load functions, form actions, server/client boundaries, serialization, or invalidation.
- License 许可
- MIT
- 最近更新
- 2026-08-04
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- sveltekit-data-flow
- metadata
- { "last_updated": "2026-06-08", "verified_against": "Svelte 5/Kit docs and sveltejs/kit#15934" }
- description
- SvelteKit data flow guidance. Use when working with load functions, form actions, server/client boundaries, serialization, or invalidation.
02 资源文件 6
- 参考文档references/client-auth-invalidation.md3.0 KB
- 参考文档references/error-redirect-handling.md9.4 KB
- 参考文档references/explicit-environment-variables.md1.7 KB
- 参考文档references/form-actions.md5.6 KB
- 参考文档references/load-functions.md6.5 KB
- 参考文档references/serialization.md7.4 KB
03 SKILL.md 正文
SvelteKit Data Flow
Quick Start
Environment variables: Prefer explicit env vars (src/env.ts + $app/env/private|public) when the experimental flag is enabled.
Which file? Server-only (DB/secrets): +page.server.ts |
Universal (runs both): +page.ts | API: +server.ts
Load decision: Need server resources? → server load | Need client APIs? → universal load
Form actions: Always +page.server.ts. Return fail() for
errors, throw redirect() to navigate, throw error() for failures.
Example
// +page.server.ts
import { fail, redirect } from '@sveltejs/kit';
export const load = async ({ locals }) => {
const user = await db.users.get(locals.userId);
return { user }; // Must be JSON-serializable
};
export const actions = {
default: async ({ request }) => {
const data = await request.formData();
const email = data.get('email');
if (!email) return fail(400, { email, missing: true });
await updateEmail(email);
throw redirect(303, '/success');
},
};
Reference Files
- load-functions.md - Server vs universal
- form-actions.md - Form handling patterns
- serialization.md - What can/can't serialize
- error-redirect-handling.md - fail/redirect/error
- client-auth-invalidation.md - invalidateAll() after client-side auth
- explicit-environment-variables.md - typed, validated env vars
Notes
- Server load → universal load via
dataparam | ALWAYSthrow redirect()/error() - No class instances/functions from server load (not serializable)
$app/env/privateis server-only; only mark genuinely safe values as public- Last verified: 2026-06-08
<!-- PROGRESSIVE DISCLOSURE GUIDELINES:
- Keep this file ~50 lines total (max ~150 lines)
- Use 1-2 code blocks only (recommend 1)
- Keep description <200 chars for Level 1 efficiency
- Move detailed docs to references/ for Level 3 loading
- This is Level 2 - quick reference ONLY, not a manual
LLM WORKFLOW (when editing this file):
04 同仓库更多 Skills
sveltekit-structure
SvelteKit structure guidance. Use for routing, layouts, error handling, SSR, or svelte:boundary. Covers file naming, nested layouts, error boundaries, pending UI, and hydration.
svelte-template-directives
Svelte template directive guidance. Use when working with snippets, attachments, dynamic HTML, declaration tags, debugging tags, or global DOM events.
svelte-styling
Svelte CSS styling patterns. Use for scoped styles, CSS custom properties, style: directive, :global, or styling child components.
svelte-runes
Implement Svelte 5 runes correctly. Use for reactive state, props, effects, $state.raw, $derived.by, $props, and $bindable.
svelte-layerchart
Build Svelte LayerChart components. Use for tooltip snippets, Chart context access, gradients, highlights, axes, and Svelte 5 snippet patterns.
svelte-core-bestpractices
Svelte 5 core best practices. Use when creating, editing, or reviewing .svelte, .svelte.ts, or .svelte.js files. Routes to deeper Svelte skills.