From e305b2efbba5112593345a504f98df456c021108 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Mon, 9 Nov 2026 03:02:14 +0000 Subject: [PATCH] perf(mobile): read new-workspace host labels through the stored host-list query --- .../new-workspace/NewWorkspacePageScreen.tsx | 2 +- .../src/new-workspace/use-host-label-by-id.ts | 40 ++++++++----------- mobile/src/query/first-paint-query-keys.ts | 10 +++++ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/mobile/src/new-workspace/NewWorkspacePageScreen.tsx b/mobile/src/new-workspace/NewWorkspacePageScreen.tsx index 87d2dd18388..c067d406cfa 100644 --- a/mobile/src/new-workspace/NewWorkspacePageScreen.tsx +++ b/mobile/src/new-workspace/NewWorkspacePageScreen.tsx @@ -20,7 +20,7 @@ export function NewWorkspacePageScreen() { const { hostCapabilities } = useHostProtocolGates() const connected = connState === 'connected' const worktrees = useHostWorktreeRows(client, connected, hostId) - const hostLabelById = useHostLabelById(client, connected) + const hostLabelById = useHostLabelById(client, connected, hostId) const worktreePaths = useMemo(() => worktrees.map((worktree) => worktree.path), [worktrees]) return ( diff --git a/mobile/src/new-workspace/use-host-label-by-id.ts b/mobile/src/new-workspace/use-host-label-by-id.ts index 40f56029255..6ea165fc630 100644 --- a/mobile/src/new-workspace/use-host-label-by-id.ts +++ b/mobile/src/new-workspace/use-host-label-by-id.ts @@ -1,32 +1,26 @@ -import { useEffect, useState } from 'react' +import { useMemo } from 'react' import type { ExecutionHostId } from '../../../src/shared/execution-host' -import { readHostSshTargetLabels } from '../host-screen/host-ssh-target-labels-read' +import { + HOST_LIST_TARGET, + hostRepoLabelsQuery, + NO_HOST_LIST_INPUT +} from '../host-screen/host-list-queries' +import { useHostQuery } from '../query/host-query' import type { RpcClient } from '../transport/rpc/rpc-client-contract' const NO_HOST_LABELS: ReadonlyMap = new Map() +// The host list's labels: the drawer shows the stored ones at once and the read refreshes them. export function useHostLabelById( client: RpcClient | null, - connected: boolean + connected: boolean, + hostId: string ): ReadonlyMap { - const [labels, setLabels] = useState(NO_HOST_LABELS) - - useEffect(() => { - if (!client || !connected) { - return - } - let live = true - readHostSshTargetLabels(client) - .then(({ hostLabelById }) => { - if (live) { - setLabels(hostLabelById) - } - }) - .catch(() => {}) - return () => { - live = false - } - }, [client, connected]) - - return labels + const { data } = useHostQuery( + hostRepoLabelsQuery, + { hostId, client: connected ? client : null }, + HOST_LIST_TARGET, + NO_HOST_LIST_INPUT + ) + return useMemo(() => (data ? new Map(data.hostLabels) : NO_HOST_LABELS), [data]) } diff --git a/mobile/src/query/first-paint-query-keys.ts b/mobile/src/query/first-paint-query-keys.ts index aee6d07b4c5..b916cae5a07 100644 --- a/mobile/src/query/first-paint-query-keys.ts +++ b/mobile/src/query/first-paint-query-keys.ts @@ -40,6 +40,16 @@ export function firstPaintQueryKeys(hostId: string, route: URL): PersistedHostQu if (screen === 'tasks') { return firstPaintTaskKeys(hostId) } + if (screen === 'new-workspace') { + // The drawer's existing-workspace check and host labels. + return [ + persistedHostQueryKey(hostWorktreeCatalogQuery, hostWorktreeCatalogKey(hostId)), + persistedHostQueryKey( + hostRepoLabelsQuery, + hostQueryKey(hostId, hostRepoLabelsQuery.family, HOST_LIST_TARGET, NO_HOST_LIST_INPUT) + ) + ].filter((key) => key !== null) + } const keys = screen === undefined ? [