[Blazor] Custom CircuitHandler latency breaks WS connection on navigation
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
```csharp
namespace Microsoft.AspNetCore.Components.Server.Circuits;
public class BlazorCircuitHandler() : CircuitHandler
{
public override async Task OnCircuitOpenedAsync(Circuit circuit, CancellationToken cancellationToken)
{
await Task.Delay(2000);
await base.OnCircuitOpenedAsync(circuit, cancellationToken);
}
public override async Task OnCircuitClosedAsync(Circuit circuit, CancellationToken cancellationToken)
{
await base.OnCircuitClosedAsync(circuit, cancellationToken);
}
}
```
A lot of people use custom Blazor Server CircuitHandler implementations for initializing user state, connecting to SignalR Hubs, etc.
As seen in the video below, if you load a page with an InteractiveServer component, and navigate away before the circuit is opened, the whole circuit breaks. Thus, the whole app breaks.
### Expected Behavior
This would be solved with [#55127](https://github.com/dotnet/aspnetcore/issues/55127), because enhanced navigation would reopen the broken connection.
### Steps To Reproduce
Add custom circuit handler implementation to services
https://github.com/user-attachments/assets/aabb8b91-456c-4496-a3c5-7efea5a230d4
### Exceptions (if any)
_No response_
### .NET Version
9.0.100
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.