Skip to content

Commit 26a7bf6

Browse files
committed
Disconnect circuit on beforeunload event (#23224)
1 parent ad4f0a0 commit 26a7bf6

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Boot.Server.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ async function boot(userOptions?: Partial<CircuitStartOptions>): Promise<void> {
5656
return true;
5757
};
5858

59-
window.addEventListener(
60-
'unload',
61-
() => {
59+
let disconnectSent = false;
60+
const cleanup = () => {
61+
if (!disconnectSent) {
6262
const data = new FormData();
6363
const circuitId = circuit.circuitId!;
6464
data.append('circuitId', circuitId);
65-
navigator.sendBeacon('_blazor/disconnect', data);
66-
},
67-
false
68-
);
65+
disconnectSent = navigator.sendBeacon('_blazor/disconnect', data);
66+
}
67+
};
68+
69+
window.addEventListener('beforeunload', cleanup, { capture: false, once: true });
70+
window.addEventListener('unload', cleanup, { capture: false, once: true });
6971

7072
window['Blazor'].reconnect = reconnect;
7173

0 commit comments

Comments
 (0)