Under The Hood
frontend svelte Svelte 5 (runes mode)

Svelte 5 runes vs legacy let-based reactivity

Last updated
Prerequisites:
Svelte 4 component basics
Understanding of the Svelte compiler
  • svelte
  • runes
  • reactivity
  • signals
  • svelte5
  • compiler

Read at your depth

The practical view

In Svelte 4, reactivity was implicit and compiler-driven: let count = 0; created a reactive variable, and count += 1 updated the DOM. But that magic only worked inside .svelte component top-level scope. Svelte 5 introduces runes — explicit markers: let count = $state(0); creates reactive state anywhere (even in .js/.ts modules); $derived(expr) replaces the $: label; $effect(() => ...) replaces the reactive statement for side effects; and $props() replaces export let. Code written with runes works in plain modules, so state logic is extractable and testable outside components.

The same idea in other frameworks

react equivalent
const [count, setCount] = useState(0); // setCount triggers re-render

Legacy vs modern

Reactive state in a shared module: Svelte 4 vs runes

Svelte 4 reactivity only worked inside components; runes make state a first-class primitive usable in plain modules, extractable and testable.

before → after
Svelte 4 component-only state
<script>
  let count = 0; // implicit reactivity: compiler-scoped
  function inc() { count += 1; }
</script>
Runes module state
export let count = $state(0);
export function increment() { count += 1; }

Interview gotchas

Under The Hood — a multi-depth technical interview hub.

Press ⌘ K to search.