Overview

Svelte 5 introduces Runes — a universal, fine-grained reactivity system that replaces the Svelte 4 compiler-driven reactivity. This page documents production-ready patterns for Svelte 5 (v5.0+).

Key Findings

1. state.raw for large data only reassigned

2. derived.by for complex logic

3. $effect for side effects only — avoid state updates in effects, use event handlers instead

4. derived for computed prop values

5. Snippets replace slots: {#snippet name()}…{/snippet} rendered with {@render name()}

6. Event handlers: onclick not on:click, <svelte:window onkeydown={…}> for global events

7. {@attach} for external lib integration (D3, charts) — returns cleanup function

8. {@const} for template-scoped constants in each blocks

9. TypeScript: interface Props, $props(), Snippet<[Type]> for snippet types

Evolution Notes

Content last updated: 2026-06-07 Next review: 2026-06-14