In a .NET 10 Blazor Web App, what are the four render modes, where does each run a component's code, and what does each cost?
answer
- no @rendermode means not interactive
- a circuit over a SignalR connection
- the .NET runtime downloaded to the browser
- Auto: Server first, WebAssembly once cached
- RenderMode.InteractiveServer and its two siblings
basics
~20 sA Blazor Web App renders each component as static SSR (server HTML, no interactivity), Interactive Server (events handled on the server over a SignalR circuit), Interactive WebAssembly (the .NET runtime runs in the browser) or Interactive Auto (Server first, WebAssembly once the bundle is cached).
solid answer
~50 sWith no `@rendermode` anywhere above it, a component is **static SSR**: the server renders it to HTML for one request and keeps nothing alive, so `@onclick` does nothing. `InteractiveServer` keeps the component on the server and exchanges UI events and DOM diffs with the browser over a SignalR connection, the **circuit** - quick first interaction and direct server access, but every event is a network round trip and every connected user holds server memory. `InteractiveWebAssembly` downloads the .NET runtime and the app's assemblies and runs the component in the browser - no per-user server state and no round trip per click, but a larger first download, code built in the `.Client` project, and data reached through an HTTP API. `InteractiveAuto` starts on Server and uses WebAssembly on later visits once the files are cached; it never moves a component that is already on the page. All three interactive modes prerender by default.
code
razor · 12 lines@page "/leave-balance"
@rendermode InteractiveServer
<h3>Leave balance</h3>
<p>Days left: @daysLeft</p>
<button @onclick="Refresh">Refresh</button>
@code {
private int daysLeft = 12;
private void Refresh() => daysLeft = 12;
}go deeper
Name the four modes and say which ones respond to clicks. Remember that a component with no render mode anywhere above it is static and its event handlers never run.
Explain the circuit, the WebAssembly download and the .Client project, and walk through what Auto does on a first visit versus a later one. Mention that all interactive modes prerender by default.
Argue the latency, memory-per-user, offline and data-access costs of each mode for a concrete page, and explain why Auto doubles the testing and security surface.
Frame render modes as a per-page budget: server memory and connection count against download size and API surface, and set rules so teams do not mix runtimes on one page by accident.
## What a render mode decides A **Blazor Web App** (the `blazor` template since .NET 8) can render every Razor component in one of four ways. The **render mode** decides three things for a component and everything below it: **where its C# runs** (server or browser), **whether it is interactive** (whether `@onclick`, `@bind` and other event handlers do anything), and **how it gets to the page**. A mode is set with the `@rendermode` directive on a component definition (`@rendermode InteractiveServer` under `@page`) or the `@rendermode` directive attribute on a component instance (`<LeaveRequestForm @rendermode="InteractiveWebAssembly" />`). The short names come from the static class `Microsoft.AspNetCore.Components.Web.RenderMode`, which the template imports with `@using static` in `_Imports.razor`. ## The four modes side by side | Mode | How you select it | Where C# runs | Interactive | Main cost | |---|---|---|---|---| | Static server (static SSR) | no render mode anywhere above the component | server, once per request | no | every interaction is a full HTTP request (a link or a form post) | | Interactive Server | `InteractiveServer` | server, inside a circuit | yes | a round trip per UI event; server memory per connected user | | Interactive WebAssembly | `InteractiveWebAssembly` | browser, on the .NET WebAssembly runtime | yes | download of runtime and assemblies; data only through an API | | Interactive Auto | `InteractiveAuto` | server on first visit, browser later | yes | both of the above to build, test and secure | `RenderMode.InteractiveServer`, `RenderMode.InteractiveWebAssembly` and `RenderMode.InteractiveAuto` are pre-built instances of `InteractiveServerRenderMode`, `InteractiveWebAssemblyRenderMode` and `InteractiveAutoRenderMode`. Each type's parameterless constructor sets `Prerender` to `true`, so all three interactive modes first send prerendered HTML from the server. ## Interactive Server and Interactive WebAssembly in more detail - **Interactive Server** creates a **circuit**: a server-side object graph holding the user's component instances and scoped services, connected to the browser by SignalR (normally a WebSocket). A click is sent to the server, the handler runs there, and Blazor sends back only the changed DOM fragments. The component can use any server service directly - a `DbContext` factory, the file system, an internal API - because it never leaves the server. - **Interactive WebAssembly** runs the component on the .NET runtime compiled to WebAssembly in the browser tab. The component must be built from the **client project** (the template's `.Client` project, which uses the `Microsoft.NET.Sdk.BlazorWebAssembly` SDK), its assemblies are downloaded and cached by the browser, and anything it needs from the server goes through `HttpClient`. Everything shipped there - code and configuration - is readable by the user, so it can hold no secrets. ## How Interactive Auto chooses Auto is decided in the browser by `blazor.web.js` when an Auto component appears on the page: 1. If WebAssembly components already exist on the page, Auto picks WebAssembly; if Server components exist, it picks Server, so the page does not run two runtimes that share no state. 2. Otherwise, if the WebAssembly runtime has already loaded, it picks WebAssembly. 3. Otherwise it compares a hash of the WebAssembly boot resources with one stored in `localStorage` on an earlier successful load. No match (first visit, new deployment, cleared storage) means the files are probably not cached, so the component starts on **Server** at once. 4. The WebAssembly files keep downloading in the background - when an Auto component started that download, limited to one parallel download so the circuit is not starved - and the hash is stored when they finish. Once a component is interactive it keeps its mode for as long as it stays on the page; the switch to WebAssembly happens on a later page load, not under a live component. ## The costs interviewers probe - **Latency:** Interactive Server pays a network round trip on every event, which is invisible on a LAN and obvious on a mobile connection; WebAssembly pays once, at startup. - **Scale:** each Interactive Server user holds a circuit in server memory and an open connection; WebAssembly users cost the server only their API calls. - **Offline and flaky networks:** an Interactive Server component stops responding when the connection drops and the page shows reconnection UI; a WebAssembly component keeps handling events locally and only its HTTP calls fail; static SSR needs the server for every navigation. - **Data access and security:** Server components call services directly; WebAssembly and Auto components need an authenticated API and must treat their own code as public. - **Build shape:** WebAssembly and Auto components live in the `.Client` project, and an Auto component must work correctly in both places.
- How does Interactive Auto know on a later visit that the WebAssembly files are cached?After a successful WebAssembly load, `blazor.web.js` stores a hash of the boot resources in `localStorage`. On the next page load it compares that hash with the current one. A match means the files are likely in the browser cache, so Auto components start on WebAssembly; no match - a first visit, a new deployment or cleared storage - makes them start on Server immediately while the download continues in the background.
- Why must InteractiveWebAssembly and InteractiveAuto components live in the .Client project?Only assemblies built by the client project are downloaded to the browser. The template's `.Client` project uses the `Microsoft.NET.Sdk.BlazorWebAssembly` SDK, and the server project chains `AddAdditionalAssemblies(typeof(Client._Imports).Assembly)` onto `MapRazorComponents<App>()` so it can route to and prerender those components too. A component compiled only into the server project can never run in the browser.
- What does each mode do when the user's network drops for a minute?Static SSR pages already on screen stay readable, but the next link or form post fails. Interactive Server components stop reacting because their handlers run on the server; the page shows its reconnection UI (the .NET 10 template ships a `ReconnectModal` component) and tries to reconnect. Interactive WebAssembly components keep handling clicks locally; only their HTTP calls fail until the network returns.
- Interactive Server runs the component in the browser and only fetches data from the server.
- A page without @rendermode is interactive because the template enables Server interactivity.
- Interactive Auto moves a live component from the server to WebAssembly when the download finishes.
- Interactive WebAssembly components can use the server's DbContext directly, like Server components.
- Interactive Server costs no server memory per user because SignalR connections are stateless.