Skip to content

Move reconnection delay mechanism into framework code #24566

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
Aug 5, 2020
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
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
'opacity: 0.8',
'text-align: center',
'font-weight: bold',
'transition: visibility 0s linear 500ms',
];

this.modal.style.cssText = modalStyles.join(';');
Expand Down Expand Up @@ -64,15 +65,21 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
this.document.body.appendChild(this.modal);
}
this.modal.style.display = 'block';
this.modal.classList.add('show');
this.button.style.display = 'none';
this.reloadParagraph.style.display = 'none';
this.message.textContent = 'Attempting to reconnect to the server...';

// The visibility property has a transition so it takes effect after a delay.
// This is to prevent it appearing momentarily when navigating away. For the
// transition to take effect, we have to apply the visibility asynchronously.
this.modal.style.visibility = 'hidden';
setTimeout(() => {
this.modal.style.visibility = 'visible';
}, 0);
}

hide(): void {
this.modal.style.display = 'none';
this.modal.classList.remove('show');
}

failed(): void {
Expand Down
15 changes: 9 additions & 6 deletions src/Components/Web.JS/tests/DefaultReconnectDisplay.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultReconnectDisplay } from "../src/Platform/Circuits/DefaultReconnectDisplay";
import {JSDOM} from 'jsdom';
import { NullLogger} from '../src/Platform/Logging/Loggers';
import { JSDOM } from 'jsdom';
import { NullLogger } from '../src/Platform/Logging/Loggers';

describe('DefaultReconnectDisplay', () => {

Expand All @@ -14,10 +14,16 @@ describe('DefaultReconnectDisplay', () => {
expect(element).toBeDefined();
expect(element!.id).toBe('test-dialog-id');
expect(element!.style.display).toBe('block');
expect(element!.classList).toContain('show');
expect(element!.style.visibility).toBe('hidden');

expect(display.message.textContent).toBe('Attempting to reconnect to the server...');
expect(display.button.style.display).toBe('none');

// Visibility changes asynchronously to allow animation
return new Promise(resolve => setTimeout(() => {
expect(element!.style.visibility).toBe('visible');
resolve();
}, 1));
});

it ('does not add element to the body multiple times', () => {
Expand All @@ -37,7 +43,6 @@ describe('DefaultReconnectDisplay', () => {
display.hide();

expect(display.modal.style.display).toBe('none');
expect(display.modal.classList).not.toContain('show');
});

it ('updates message on fail', () => {
Expand All @@ -48,7 +53,6 @@ describe('DefaultReconnectDisplay', () => {
display.failed();

expect(display.modal.style.display).toBe('block');
expect(display.modal.classList).toContain('show');
expect(display.message.innerHTML).toBe('Reconnection failed. Try <a href=\"\">reloading</a> the page if you\'re unable to reconnect.');
expect(display.button.style.display).toBe('block');
});
Expand All @@ -61,7 +65,6 @@ describe('DefaultReconnectDisplay', () => {
display.rejected();

expect(display.modal.style.display).toBe('block');
expect(display.modal.classList).toContain('show');
expect(display.message.innerHTML).toBe('Could not reconnect to the server. <a href=\"\">Reload</a> the page to restore functionality.');
expect(display.button.style.display).toBe('none');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,3 @@ a, .btn-link {
right: 0.75rem;
top: 0.5rem;
}

#components-reconnect-modal.show {
animation: VISIBILITY 500ms linear;
}

@keyframes VISIBILITY {
0%,99% { visibility: hidden; }
100% { visibility: visible; }
}