Agent skill
frontend-svelte5-best-practices
Svelte 5 runes, snippets, SvelteKit patterns, and modern best practices. Use when creating, editing, reviewing, or refactoring .svelte components, .svelte.ts/.svelte.js modules, or SvelteKit applications. Triggers on: runes ($state, $derived, $effect, $props, $bindable, $inspect), snippets ({#snippet}, {@render}), event handling, SvelteKit data loading, form actions, Svelte 4→5 migration, TypeScript props, generic components, SSR state isolation, performance, or component testing.
Install this agent skill to your Project
npx add-skill https://github.com/jasonraimondi/dotfiles/tree/macos/config/skillshare/skills/frontend-svelte5-best-practices
Metadata
Additional technical details for this skill
- author
- ejirocodes
- version
- 2.1.0
SKILL.md
Svelte 5 Best Practices
Workflow
Follow this sequence when working on Svelte 5 code:
- Check project version — Inspect
package.jsonfor Svelte version. If < 5, consult migration.md before writing any code. - Read relevant references — Before writing or modifying a component, read the reference file(s) matching your task from the table below.
- Write code — Apply patterns from references and the quick patterns below.
- Validate — Run the autofixer on modified components:
bash
npx @sveltejs/mcp svelte-autofixer ./src/lib/Component.svelte
CLI Tools
npx @sveltejs/mcp list-sections # List doc sections
npx @sveltejs/mcp get-documentation "$state,$derived,$effect" # Fetch specific docs
npx @sveltejs/mcp svelte-autofixer ./path/Component.svelte # Validate component (escape $ as \$)
Reference Lookup
Read the matching file before writing code for that topic.
| Topic | When to Read | File |
|---|---|---|
| Runes | $state, $derived, $effect, $props, $bindable, $inspect | runes.md |
| Snippets | Replacing slots, {#snippet}, {@render} | snippets.md |
| Events | onclick handlers, callback props, context API | events.md |
| TypeScript | Props typing, generic components | typescript.md |
| Migration | Svelte 4→5, stores→runes, slots→snippets | migration.md |
| SvelteKit | Load functions, form actions, SSR, page typing | sveltekit.md |
| Performance | Universal reactivity, avoiding over-reactivity, streaming | performance.md |
Essential Patterns
Reactive State
<script>
let count = $state(0); // Reactive state
let doubled = $derived(count * 2); // Computed value
</script>
Component Props
<script>
let { name, count = 0 } = $props();
let { value = $bindable() } = $props(); // Two-way binding
</script>
Snippets (replacing slots)
<script>
let { children, header } = $props();
</script>
{@render header?.()}
{@render children()}
Event Handlers
<!-- Svelte 5: use onclick, not on:click -->
<button onclick={() => count++}>Click</button>
Callback Props (replacing createEventDispatcher)
<script>
let { onclick } = $props();
</script>
<button onclick={() => onclick?.({ data })}>Click</button>
Common Mistakes
letwithout$state— Variables are not reactive without$state()$effectfor derived values — Use$derivedinsteadon:clicksyntax — Useonclickin Svelte 5createEventDispatcher— Use callback props instead<slot>— Use snippets with{@render}- Missing
$bindable()— Required forbind:to work - Module-level state in SSR — Causes cross-request data leaks
- Sequential awaits in load — Use
Promise.allfor parallel requests - Mixing Svelte 4/5 patterns — Check project version first; don't mix syntaxes
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
tools-image-manipulation-image-magick
Process and manipulate images using ImageMagick. Supports resizing, format conversion, batch processing, and retrieving image metadata. Use when working with images, creating thumbnails, resizing wallpapers, or performing batch image operations.
frontend-react-doctor
Run after making React changes to catch issues early. Use when reviewing code, finishing a feature, or fixing bugs in a React project.
typescript-advanced-types
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.
typescript-better-auth-best-practices
Skill for integrating Better Auth - the comprehensive TypeScript authentication framework.
testing-tdd
Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.
planning-interview-me
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "interview me".
Didn't find tool you were looking for?