Blazor Server apps often face one annoying issue: whenever a user gets disconnected, the entire circuit state is lost. That means counters reset, form data disappears, and the user has to start over.
With .NET 10, Blazor introduces Circuit Persistence — a game-changing feature that allows your component state to survive reconnections. In this article, we’ll explore what it is and see it in action with a simple example.
🔴 Problem in Previous Versions
Here’s a basic counter component in older Blazor versions:
@page "/counter"
<h3>Counter (without persistence)</h3>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
If the connection to the server drops and reconnects, it currentCount
resets to 0. That’s frustrating for users. So Blazor 10 solved this problem below
🟢 Solution in Blazor 10
Blazor 10 adds the attribute [SupplyParameterFromPersistentComponentState]
to help persist the component state. Let’s rewrite the counter using it:
@page "/counter-persistent"
<h3>Counter (with persistence)</h3>
<p>Current count: @CurrentCount</p>
<button class="btn btn-success" @onclick="IncrementCount">Click me</button>
@code {
[SupplyParameterFromPersistentComponentState]
public int CurrentCount { get; set; }
private void IncrementCount()
{
CurrentCount++;
}
}
When you lose the connection, see the image below, and the Current count is 3.
![error]()
👉 Now, even if the server connection drops, the counter value will continue from where the user left off after re-connection, and the Current count is 4
![error1]()
✨ Benefits of Circuit Persistence
✅ No unexpected resets – state survives connection loss.
✅ Great for banking, e-commerce, and form-heavy apps.
✅ Improves user experience significantly.
🏁 Conclusion
Blazor 10 takes a big step forward in reliability with Circuit Persistence. If you’re building Blazor Server apps, this feature can dramatically improve the user experience by preventing frustrating state resets.
Start experimenting with it today, and make your apps more resilient and user-friendly! 🚀