Skip to content

[main] Revert Enforce WebSockets Transport for Blazor #36674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public static ComponentEndpointConventionBuilder MapBlazorHub(
throw new ArgumentNullException(nameof(path));
}

// Only support the WebSockets transport type by default
return endpoints.MapBlazorHub(path, configureOptions: options => { options.Transports = HttpTransportType.WebSockets; });
return endpoints.MapBlazorHub(path, configureOptions: _ => { });
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.webview.js

Large diffs are not rendered by default.

19 changes: 3 additions & 16 deletions src/Components/Web.JS/src/Boot.Server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DotNet } from '@microsoft/dotnet-js-interop';
import { Blazor } from './GlobalExports';
import { HubConnectionBuilder, HubConnection, HttpTransportType } from '@microsoft/signalr';
import { HubConnectionBuilder, HubConnection } from '@microsoft/signalr';
import { MessagePackHubProtocol } from '@microsoft/signalr-protocol-msgpack';
import { showErrorNotification } from './BootErrors';
import { shouldAutoStart } from './BootCommon';
Expand Down Expand Up @@ -86,7 +86,7 @@ async function initializeConnection(options: CircuitStartOptions, logger: Logger
(hubProtocol as unknown as { name: string }).name = 'blazorpack';

const connectionBuilder = new HubConnectionBuilder()
.withUrl('_blazor', HttpTransportType.WebSockets)
.withUrl('_blazor')
.withHubProtocol(hubProtocol);

options.configureSignalR(connectionBuilder);
Expand Down Expand Up @@ -144,14 +144,7 @@ async function initializeConnection(options: CircuitStartOptions, logger: Logger
// Throw this exception so it can be handled at the reconnection layer, and don't show the
// error notification.
throw ex;
} else if (!isNestedError(ex)) {
showErrorNotification();
} else if (ex.innerErrors && ex.innerErrors.some(e => e.errorType === 'UnsupportedTransportError' && e.transport === HttpTransportType.WebSockets)) {
showErrorNotification('Unable to connect, please ensure you are using an updated browser that supports WebSockets.');
} else if (ex.innerErrors && ex.innerErrors.some(e => e.errorType === 'FailedToStartTransportError' && e.transport === HttpTransportType.WebSockets)) {
showErrorNotification('Unable to connect, please ensure WebSockets are available. A VPN or proxy may be blocking the connection.');
} else if (ex.innerErrors && ex.innerErrors.some(e => e.errorType === 'DisabledTransportError' && e.transport === HttpTransportType.LongPolling)) {
logger.log(LogLevel.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.');
} else {
showErrorNotification();
}
}
Expand All @@ -169,14 +162,8 @@ async function initializeConnection(options: CircuitStartOptions, logger: Logger
});

return connection;

function isNestedError(error: any): error is AggregateError {
return error && ('innerErrors' in error);
}
}

type AggregateError = Error & { innerErrors: { errorType: string, transport: HttpTransportType }[] };

function unhandledError(connection: HubConnection, err: Error, logger: Logger): void {
logger.log(LogLevel.Error, err);

Expand Down
6 changes: 1 addition & 5 deletions src/Components/Web.JS/src/BootErrors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
let hasFailed = false;

export async function showErrorNotification(customErrorMessage: string = '') {
export async function showErrorNotification() {
let errorUi = document.querySelector('#blazor-error-ui') as HTMLElement;
if (errorUi) {
errorUi.style.display = 'block';

if (customErrorMessage && errorUi.firstChild) {
errorUi.firstChild.textContent = `\n\t${customErrorMessage}\t\n`;
}
}

if (!hasFailed) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env, ResourceRequestLog resourceRequestLog)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ResourceRequestLog resourceRequestLog)
{
var enUs = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = enUs;
Expand Down

This file was deleted.