-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add page reload when resuming Blazor circuit fails #64290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
4d27909 to
fce8418
Compare
| // 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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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:
ReconnectModalcomponent used in the Blazor project template,DefaultReconnectDisplayimplementation used in the framework as the fallback when no reconnection UI is found in the user code.Fixes #64228