Skip to main content

Runtime for Sveltes

The runtime side of Svelte covers how a component lives and shares data over time. Lifecycle functions such as onMount run code when a component appears on the page, and the context API lets a parent offer values to descendants via setContext and getContext without passing props through every level.

Stage: Component Patterns · Part of the Svelte roadmap · Last reviewed 19 November 2026

What to learn in Runtime

Runtime interview questions

Why does onMount not run during server-side rendering?

onMount runs only in the browser after the component is attached to the DOM. During server rendering there is no DOM, so it is skipped. That makes it the right place for code that touches window, document or browser-only libraries.

When would you use context instead of props in Svelte?

Use context when many nested components need the same value, such as a theme or a form controller, and threading props through each layer would be noisy. For direct parent-child data, props remain clearer and easier to trace.

Where Runtime fits in the Svelte roadmap

Runtime belongs to the Component Patterns stage (intermediate level). Compose and share.

Back to the full Svelte roadmap