skip to content

Render Mode Choice

Blazor Web App components render as static SSR or interactively on Server, WebAssembly or Auto, set by @rendermode and prerendered by default. Interviewers probe latency, scale and offline trade-offs.

on this pageshow

explore

questions

6

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?

level: middleimportance: must knowfreq 74%

answer

  1. no @rendermode means not interactive
  2. a circuit over a SignalR connection
  3. the .NET runtime downloaded to the browser
  4. Auto: Server first, WebAssembly once cached
  5. RenderMode.InteractiveServer and its two siblings

basics

~20 s

A 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 s

With 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
razor
@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

for a junior

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.

for a middle

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.

for a senior

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.

for a principal

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.
open as a page

In a Blazor Web App, what does prerendering do to an interactive component, what problems follow, and how do you detect or disable it?

level: middleimportance: must knowfreq 62%

basics

~20 s

Prerendering renders an interactive component to HTML on the server first, so content appears before interactivity starts. The component is then created again when it becomes interactive, which doubles initialization and breaks client-only services; detect it with RendererInfo, disable it with prerender: false.

open as a page

In a Blazor Web App, why does a button's @onclick never run on a page without @rendermode, and what fixes it?

level: juniorimportance: should knowfreq 58%

basics

~20 s

Without a render mode the page is static SSR: the server sends finished HTML and discards the component, so nothing is left to run the handler. Give the page an interactive render mode, and make sure Program.cs registers that mode's services and endpoints.

open as a page

In a Blazor Web App, what does [StreamRendering] change when a statically rendered page awaits slow data in OnInitializedAsync?

level: middleimportance: should knowfreq 34%

basics

~20 s

Without it the server waits for the page's async work before sending any HTML. With [StreamRendering] it sends the first render (for example a loading message) at once, then streams the finished markup later in the same response, which blazor.web.js patches into place.

open as a page

In a Blazor Web App, why does a static page that passes ChildContent to a child with @rendermode InteractiveServer throw, and what other render-mode boundary rules apply?

level: seniorimportance: should knowfreq 38%

basics

~20 s

A render mode on a child starts a new boundary whose parameters are serialized into the page for the interactive runtime. A RenderFragment is a delegate, arbitrary code, so it cannot be serialized and Blazor throws an InvalidOperationException.

open as a page

For an employee self-service portal built as a .NET 10 Blazor Web App, mostly static pages plus a few interactive widgets, how would you choose render modes?

level: principalimportance: should knowfreq 30%

basics

~20 s

Default to static SSR for read-mostly pages and put an interactive mode only on the widgets that need it, choosing Server, WebAssembly or Auto from latency, concurrent users, offline needs and data access. Revisit if most pages become interactive or the portal must work offline.

open as a page