Sveltekit data flow
SvelteKit data flow guidance. Use when working with load functions, form actions, server/client boundaries, serialization, or invalidation.From its SKILL.md
npx -y skills add spences10/skills --skill sveltekit-data-flowAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 15 stars15 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.7 KB, 606 tokens by cl100k_base, as published. Nobody here has run it
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
What ships with it: 6 files
33.7 KB alongside SKILL.md
references/
- client-auth-invalidation.md3.0 KB
- error-redirect-handling.md9.4 KB
- explicit-environment-variables.md1.7 KB
- form-actions.md5.6 KB
- load-functions.md6.5 KB
- serialization.md7.4 KB