Svelte flag ceremony: 20 levels predicting how often the $state, $derived, $effect, $effect.pre and $effect.root runes fire, on a runtime built from scratch.
In Svelte 5, let x = $state(initial) makes a reactive value you read and write like a plain variable; the compiler turns each write into a signal. $effect(() => …) runs once after the component mounts, then again after any write that changes a value it read, once per turn (flush).
An object or array inside $state becomes a deep proxy: every property that is read gets its own signal, the properties of nested objects too. An effect runs again only when a property it read changes, or when the object holding it is replaced.
let d = $derived(expression) makes a derived value. It is computed when first read, kept, and computed again only when its source changed and someone reads it again. A derived nobody reads is never computed.
$effect may return a function. That function runs before the effect runs again, and when its component is removed (the tent struck). The usual pattern: open a subscription in the effect's body, close it in the cleanup.
$effect.root(fn) makes an effect root of its own, outside the component tree. The effects inside it are not cleaned up when a component is removed; call the function $effect.root returns to stop them. Good for an effect that lives longer than a component.
The Svelte compiler only processes .svelte files and modules ending in .svelte.js or .svelte.ts. There runes may be used, at module level too. A plain .js file is passed through as it is, so a rune in it is not a compile error but a name nobody knows at run time.