Skip to content

Commit 855043f

Browse files
committed
Close the circuit immediately upon disposal
1 parent f5b68ce commit 855043f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
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/dist/Release/blazor.web.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/Boot.Server.Common.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
181192
async 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

Comments
 (0)