Skip to content

Disable Long Polling Fallback Transport for Blazor Server #470

Closed
@TanayParikh

Description

@TanayParikh

Disable Long Polling Fallback Transport for Blazor Server

Long Polling is a fall-back transport utilized when WebSockets aren't available. This can lead to a degraded user experience. Thus, the Long Polling fallback has been removed, and both the client and server now support only WebSockets by default.

Version introduced

.NET 6 rc 1

Old behavior

If WebSockets are unavailable for a circuit (ex. network issues or browser incompatibility), Long Polling is used instead.

New behavior

Client Server Message
WS (without browser WS support) WebSockets Unable to connect, please ensure you are using an updated browser that supports WebSockets.
WS (with WS connection being rejected) WebSockets Unable to connect, please ensure WebSockets are available. A VPN or proxy may be blocking the connection.
WS LongPolling An unhandled error has occurred. Console Error: Unable to initiate a SignalR connection to the server. This might be because the server is not configured to support WebSockets. To troubleshoot this, visit https://aka.ms/blazor-server-websockets-error.
LongPolling WebSockets An unhandled error has occurred.

Reason for change

Improve overall end-user-experience by enforcing WebSocket use.

Recommended action

Ensure WebSockets are functioning as expected with your application. If you must use Long Polling, the following client and server side changes must be made:

Server Side

In Startup.cs, replace endpoints.MapBlazorHub() with:

endpoints.MapBlazorHub(configureOptions: options => 
{ 
    options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling; 
});

Client Side

In Pages/_Layout.cshtml, update the blazor.server.js script tag to include the autostart="false" attribute:

<script src="_framework/blazor.server.js" autostart="false"></script>

Below the blazor.server.js script tag, add the following snippet. WebSockets (1) and Long Polling (4) are the supported HTTPTransportTypes.

<script>
    (function start() {
        Blazor.start({
            configureSignalR: builder => builder.withUrl('_blazor', 1 | 4) // WebSockets and Long Polling
        });
    })()
</script>

Category

  • Binary compatibility (the newer version can be used without recompiling)
  • Source compatibility (successfully recompiling against newer version requires source changes)

Affected APIs

Not detectable via API analysis


Issue metadata

  • Issue type: breaking-change

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions