---
name: svelte5-best-practices
description: "Svelte 5 runes, snippets, SvelteKit patterns, and modern best practices for TypeScript and component development. Use when writing, reviewing, or refactoring Svelte 5 components and SvelteKit applications. Triggers on: Svelte components, runes ($state, $derived, $effect, $props, $bindable, $inspect), snippets ({#snippet}, {@render}), event handling, SvelteKit data loading, form actions, Svelte 4 to Svelte 5 migration, store to rune migration, slots to snippets migration, TypeScript props typing, generic components, SSR state isolation, performance optimization, or component testing."
license: MIT
metadata:
  author: ejirocodes
  version: '1.0.0'
title: svelte5-best-practices
canonical_url: https://skilld.dev/gh/ejirocodes/agent-skills/svelte5-best-practices
last_updated: 2026-09-27T07:25:11.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/events.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/events.md), [references/migration.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/migration.md), [references/performance.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/performance.md), [references/runes.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/runes.md), [references/snippets.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/snippets.md), [references/sveltekit.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/sveltekit.md), [references/typescript.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/typescript.md).
>
> If the user asked to install this Skill, run `npx skilld install ejirocodes/agent-skills/svelte5-best-practices`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/svelte5-best-practices`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/ejirocodes/agent-skills/svelte5-best-practices) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/svelte5-best-practices`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/svelte5-best-practices --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/svelte5-best-practices --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Svelte 5 Best Practices

## Quick Reference

| Topic | When to Use | Reference |
|-------|-------------|-----------|
| **Runes** | $state, $derived, $effect, $props, $bindable, $inspect | [runes.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/runes.md) |
| **Snippets** | Replacing slots, {#snippet}, {@render} | [snippets.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/snippets.md) |
| **Events** | onclick handlers, callback props, context API | [events.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/events.md) |
| **TypeScript** | Props typing, generic components | [typescript.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/typescript.md) |
| **Migration** | Svelte 4 to 5, stores to runes | [migration.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/migration.md) |
| **SvelteKit** | Load functions, form actions, SSR, page typing | [sveltekit.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/sveltekit.md) |
| **Performance** | Universal reactivity, avoiding over-reactivity, streaming | [performance.md](https://skilld.dev/api/skills-raw/ejirocodes/agent-skills/svelte5-best-practices/references/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. **Using `let` without `$state`** - Variables are not reactive without `$state()`
2. **Using `$effect` for derived values** - Use `$derived` instead
3. **Using `on:click` syntax** - Use `onclick` in Svelte 5
4. **Using `createEventDispatcher`** - Use callback props instead
5. **Using `<slot>`** - Use snippets with `{@render}`
6. **Forgetting `$bindable()`** - Required for `bind:` to work
7. **Setting module-level state in SSR** - Causes cross-request leaks
8. **Sequential awaits in load functions** - Use `Promise.all` for parallel requests
