From e44edf5b3553371bfd571a5b63d7ad1171b353e7 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 03:16:36 +0000 Subject: [PATCH] Keep the sidebar's projects when the app renders while restoring hosts (#10042) * fix(app): publish restored hosts together with their directory sync A component that rendered while the host registry restored the project icon cache saw the host but found no directory sync for it, so its directory demand was dropped and the sidebar stayed on No projects yet for the session. Hosts are now published in the same step that creates their runtimes. Fixes #9996 Co-Authored-By: Claude Opus 5.5 * refactor(app): publish restored hosts through setHostsAndSync Every host-list change now goes through the one method that assigns the hosts, creates their runtimes, and notifies listeners in a single step. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- packages/app/src/runtime/host-runtime.test.ts | 49 ++++++++++++++++++- packages/app/src/runtime/host-runtime.ts | 4 +- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/packages/app/src/runtime/host-runtime.test.ts b/packages/app/src/runtime/host-runtime.test.ts index fa4520e62..69210defb 100644 --- a/packages/app/src/runtime/host-runtime.test.ts +++ b/packages/app/src/runtime/host-runtime.test.ts @@ -2739,6 +2739,52 @@ describe("HostRuntimeStore", () => { session.clearSession(host.serverId); }); + it("loads the directory for a consumer that sees a restored host before the registry finishes loading", async () => { + const host = makeHost({ + connections: [{ id: "direct:lan:6767", type: "directTcp", endpoint: "lan:6767" }], + }); + const fakeClient = new FakeDaemonClient(); + fakeClient.setConnectionState({ status: "connected" }); + const store = new HostRuntimeStore({ + storage: createMemoryHostRuntimeStorage({ + [REGISTRY_KEY]: JSON.stringify([host]), + "@paseo:e2e": "1", + }), + deps: { + createClient: () => fakeClient as unknown as DaemonClient, + connectToDaemon: async ({ host: hostProfile }) => ({ + client: fakeClient as unknown as DaemonClient, + serverId: hostProfile.serverId, + hostname: hostProfile.label ?? null, + }), + getClientId: async () => "cid_test_runtime", + }, + }); + + // A component renders on every tick while the registry loads, and acquires directory + // demand for each host it reads, as the sidebar does on its first render. + const registry = { loading: true }; + const boot = store.boot().finally(() => { + registry.loading = false; + }); + let releaseDemand: (() => void) | null = null; + while (registry.loading && !releaseDemand) { + if (store.getHosts().some((candidate) => candidate.serverId === host.serverId)) { + releaseDemand = store.acquireDirectoryDemand(host.serverId); + } + await Promise.resolve(); + } + await boot; + expect(releaseDemand).not.toBeNull(); + + await waitForHostOnline(store, host.serverId); + await vi.waitFor(() => expect(fakeClient.fetchAgentsCalls).toHaveLength(1)); + + releaseDemand?.(); + store.syncHosts([]); + useSessionStore.getState().clearSession(host.serverId); + }); + it("keeps readable hosts when the registry holds entries this build can't read", async () => { const { store, storage } = await bootWithRegistry(JSON.stringify(storedWithUnreadableEntries)); @@ -2863,7 +2909,8 @@ describe("HostRuntimeStore", () => { await registryLoaded; expect(store.isHostRegistryLoaded()).toBe(true); - expect(hostListNotifications).toBe(2); + // Publishing the restored hosts, the registry turning ready, and the registry loading. + expect(hostListNotifications).toBe(3); } finally { if (previousOverride === undefined) { delete process.env.EXPO_PUBLIC_LOCAL_DAEMON; diff --git a/packages/app/src/runtime/host-runtime.ts b/packages/app/src/runtime/host-runtime.ts index f883c19b6..4cdee9038 100644 --- a/packages/app/src/runtime/host-runtime.ts +++ b/packages/app/src/runtime/host-runtime.ts @@ -1816,11 +1816,9 @@ export class HostRuntimeStore { shouldPersistHosts = true; } } - this.hosts = profiles; - this.replicaCache.setHosts(profiles.map((profile) => profile.serverId)); projectIconCache.setHosts(profiles.map((profile) => profile.serverId)); await projectIconCache.restore(); - this.syncHosts(profiles); + this.setHostsAndSync(profiles); for (const profile of profiles) { void this.directorySyncByServer .get(profile.serverId)