mcpField
S
sveltekit-data-flow

sveltekit-data-flow

github.com/spences10Development1693 installsUpdated 16w ago
Repository

About sveltekit-data-flow

A coding skill for SvelteKit developers covering data loading, form handling, and error control. It maps server-only and universal logic to route files and documents serialization and environment-variable practices.

Key features

  1. 01Distinguishes server and universal load
  2. 02Explains form action patterns
  3. 03Covers errors and redirects
  4. 04Documents serialization limits
  5. 05Guides explicit environment variables

Use cases

  1. 01Choose where page data loads
  2. 02Implement server-side form submissions
  3. 03Invalidate client data after authentication changes

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/spences10/skills --skill sveltekit-data-flow

After installing, type/sveltekit-data-flowin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
client-auth-invalidation.md
error-redirect-handling.md
explicit-environment-variables.md
form-actions.md
load-functions.md
serialization.md

Details

From the project README

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

Notes

  • Server load → universal load via data param | ALWAYS throw redirect()/error()
  • No class instances/functions from server load (not serializable)
  • $app/env/private is server-only; only mark genuinely safe values as public
  • Last verified: 2026-06-08

Comments

Markdown supported