Disconnect circuit on `beforeunload` event (#23224)
This commit is contained in:
parent
f6a6e4bd07
commit
4465a8efc8
File diff suppressed because one or more lines are too long
|
|
@ -56,16 +56,18 @@ async function boot(userOptions?: Partial<CircuitStartOptions>): Promise<void> {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener(
|
let disconnectSent = false;
|
||||||
'unload',
|
const cleanup = () => {
|
||||||
() => {
|
if (!disconnectSent) {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
const circuitId = circuit.circuitId!;
|
const circuitId = circuit.circuitId!;
|
||||||
data.append('circuitId', circuitId);
|
data.append('circuitId', circuitId);
|
||||||
navigator.sendBeacon('_blazor/disconnect', data);
|
disconnectSent = navigator.sendBeacon('_blazor/disconnect', data);
|
||||||
},
|
}
|
||||||
false
|
};
|
||||||
);
|
|
||||||
|
window.addEventListener('beforeunload', cleanup, { capture: false, once: true });
|
||||||
|
window.addEventListener('unload', cleanup, { capture: false, once: true });
|
||||||
|
|
||||||
window['Blazor'].reconnect = reconnect;
|
window['Blazor'].reconnect = reconnect;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue