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.

Stars 18
Forks 0

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:

  1. Check project version — Inspect package.json for Svelte version. If < 5, consult migration.md before writing any code.
  2. Read relevant references — Before writing or modifying a component, read the reference file(s) matching your task from the table below.
  3. Write code — Apply patterns from references and the quick patterns below.
  4. Validate — Run the autofixer on modified components:
    bash
    npx @sveltejs/mcp svelte-autofixer ./src/lib/Component.svelte
    

CLI Tools

bash
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

svelte
<script>
  let count = $state(0);            // Reactive state
  let doubled = $derived(count * 2); // Computed value
</script>

Component Props

svelte
<script>
  let { name, count = 0 } = $props();
  let { value = $bindable() } = $props(); // Two-way binding
</script>

Snippets (replacing slots)

svelte
<script>
  let { children, header } = $props();
</script>

{@render header?.()}
{@render children()}

Event Handlers

svelte
<!-- Svelte 5: use onclick, not on:click -->
<button onclick={() => count++}>Click</button>

Callback Props (replacing createEventDispatcher)

svelte
<script>
  let { onclick } = $props();
</script>

<button onclick={() => onclick?.({ data })}>Click</button>

Common Mistakes

  1. let without $state — Variables are not reactive without $state()
  2. $effect for derived values — Use $derived instead
  3. on:click syntax — Use onclick in Svelte 5
  4. createEventDispatcher — Use callback props instead
  5. <slot> — Use snippets with {@render}
  6. Missing $bindable() — Required for bind: to work
  7. Module-level state in SSR — Causes cross-request data leaks
  8. Sequential awaits in load — Use Promise.all for parallel requests
  9. Mixing Svelte 4/5 patterns — Check project version first; don't mix syntaxes

Expand your agent's capabilities with these related and highly-rated skills.

jasonraimondi/dotfiles

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.

18 0
Explore
jasonraimondi/dotfiles

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.

18 0
Explore
jasonraimondi/dotfiles

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.

18 0
Explore
jasonraimondi/dotfiles

typescript-better-auth-best-practices

Skill for integrating Better Auth - the comprehensive TypeScript authentication framework.

18 0
Explore
jasonraimondi/dotfiles

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.

18 0
Explore
jasonraimondi/dotfiles

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".

18 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results