# Svelte 5 Migration Guide
## Overview
This guide covers migrating from Svelte 4 to Svelte 5, with focus on the new Runes system which replaces the old reactive syntax.
---
## 🔄 Key Changes at a Glance
| Svelte 4 | Svelte 5 | Description |
|----------|----------|-------------|
| `let count = 0` | `let count = $state(0)` | Reactive state |
| `$: doubled = count * 2` | `let doubled = $derived(count * 2)` | Derived values |
| `$: { sideEffect() }` | `$effect(() => { sideEffect() })` | Side effects |
| `export let prop` | `let { prop } = $props()` | Component props |
| `
Card content
Card content
Main content
FooterMain content
{#snippet footer()} Footer {/snippet}Doubled: {$doubled}
// stores/counter.svelte.ts export class Counter { count = $state(0); doubled = $derived(this.count * 2); } // ComponentDoubled: {counter.doubled}
``` --- ## 🔧 Component Lifecycle ### onMount / onDestroy ```svelte ``` --- ## 📋 Migration Checklist ### Phase 1: Preparation - [ ] Update to latest Svelte 4.x - [ ] Fix all deprecation warnings - [ ] Ensure tests are passing - [ ] Review component inventory ### Phase 2: Upgrade - [ ] Update to Svelte 5 - [ ] Update SvelteKit (if using) - [ ] Update dependencies ### Phase 3: Migrate Components - [ ] Convert `export let` → `$props()` - [ ] Convert reactive declarations → `$derived()` - [ ] Convert reactive statements → `$effect()` - [ ] Convert slots → snippets - [ ] Convert events → callback props - [ ] Convert stores → class-based state ### Phase 4: Validation - [ ] Run all tests - [ ] Check for runtime errors - [ ] Performance testing - [ ] Accessibility audit --- ## 🛠️ Automated Migration Svelte 5 includes a migration script: ```bash # Run the migration script npx sv migrate svelte-5 # This will: # - Update syntax to Svelte 5 # - Convert reactive statements # - Update event handlers # - Flag manual review items ``` **Note:** Always review automated changes and test thoroughly!