Blazor: Authorization taking too much time makes the component lose its state
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Context: Blazor Server-Side on .NET 8 RC1
I have a my own `IAuthorizationHandler`: it pulls the user's permissions from the database and then validate the different pending requirements of a specific type to validate a policy. (it is triggered by the `@attribute [Authorize(Policy = "Root")]` on the razor page)
When a client lose connection with the server, the overlay `Attempting to reconnect to the server: N of M` appears:

When the client gains back the connection with the server, the same `Circuit` is maintained successfully and the authorization is validated again.
When the process of the `IAuthorizationHandler` is very fast, the component will resume with its state successfully:

When the process of the `IAuthorizationHandler` is taking too "long", the component will be unloaded, replaced with `Authorizing...` when reconnecting, then after authorization is successful, the component will be reloaded with a brand new state, which leads to losing the data that was on the page before losing connection with the server.

### Expected Behavior
In my opinion, there is multiple expected behavior:
- The `Authorizing...` should appear but the other component should keep its state while it is pending for authorization.
- The user should be able to prevent the `Authorizing...` from appearing. (Is it not possible already?)
### Steps To Reproduce
1. Configure a simple policy `Root` with a custom requirement
2. Implement a `IAuthorizationHandler` with a huge delay on it that `Succeed` your pending custom requirement
3. Open your DevTools on your browser
4. Open a razor page that has a `@attribute [Authorize(Policy = "Root")]`
5. Go offline from your DevTools to lose connection with Blazor Server
6. Wait for the "Attempting to reconnect to the server..."
7. Go online again from your DevTools to make SignalR reconnect successfully to Blazor Server
And now, with a big delay, you should see the component disappear, having `Authorizing...` appear, then the component reloading with its default state.
### Exceptions (if any)
No exceptions.
### .NET Version
8.0.100-rc.1.23455.8
### Anything else?
Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.8.0 Preview 2.0
.NET SDK:
Version: 8.0.100-rc.1.23455.8
Commit: e14caf947f
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100-rc.1.23455.8\
.NET workloads installed:
There are no installed workloads to display.
Host:
Version: 8.0.0-rc.1.23419.4
Architecture: x64
Commit: 92959931a3
RID: win-x64
.NET SDKs installed:
7.0.203 [C:\Program Files\dotnet\sdk]
8.0.100-preview.6.23330.14 [C:\Program Files\dotnet\sdk]
8.0.100-rc.1.23455.8 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-preview.6.23329.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-preview.6.23329.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0-preview.6.23329.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0-rc.1.23420.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Contributor guide
Assessment
This issue has not been assessed yet.