Skip to content

[Blazor] Public API changes to enable compression on Interactive components for Blazor Web #53821

@javiercn

Description

@javiercn

Background and Motivation

We've enabled websocket compression on interactive server components in Blazor web. As part of that, we needed new public APIs to configure some of the settings and disable them if needed.

Compression is enabled by default and we don't expect the majority of our customers to change any of the settings.

Proposed API

+ namespace Microsoft.AspNetCore.Components.Server;

+ public class ServerComponentsEndpointOptions()
{
+  public Func<HttpContext!, WebSocketAcceptContext!>? ConfigureWebsocketOptions { get; set; }
+  public ContentSecurityFrameAncestorPolicy { get; set; }
}

+ name Microsoft.AspNetCore.Builder;

+static class ServerRazorComponentsEndpointConventionBuilderExtensions
{
+  RazorComponentsEndpointConventionBuilder .AddInteractiveServerRenderMode(this RazorComponentsEndpointConventionBuilder! builder, Action<ServerComponentsEndpointOptions!>? callback = null) 

Usage Examples

Disable compression

builder.MapRazorComponents<App>().AddServerRenderMode(o => o.ConfigureWebSocketOptions = null)

Configure a more strict frame-ancestors directive policy.

builder.MapRazorComponents<App>().AddServerRenderMode(o => o.ContentSecurityFrameAncestorsPolicy = "'none'")

Alternative Designs

Disable compression

We discarded this approach because we still want to support configuring the parameters for the websocket, and we don't want to introduce two settings (CompressionEnabled and the callback). And given that this is going to be extremely rare, the callback we think is good enough.

builder.MapRazorComponents<App>().AddServerRenderMode(o => o.CompressionEnabled = false)

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions