SvelteKit data flow guidance. Use for load functions, form actions, and server/client data. Covers +page.server.ts vs +page.ts, serialization, fail(), redirect(), error().
This skill inherits all available tools. When active, it can use any tool Claude has access to.
README.mdreferences/error-redirect-handling.mdreferences/form-actions.mdreferences/load-functions.mdreferences/serialization.mdWhich 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.
// +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');
},
};
data param | ALWAYS
throw redirect()/error()