--- name: svelte description: | Svelte 5 and SvelteKit framework patterns. Covers runes ($state, $derived, $effect, $props, $bindable, $inspect), snippets, fine-grained reactivity, component composition, and event handling. SvelteKit coverage includes file-based routing, server and universal load functions, form actions, hooks, adapters, and error handling. Includes Svelte 4 to 5 migration guidance (stores to runes, on:event to onevent, slots to snippets). Use when building Svelte 5 components, configuring SvelteKit routing, implementing form actions, migrating from Svelte 4, or debugging reactivity issues. license: MIT metadata: author: oakoss version: '1.0' source: 'https://svelte.dev/docs' user-invocable: false --- # Svelte ## Overview Svelte is a **compiler-based UI framework** that shifts work from runtime to build time, producing minimal JavaScript with no virtual DOM. Svelte 5 introduces runes for explicit, fine-grained reactivity. SvelteKit is the full-stack framework built on Svelte, providing file-based routing, server-side rendering, and deployment adapters. **When to use:** Full-stack web apps, static sites, progressive enhancement, SSR/SSG, projects needing small bundle sizes, migration from Svelte 4 to 5. **When NOT to use:** React/Vue ecosystem lock-in, projects requiring extensive third-party component libraries only available for other frameworks, teams with no Svelte experience on tight deadlines. ## Quick Reference | Pattern | API / Syntax | Key Points | | ------------------ | ------------------------------------------------------- | -------------------------------------------------- | | Reactive state | `let count = $state(0)` | Replaces `let` reactivity from Svelte 4 | | Derived state | `const double = $derived(count * 2)` | Replaces `$:` reactive declarations | | Complex derivation | `const value = $derived.by(() => { ... })` | Multi-statement derived computations | | Side effects | `$effect(() => { ... })` | Runs after DOM update, auto-tracks dependencies | | Component props | `let { name, age = 25 } = $props()` | Replaces `export let`, supports defaults | | Bindable props | `let { value = $bindable() } = $props()` | Two-way binding with `bind:value` | | Debug inspection | `$inspect(value)` | Dev-only logging, stripped in production | | Snippets | `{#snippet name(params)}...{/snippet}` | Replaces slots, reusable template blocks | | Render snippet | `{@render name(args)}` | Invoke a snippet with arguments | | Event handling | `