Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

This PR addresses the limitation where users of AddInteractiveServerRenderMode had no clean way to configure the underlying SignalR HttpConnectionDispatcherOptions. Previously, users had to resort to workarounds using metadata inspection to access properties like CloseOnAuthenticationExpiration.

Problem

Before this change, configuring SignalR connection options required this workaround:

endpoints.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .Add(e =>
    {
        var metadata = e.Metadata;
        var dispatcherOptions = metadata.OfType<HttpConnectionDispatcherOptions>().FirstOrDefault();
        if (dispatcherOptions != null)
        {
            dispatcherOptions.CloseOnAuthenticationExpiration = true;
        }
    });

This approach was:

  • Not type-safe
  • Hard to discover
  • Fragile and reliant on implementation details
  • Inconsistent with the API provided by MapBlazorHub

Solution

Added a new ConfigureConnection property to ServerComponentsEndpointOptions that accepts an Action<HttpConnectionDispatcherOptions>, enabling direct configuration of the SignalR connection dispatcher options.

Now users can configure connection options cleanly:

endpoints.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode(options =>
    {
        options.ConfigureConnection = dispatcherOptions =>
        {
            dispatcherOptions.CloseOnAuthenticationExpiration = true;
            dispatcherOptions.AllowStatefulReconnects = true;
            dispatcherOptions.ApplicationMaxBufferSize = 1024 * 1024;
            // Configure any other connection options as needed
        };
    });

Implementation Details

  • ServerComponentsEndpointOptions: Added ConfigureConnection property with comprehensive XML documentation
  • CircuitEndpointProvider: Modified to conditionally use the configuration action when mapping the Blazor hub via MapBlazorHub
  • Backward compatibility: Existing code continues to work unchanged - when ConfigureConnection is null, the original behavior is preserved
  • API consistency: Matches the pattern already established by MapBlazorHub overloads that accept dispatcher options configuration
  • Zero overhead: No performance impact when the feature is not used

Testing

Added unit tests to verify that the ConfigureConnection property can be set and correctly configures the dispatcher options, including the primary use case of setting CloseOnAuthenticationExpiration.

Fixes the issue where users needed to access HttpConnectionDispatcherOptions in AddInteractiveServerRenderMode but had no clean API to do so.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Blazor] Provide access to the underlying SignalR HttpConnectionDispatcherOptions in AddInteractiveServerRenderMode</issue_title>
<issue_description>This was possible with MapBlazorHub, but it doesn't seem possible with AddInteractiveServerRenderMode.

Calling MapBlazorHub won't work since that will try to register another endpoint.

Right now, this is the best way to do it:

    .Add(e =>
    {
        var metadata = e.Metadata;
        var dispatcherOptions = metadata.OfType<HttpConnectionDispatcherOptions>().FirstOrDefault();
        if (dispatcherOptions != null)
        {
            dispatcherOptions.CloseOnAuthenticationExpiration = true;
        }
    });
```</issue_description>

<agent_instructions>This should be part of
https://github.com/dotnet/aspnetcore/blob/063ba34bff5a3b6ee2f54cafe83b04bd3d4a5c06/src/Components/Server/src/Builder/ServerRazorComponentsEndpointConventionBuilderExtensions.cs#L33-L35

https://github.com/dotnet/aspnetcore/blob/063ba34bff5a3b6ee2f54cafe83b04bd3d4a5c06/src/Components/Server/src/Builder/ServerComponentsEndpointOptions.cs#L11

Can be expanded with an ` Action<HttpConnectionDispatcherOptions>` property to configure the dispatcher options that we then pass to MapBlazorHub.

When we map the hub https://github.com/dotnet/aspnetcore/blob/063ba34bff5a3b6ee2f54cafe83b04bd3d4a5c06/src/Components/Server/src/DependencyInjection/ServerRazorComponentsBuilderExtensions.cs#L71-L72

We pass the options to configure them.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #63520

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

@Copilot Copilot AI changed the title [WIP] [Blazor] Provide access to the underlying SignalR HttpConnectionDispatcherOptions in AddInteractiveServerRenderMode [Blazor] Provide access to HttpConnectionDispatcherOptions in AddInteractiveServerRenderMode Sep 25, 2025
@Copilot Copilot AI requested a review from javiercn September 25, 2025 12:24
Copilot finished work on behalf of javiercn September 25, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Blazor] Provide access to the underlying SignalR HttpConnectionDispatcherOptions in AddInteractiveServerRenderMode
2 participants