Skip to content

Commit

Permalink
Improve Blazor reconnection experience.
Browse files Browse the repository at this point in the history
- Updated text of reconnect dialog to be more clear.
- Added user feedback to the `Retry` event button click. The current flow is `Attempting to reconnect` -> `Failed to reconnect ... [Retry]` -> Click Retry -> `Attempting to reconnect`.
- Found that in cases where the server went away entirely the reconnect event would through unexpectedly preventing the reconnect display from handling a failed reconnect. Added a separate error flow to understand when the server went away/could not start a SignalR connection to.
- Could not find a great way to add tests for this scenario.

Addresses #12442
  • Loading branch information
NTaylorMullen committed Aug 12, 2019
1 parent 14f17fa commit 804730e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/Components/Web.JS/src/Boot.Server.ts
Expand Up @@ -37,8 +37,13 @@ async function boot(userOptions?: Partial<BlazorOptions>): Promise<void> {
}

const reconnection = existingConnection || await initializeConnection(options, logger);
if (reconnection.state !== signalR.HubConnectionState.Connected) {
logger.log(LogLevel.Information, 'Reconnection attempt failed. Unable to connect to the server.');
return false;
}

if (!(await circuit.reconnect(reconnection))) {
logger.log(LogLevel.Information, 'Reconnection attempt failed.');
logger.log(LogLevel.Information, 'Reconnection attempt to the circuit failed.');
return false;
}

Expand Down
Expand Up @@ -31,12 +31,18 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
];

this.modal.style.cssText = modalStyles.join(';');
this.modal.innerHTML = '<h5 style="margin-top: 20px"></h5><button style="margin:5px auto 5px">Retry?</button><p>Alternatively, <a href>reload</a></p>';
this.modal.innerHTML = '<h5 style="margin-top: 20px"></h5><button style="margin:5px auto 5px">Retry</button><p>Alternatively, <a href>reload</a></p>';
this.message = this.modal.querySelector('h5')!;
this.button = this.modal.querySelector('button')!;
this.reloadParagraph = this.modal.querySelector('p')!;

this.button.addEventListener('click', () => window['Blazor'].reconnect());
this.button.addEventListener('click', async () => {
this.show();
const successful = await window['Blazor'].reconnect();
if (!successful) {
this.failed();
}
});
this.reloadParagraph.querySelector('a')!.addEventListener('click', () => location.reload());
}

Expand All @@ -57,7 +63,7 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {

failed(): void {
this.button.style.display = 'block';
this.reloadParagraph.style.display = 'block';
this.message.textContent = 'Failed to reconnect to the server.';
this.reloadParagraph.style.display = 'none';
this.message.innerHTML = 'Reconnection failed. Try <a href>reloading</a> the page if you\'re unable to reconnect.';
}
}

0 comments on commit 804730e

Please sign in to comment.