-
Notifications
You must be signed in to change notification settings - Fork 10k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor Server - Auto reconnect on mobile browsers #32122
Blazor Server - Auto reconnect on mobile browsers #32122
Conversation
…delay afterwards. Support for mobile browsers to enable page reload when circuit was lost
There is an issue, when navigating away the reconnection modal is displayed for fraction of a second. I'll wait for comments how do we want to tackle that before updating this PR. Maybe I will need to dig around window['Blazor']._internal.navigationManager.listenForNavigationEvents((uri: string, intercepted: boolean): Promise<void> => {
return connection.send('OnLocationChanged', uri, intercepted);
}); |
Sorry for taking too long to get back to you here, @konradbartecki. |
Sure, @mkArtakMSFT @javiercn, no worries, let me know if anything I can hop on a quick 15 min call with you guys if you would want me to explain it. |
src/Components/Web.JS/src/Platform/Circuits/CircuitStartOptions.ts
Outdated
Show resolved
Hide resolved
src/Components/Web.JS/src/Platform/Circuits/DefaultReconnectionHandler.ts
Outdated
Show resolved
Hide resolved
}; | ||
|
||
class ReconnectionProcess { | ||
static readonly MaximumFirstRetryInterval = 3000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone remember why we implemented this originally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely because after connection goes down it would try to attempt the reconnection only after 20s, which is quite a long time.
So workaround that originally is there is to shorten the first reconnection attempt interval to 3s.
} | ||
|
||
export interface ReconnectionHandler { | ||
onConnectionDown(options: ReconnectionOptions, error?: Error): void; | ||
onConnectionUp(): void; | ||
onConnectionRejected(options: ReconnectionOptions): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a pretty good idea to me. I'm not 100% sold on reloading automatically by default (we need to at least reason about why that wasn't already our default) but the ability to configure a handler for this scenario seems valuable.
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
const delayDuration = i == 0 && options.retryIntervalMilliseconds > ReconnectionProcess.MaximumFirstRetryInterval | ||
? ReconnectionProcess.MaximumFirstRetryInterval | ||
: options.retryIntervalMilliseconds; | ||
await this.delay(delayDuration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since retryIntervalMilliseconds
was put back to 20000ms, I think it's also necessary to bring back this logic.
} | ||
|
||
export interface ReconnectionHandler { | ||
onConnectionDown(options: ReconnectionOptions, error?: Error): void; | ||
onConnectionUp(): void; | ||
onConnectionRejected(options: ReconnectionOptions): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For back-compatibility, this new property needs to be added as optional
@@ -49,6 +49,7 @@ async function boot(userOptions?: Partial<CircuitStartOptions>): Promise<void> { | |||
const reconnection = existingConnection || await initializeConnection(options, logger, circuit); | |||
if (!(await circuit.reconnect(reconnection))) { | |||
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.'); | |||
options.reconnectionHandler!.onConnectionRejected(options.reconnectionOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we should be checking whether reconnectionHandler
or onConnectionRejected
are unset, and skipping the call if so. Or is there some way we know for sure that both of them are set?
Example (untested):
options.reconnectionHandler!.onConnectionRejected(options.reconnectionOptions); | |
options.reconnectionHandler?.onConnectionRejected?(options.reconnectionOptions); |
Hi @konradbartecki. |
… comments Optional onCircuitRejected call if implemented
Blazor Server - Auto reconnect on mobile browsers
Rejected
prompt was displayed because circuit was already recycled on server.onConnectionRejected
eventAddresses #32113 #26985
Possibly adresses #23340
Related #10325