@@ -92,10 +92,8 @@ export async function startServer(components: RootComponentManager<ServerCompone
9292
9393 let disconnectSent = false ;
9494 const cleanup = ( ) => {
95- if ( ! disconnectSent ) {
96- const data = new FormData ( ) ;
97- const circuitId = circuit . circuitId ! ;
98- data . append ( 'circuitId' , circuitId ) ;
95+ if ( ! disconnectSent && isCircuitActive ( ) ) {
96+ const data = getDisconnectFormData ( ) ;
9997 disconnectSent = navigator . sendBeacon ( '_blazor/disconnect' , data ) ;
10098 }
10199 } ;
@@ -154,6 +152,12 @@ export async function disposeCircuit() {
154152 // disconnected circuit start pointing to .NET objects for a new circuit.
155153 dotNetDispatcher . dispose ( ) ;
156154
155+ const formData = getDisconnectFormData ( ) ;
156+ fetch ( '_blazor/disconnect' , {
157+ method : 'POST' ,
158+ body : formData ,
159+ } ) ;
160+
157161 connection . stop ( ) ;
158162
159163 detachWebRendererInterop ( WebRendererId . Server ) ;
@@ -178,6 +182,13 @@ export function attachCircuitAfterRenderCallback(callback: typeof afterRenderCal
178182 afterRenderCallback = callback ;
179183}
180184
185+ function getDisconnectFormData ( ) : FormData {
186+ const data = new FormData ( ) ;
187+ const circuitId = circuit . circuitId ! ;
188+ data . append ( 'circuitId' , circuitId ) ;
189+ return data ;
190+ }
191+
181192async function initializeConnection ( logger : Logger , circuit : CircuitDescriptor ) : Promise < HubConnection > {
182193 const hubProtocol = new MessagePackHubProtocol ( ) ;
183194 ( hubProtocol as unknown as { name : string } ) . name = 'blazorpack' ;
0 commit comments