---
name: "sveltekit-form-actions-load"
description: "Implement resilient, progressive web applications using SvelteKit load functions and Form Actions."
metadata:
  author: "Svelte"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "write sveltekit form action"
  - "sveltekit server load function"
  - "use:enhance sveltekit"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# SvelteKit Form Actions & Load Function Architecture

Architects SvelteKit pages: server load functions (+page.server.ts), form actions (default and named actions), progressive enhancement with use:enhance, fail() for validation errors, and invalidating data with invalidate().

## When to Invoke
Invoke this skill whenever you need to:
- write sveltekit form action
- sveltekit server load function
- use:enhance sveltekit

## Execution SOP & Rules
1. Define server loader in +page.server.ts: export const load = async ({ locals }) => ({ user: locals.user }).
2. Define form action: export const actions = { default: async ({ request }) => { ... return { success: true }; } }.
3. Enhance form in +page.svelte: <form method='POST' use:enhance>.
4. Use returned form prop ({form?.errors}) to display validation feedback without page refresh.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
