fix: prevent bootstrap phase regression when an existing host comes online first

When a saved host reconnects before bootstrapDesktop finishes, the phase
was regressed from "online" back to "connecting". Track the race settlement
and skip the setPhase("connecting") call if anyOnline already won. Also
extract getEarliestOnlineHostServerId into HostRuntimeStore and use it to
initialize the bootstrap phase, avoiding a flash of the starting screen.
This commit is contained in:
Mohamed Boudra
2026-04-26 08:15:06 +07:00
parent b7310b9e90
commit 1ec448d2b9
5 changed files with 84 additions and 33 deletions
+16 -10
View File
@@ -1739,25 +1739,31 @@ export class HostRuntimeStore {
};
}
getEarliestOnlineHostServerId(): string | null {
let earliestServerId: string | null = null;
let earliestOnlineAt: string | null = null;
for (const host of this.hosts) {
const snapshot = this.getSnapshot(host.serverId);
if (!isHostRuntimeConnected(snapshot) || !snapshot?.lastOnlineAt) continue;
if (!earliestOnlineAt || snapshot.lastOnlineAt < earliestOnlineAt) {
earliestOnlineAt = snapshot.lastOnlineAt;
earliestServerId = host.serverId;
}
}
return earliestServerId;
}
waitForAnyConnectionOnline(): { promise: Promise<void>; cancel: () => void } {
let unsubscribe: (() => void) | null = null;
const isAnyOnline = (): boolean => {
for (const host of this.hosts) {
const snapshot = this.getSnapshot(host.serverId);
if (snapshot?.connectionStatus === "online") return true;
}
return false;
};
const promise = new Promise<void>((resolve) => {
if (isAnyOnline()) {
if (this.getEarliestOnlineHostServerId() !== null) {
resolve();
return;
}
unsubscribe = this.subscribeAll(() => {
if (isAnyOnline()) {
if (this.getEarliestOnlineHostServerId() !== null) {
unsubscribe?.();
unsubscribe = null;
resolve();