Skip to content

Commit cac0a9c

Browse files
SteveSandersonMScaptainsafia
authored andcommitted
Move reconnection delay mechanism into framework code (#24566)
1 parent d817a75 commit cac0a9c

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectDisplay.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
2929
'opacity: 0.8',
3030
'text-align: center',
3131
'font-weight: bold',
32+
'transition: visibility 0s linear 500ms',
3233
];
3334

3435
this.modal.style.cssText = modalStyles.join(';');
@@ -64,15 +65,21 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
6465
this.document.body.appendChild(this.modal);
6566
}
6667
this.modal.style.display = 'block';
67-
this.modal.classList.add('show');
6868
this.button.style.display = 'none';
6969
this.reloadParagraph.style.display = 'none';
7070
this.message.textContent = 'Attempting to reconnect to the server...';
71+
72+
// The visibility property has a transition so it takes effect after a delay.
73+
// This is to prevent it appearing momentarily when navigating away. For the
74+
// transition to take effect, we have to apply the visibility asynchronously.
75+
this.modal.style.visibility = 'hidden';
76+
setTimeout(() => {
77+
this.modal.style.visibility = 'visible';
78+
}, 0);
7179
}
7280

7381
hide(): void {
7482
this.modal.style.display = 'none';
75-
this.modal.classList.remove('show');
7683
}
7784

7885
failed(): void {

src/Components/Web.JS/tests/DefaultReconnectDisplay.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DefaultReconnectDisplay } from "../src/Platform/Circuits/DefaultReconnectDisplay";
2-
import {JSDOM} from 'jsdom';
3-
import { NullLogger} from '../src/Platform/Logging/Loggers';
2+
import { JSDOM } from 'jsdom';
3+
import { NullLogger } from '../src/Platform/Logging/Loggers';
44

55
describe('DefaultReconnectDisplay', () => {
66

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

1919
expect(display.message.textContent).toBe('Attempting to reconnect to the server...');
2020
expect(display.button.style.display).toBe('none');
21+
22+
// Visibility changes asynchronously to allow animation
23+
return new Promise(resolve => setTimeout(() => {
24+
expect(element!.style.visibility).toBe('visible');
25+
resolve();
26+
}, 1));
2127
});
2228

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

3945
expect(display.modal.style.display).toBe('none');
40-
expect(display.modal.classList).not.toContain('show');
4146
});
4247

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

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

6367
expect(display.modal.style.display).toBe('block');
64-
expect(display.modal.classList).toContain('show');
6568
expect(display.message.innerHTML).toBe('Could not reconnect to the server. <a href=\"\">Reload</a> the page to restore functionality.');
6669
expect(display.button.style.display).toBe('none');
6770
});

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/wwwroot/css/site.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,3 @@ app {
181181
display: block;
182182
}
183183
}
184-
185-
#components-reconnect-modal.show {
186-
animation: VISIBILITY 500ms linear;
187-
}
188-
189-
@keyframes VISIBILITY {
190-
0%,99% { visibility: hidden; }
191-
100% { visibility: visible; }
192-
}

0 commit comments

Comments
 (0)