Skip to content

Conversation

@oroztocil
Copy link
Member

In .NET 10, resuming a Blazor circuit fails when the server has been restarted (and an out-of-process persistent storage is not used). Currently, this is handled on the client side by displaying a "reconnection failed" UI which requires the user to manually reload the page.

This creates a regression in the default behavior compared to .NET 9, particularly for local development scenarios. Previously, the page would reload automatically once the server has restarted.

This PR re-adds the default reloading behavior to:

  • the ReconnectModal component used in the Blazor project template,
  • the DefaultReconnectDisplay implementation used in the framework as the fallback when no reconnection UI is found in the user code.

Fixes #64228

@oroztocil oroztocil requested a review from a team as a code owner November 10, 2025 18:01
Copilot AI review requested due to automatic review settings November 10, 2025 18:01
@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Nov 10, 2025
@oroztocil oroztocil requested a review from javiercn November 10, 2025 18:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR changes the behavior when resuming a Blazor circuit fails by automatically reloading the page instead of prompting the user to manually reload.

  • Automatic page reload on resume failure in DefaultReconnectDisplay
  • Support for "resume-failed" state in project template's reconnect modal handler

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
DefaultReconnectDisplay.ts Changed failed() method to automatically reload the page when resume fails, instead of showing reload UI elements
ReconnectModal.razor.js Added handling for "resume-failed" state to trigger automatic page reload

// Resuming circuit failed, last resort is to reload the page.
// This enables automatic reconnection (with empty state) when the server is restarted,
// e.g. during local development.
location.reload();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this cleans the state, should it be silent? Should we log to inform that the automatic reload has started?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know? We do location.reload() in other places without logging it. (Most people would not see the message anyway if they do not enable preserving logs on navigation in the browser.)

Maybe the comment is misleading. The state is "cleaned" implicitly simply because a hard refresh is performed. This is done mainly for the benefit of developers so that they can continue using the page they are working on as soon as the server restarts.

Copy link
Member

@ilonatommy ilonatommy Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial behavior was to rely on the user to reload, now it's automatic. Can it happen that we get into failed because of a server error and get into reload loop? E.g. 500 -> reload -> 500 -> reload? I mean: if something unexpected like this happens, we should leave some tools for investigation.

Copy link
Member Author

@oroztocil oroztocil Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not very obvious because the flag that controls this is not-very-descriptively named reconnect but the else branch (that does the reloading) is executed exactly only in the scenario where we try to resume state and it fails (because the new server instance does not have any state persisted for the circuit). It does not happen on a failed circuit start or a circuit reconnection. It does not happen when the server is not available.

Hard reloading the page means starting from scratch (just with the current URL). After the reload we are no longer in either a reconnection nor a resuming scenario. We can get a 404, we can get a new Blazor session, we can probably get some weird states in between - but we do not get a loop, at least not because of this line of code.

Before .NET 10, there was no state resuming so we cannot compare the behavior directly. However, we have been doing location.reload() when a reconnection attempt is rejected - which happened in the same scenarios as the failed state resuming now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor Server app in .NET 10 fails to reconnect after server restart, unlike .NET 9

3 participants