On Blazor Interactive Server, what happens to a user's circuit and cake basket when the connection drops, and what do CircuitOptions and .NET 10 circuit persistence change?
answer
- reconnect UI, then the same circuit
- DisconnectedCircuitRetentionPeriod = 3 minutes
- DisconnectedCircuitMaxRetained = 100
- .NET 10: evicted circuit state persisted
- 1,000 circuits for 2 hours in memory
basics
~20 sThe server keeps a disconnected circuit, by default up to 100 for 3 minutes, while the reconnect UI retries; reconnecting in time loses nothing. In .NET 10, an evicted or paused circuit's [PersistentState] values can resume into a new circuit unless the page reloads.
solid answer
~40 sWhen the SignalR connection drops, the browser shows the reconnection UI (in the .NET 10 template, the `ReconnectModal` component) and retries, while the server keeps the circuit in a disconnected list. `CircuitOptions.DisconnectedCircuitRetentionPeriod` (3 minutes) and `DisconnectedCircuitMaxRetained` (100) bound that list; reconnect within them and the full in-memory state, components and scoped basket included, is still there. Before .NET 10, an evicted circuit was simply disposed and the user got a fresh one. In ASP.NET Core 10, eviction or an explicit `Blazor.pauseCircuit()` first saves the circuit's `[PersistentState]` properties: in memory by default (`PersistedCircuitInMemoryMaxRetained` 1,000, `PersistedCircuitInMemoryRetentionPeriod` 2 hours) or in a configured `HybridCache` (8 hours by default). A later reconnect resumes into a new circuit with those values, as long as the page was not fully reloaded. Only marked, JSON-serializable state comes back.
code
csharp · 8 lines// Program.cs
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(options =>
{
options.DisconnectedCircuitRetentionPeriod = TimeSpan.FromMinutes(5);
options.DisconnectedCircuitMaxRetained = 200;
options.PersistedCircuitInMemoryRetentionPeriod = TimeSpan.FromHours(4);
});go deeper
Recall that a dropped connection shows a reconnect UI and the server keeps the circuit for a limited time.
Explain DisconnectedCircuitRetentionPeriod and DisconnectedCircuitMaxRetained, and what the user sees after eviction.
Use .NET 10 circuit persistence with [PersistentState], RegisterPersistentService and HybridCache, and tune retention against memory.
Balance reconnect windows, persisted-state stores and farm topology against memory cost and user expectations on mobile networks.
## Two layers of protection An Interactive Server user's state lives in server memory inside a **circuit**. When the network blips, a mobile browser suspends the tab, or a laptop sleeps, the SignalR connection drops while the circuit's state is still on the server. ASP.NET Core 10 offers two layers to bring the user back: | Layer | What is kept | Where | Defaults | |---|---|---|---| | Disconnected circuit retention | The whole circuit: components, render tree, scoped services | Server memory | `DisconnectedCircuitMaxRetained` = 100, `DisconnectedCircuitRetentionPeriod` = 3 minutes | | Circuit state persistence (new in 10) | Only `[PersistentState]` properties of components and registered services | In-memory store, or `HybridCache` when configured | `PersistedCircuitInMemoryMaxRetained` = 1,000, `PersistedCircuitInMemoryRetentionPeriod` = 2 hours, `PersistedCircuitDistributedRetentionPeriod` = 8 hours | ## Layer 1: reconnecting to the same circuit 1. The connection drops. The browser shows the reconnection UI; the Blazor Web App template in .NET 10 ships a `ReconnectModal` component for it. 2. The client retries. The server marks the circuit disconnected and keeps it in a bounded list. 3. If the client reconnects before the retention period ends, and the circuit has not been pushed out by the 100-circuit limit, it re-attaches to the **same** circuit. Every field, scoped service and pending render is intact. 4. Otherwise the circuit is evicted. Before .NET 10 that meant disposal: the reconnect fails, and reloading gives the user a brand-new circuit with an empty basket. Raising the retention period or count keeps more users' state alive longer at the cost of server memory, because a disconnected circuit still holds everything it held while connected. ## Layer 2: circuit state persistence in ASP.NET Core 10 In ASP.NET Core 10, when a disconnected circuit is evicted, Blazor first **pauses** it: it collects the values of `[PersistentState]` properties, the same mechanism used for prerendering, and stores them, then disposes the heavy circuit. When the user's browser comes back without a full page reload, a **new** circuit is created and those values are restored before the components initialize. - It is on by default when `AddInteractiveServerComponents()` is called; the default store is in memory. - Assigning a `HybridCache` with a distributed backing store lets persisted state be resumed on a different server than the one that saved it, with its own 8-hour default retention. - `Blazor.pauseCircuit()` and `Blazor.resumeCircuit()` let JavaScript pause deliberately, for example when the tab is hidden, which stores the state in the browser and frees the server's resources. - Only state you mark comes back. A basket service must expose its lines through a public `[PersistentState]` property and be registered with `RegisterPersistentService`. ## Limits - Only Interactive Server benefits; WebAssembly state never lived on the server. - A full page refresh loses the persisted circuit state; it is resumed only into the same page session. - Persisted values must be JSON serializable; EF Core entities with cycles and large graphs are poor candidates. - Recovery is best effort; if persistence fails, the user gets the ordinary disconnected experience. - In a server farm, reconnecting to the original circuit needs the same server, which is why sticky sessions matter; a distributed `HybridCache` lets persisted state be resumed even when the original server is gone. ## What the user experiences 1. **Short drop, under the retention period:** the reconnect UI appears briefly and disappears; everything is exactly as it was. 2. **Long drop, circuit evicted, state persisted:** the reconnect completes into a new circuit; marked state such as the basket returns, while unmarked component fields start from their initial values. 3. **Long drop and no persisted state, or a full reload:** the user is offered a reload and starts with a fresh circuit. Designing for case 2 means asking, for every field on a page, whether losing it after a long disconnect would annoy the customer. ## Choosing what to persist Mark what the user would be upset to lose and what is cheap to serialize: the basket's lines, a half-filled delivery form, a selected pickup slot. Reload reference data, such as the cake catalogue, instead of persisting it.
- A customer's phone was in a tunnel for ten minutes; with ASP.NET Core 10 defaults, what comes back when the page reconnects?The disconnected circuit was evicted after 3 minutes, so the original circuit is gone. With .NET 10 persistence its `[PersistentState]` values were saved, in memory for up to 2 hours by default, and a new circuit is resumed with them. If the basket is marked and registered, it returns; unmarked fields, such as an open dialog's state, start fresh.
- Why does raising DisconnectedCircuitRetentionPeriod to an hour worry operations staff?A disconnected circuit keeps its whole component tree and scoped services in server memory. An hour-long window with many mobile users can hold thousands of idle circuits. Circuit state persistence in .NET 10 is the cheaper option: it keeps only the marked state, not the circuit.
A cloakroom: step out briefly and your coat is on its hook as you left it. Stay away past closing and the attendant clears the hooks, boxing only the items you tagged; they are handed back at your return, the rest is gone.
- When the connection drops, the circuit and its state are disposed immediately.
- Disconnected circuits are kept forever until the user returns.
- Circuit state persistence restores every field of every component.
- Persisted circuit state survives a full page refresh.
- Circuit state persistence also applies to Interactive WebAssembly components.
Assumes ASP.NET Core 10; circuit state persistence, its PersistedCircuit* options and Blazor.pauseCircuit/resumeCircuit are new in 10, while the 100-circuit, 3-minute disconnected retention dates from earlier releases.