spences10 avatar

Sveltekit Data Flow

This is a quick reference for SvelteKit's data loading and form handling patterns. It covers the essential decision points: when to use +page.server.ts versus +page.ts, how to structure load functions, and the proper way to handle form actions with fail(), redirect(), and error(). The included example shows a typical server-side load with form action, and it links out to deeper references on serialization rules and invalidation patterns. It's lean by design, meant to be the cheat sheet you keep open while wiring up routes, not a full tutorial. Good for when you know SvelteKit basics but need to double check the data flow conventions.

skills.sh installs
512
GitHub stars
95
last updated
Aug 21, 2026

Install

$ npx -y skills add spences10/svelte-skills-kit --skill sveltekit-data-flow --agent claude-code

Installs into .claude/skills of the current project.

Files

SvelteKit Data Flow

Quick Start

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

Sponsors

Details

Repository
github.com/spences10/svelte-skills-kit
Categories
Frontend Development, Backend & APIs, Debugging
First seen
Jun 3, 2026

More from spences10/svelte-skills-kit

All 8
1webflow avataraccessibility-auditwebflow/webflow-skillsRun comprehensive accessibility audit (WCAG 2.1) on Webflow pages - checks buttons, forms, links, focus states, headings, keyboard navigation, and generates det486skills.sh installs
2spences10 avatarsveltekit-remote-functionsspences10/svelte-skills-kitSvelteKit remote functions guidance. Use for query(), form(), command(), and prerender() patterns in .remote.ts files.430skills.sh installs
3webflow avatarcms-best-practiceswebflow/webflow-skillsExpert guidance on Webflow CMS architecture and best practices. Use when planning collections, setting up relationships, optimizing content structure, or troubl419skills.sh installs
4syncfusion avatarsyncfusion-blazor-licensesyncfusion/blazor-ui-components-skillsGenerate, register, secure, validate, and troubleshoot Syncfusion Blazor license keys across all Blazor project types403skills.sh installs
5syncfusion avatarsyncfusion-blazor-datamanagersyncfusion/blazor-ui-components-skillsImplements Syncfusion Blazor SfDataManager for data access, data binding, and adaptor configuration in Blazor Server, WebAssembly, and Web App. Used when bindin395skills.sh installs
6syncfusion avatarsyncfusion-blazor-accumulation-chartsyncfusion/blazor-ui-components-skillsImplement Syncfusion Blazor Accumulation Chart (SfAccumulationChart) for proportional data visualization. Use this when creating pie charts, doughnut charts, fu393skills.sh installs