- Notifications
You must be signed in to change notification settings - Fork10.4k
Add visibility change beacon and circuit cleanup heuristic for Blazor Server#62789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
oroztocil wants to merge1 commit intomainChoose a base branch fromoroztocil/circuit-cleanup-improvements
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+193 −6
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This was referencedJul 17, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
Changes
unload
event withpagehide
for sending disconnect beacon from the Blazor client to the server.visibilitychange
event fires on the document.PageHiddenAt
timestamp of the last change to thehidden
state for the session.CircuitHost
instance for the session.visible
state. Null value indicates that the page is currently visible and active (as far as the server knows).CircuitRegistry.DisconnectAsync
(which is called when the SignalR connection breaks).CircuitRegistry.DisconnectedCircuits
memory cache (and later into the persistent state storage).Motivation
We replace the
unload
event withpagehide
because the two should fire in (practically) the same situations but the latter is not deprecated and does not cause warnings for the users.Reasoning behind the visibility-based optimization is as such:
visibilitychange
event is the only one that fires somewhat reliably on mobile devices, in particular when switching tabs in the browser, switching to another app, or going to the home screen.and no other events are processed.
hidden
state, 2) depending on the timeout settings, the server recognizes at some point that the SignalR connection has disconnected.unload
/pagehide
event), we would move the disconnected circuit into theDisconnectedCircuits
memory cache, and later into the persistent state storage. This is wasteful for the mobile scenarios described above as circuits from closed/discarded tabs would never be restored anyway.Risks
pagehide
event fires mostly in the same situations as thevisibilitychange
- taking into account only situations where we actuallywant to dispose the circuit (closing the tab, navigating away, hard refresh, closing the browser).DisconnectedCircuits
, now we terminate and dispose it (because the server sees the same order of events as e.g. in the mobile app switch scenario) even though the circuit would be eligible for restoration when the device regains network connection and the user foregrounds the Blazor tab.Questions
CircuitOptions
? What should be the default value? Or, should we compute it based on someHubOptions
value (e.g. the client timeout)?Fixes#54793