You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[release/8.0] [Blazor] Close the circuit when all Blazor Server components are disposed (#50170)
# [Blazor] Close the circuit when all Blazor Server components are disposed
Allows a Blazor Server circuit to close when all root Blazor Server components get dynamically removed from the page.
## Description
The overall approach I've taken is:
1. Define what it means for the circuit to be in use (`WebRootComponentManager.hasAnyExistingOrPendingServerComponents()`):
* There are interactive Blazor Server components on the page, or...
* The initialization of an interactive Blazor Server component has started, but hasn't completed yet, or...
* There are SSR'd components on the page that haven't been initialized for interactivity yet (consider stream rendering, where we don't activate new components until the response completes), but they have either a "Server" or "Auto" render mode
2. Determine the cases where a circuit's "in use" status may have changed:
* After a render batch is applied (see `attachCircuitAfterRenderCallback` in `WebRootComponentManager.ts`)
* An applied render batch may result in the creation/disposal of a root component
* After an SSR update occurs, but before the first render batch is applied
* Consider the case where an SSR'd component with a Server render mode gets removed from the page, but before the circuit has a chance to initialize
3. Decide what to do if the "in use" status may have changed (`WebRootComponentManager.circuitMayHaveNoRootComponents()`):
* If the circuit is not in use:
* Start a timeout with some configurable duration (`SsrStartOptions.circuitInactivityTimeoutMs`), if it hasn't started already
* When the timeout expires, dispose the circuit
* If the circuit is not in use:
* Clear any existing timeout
This PR also:
- [X] Addresses a bug preventing Virtualize from working correctly when a WebAssembly and Server instance is present on the page at the same time
- [X] Adds E2E tests
Fixes#48765
logger.log(LogLevel.Information,'Reconnection attempt to the circuit was rejected by the server. This may indicate that the associated state is no longer available on the server.');
logger.log(LogLevel.Error,'Unable to initiate a SignalR connection to the server. This might be because the server is not configured to support WebSockets. For additional details, visit https://aka.ms/blazor-server-websockets-error.');
190
-
}
191
-
}
92
+
if(circuit.didRenderingFail()){
93
+
// We can't start a new circuit after a rendering failure because the renderer
94
+
// might be in an invalid state.
95
+
returnPromise.resolve(false);
192
96
}
193
97
194
-
// Check if the connection is established using the long polling transport,
195
-
// using the `features.inherentKeepAlive` property only present with long polling.
logger.log(LogLevel.Warning,'Failed to connect via WebSockets, using the Long Polling fallback transport. This may be due to a VPN or proxy blocking the connection. To troubleshoot this, visit https://aka.ms/blazor-server-using-fallback-long-polling.');
98
+
if(circuit.isDisposedOrDisposing()){
99
+
// If the current circuit is no longer available, create a new one.
0 commit comments