@@ -92,10 +92,8 @@ export async function startServer(components: RootComponentManager<ServerCompone
92
92
93
93
let disconnectSent = false ;
94
94
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 ( ) ;
99
97
disconnectSent = navigator . sendBeacon ( '_blazor/disconnect' , data ) ;
100
98
}
101
99
} ;
@@ -154,6 +152,12 @@ export async function disposeCircuit() {
154
152
// disconnected circuit start pointing to .NET objects for a new circuit.
155
153
dotNetDispatcher . dispose ( ) ;
156
154
155
+ const formData = getDisconnectFormData ( ) ;
156
+ fetch ( '_blazor/disconnect' , {
157
+ method : 'POST' ,
158
+ body : formData ,
159
+ } ) ;
160
+
157
161
connection . stop ( ) ;
158
162
159
163
detachWebRendererInterop ( WebRendererId . Server ) ;
@@ -178,6 +182,13 @@ export function attachCircuitAfterRenderCallback(callback: typeof afterRenderCal
178
182
afterRenderCallback = callback ;
179
183
}
180
184
185
+ function getDisconnectFormData ( ) : FormData {
186
+ const data = new FormData ( ) ;
187
+ const circuitId = circuit . circuitId ! ;
188
+ data . append ( 'circuitId' , circuitId ) ;
189
+ return data ;
190
+ }
191
+
181
192
async function initializeConnection ( logger : Logger , circuit : CircuitDescriptor ) : Promise < HubConnection > {
182
193
const hubProtocol = new MessagePackHubProtocol ( ) ;
183
194
( hubProtocol as unknown as { name : string } ) . name = 'blazorpack' ;
0 commit comments