From 5e7f69456b69527500f5f78ee09e05bc75be5161 Mon Sep 17 00:00:00 2001 From: LukeGus Date: Thu, 8 Oct 2026 14:04:23 -0500 Subject: [PATCH] fix: manage tab refetches before giving up on a host or credential it cannot find --- src/ui/locales/en.json | 1 + src/ui/manage/ManageTab.tsx | 54 ++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/ui/locales/en.json b/src/ui/locales/en.json index 793263629..938407b0a 100644 --- a/src/ui/locales/en.json +++ b/src/ui/locales/en.json @@ -2477,6 +2477,7 @@ "collapse": "Collapse", "expand": "Expand", "cannotBeUndone": "This cannot be undone.", + "hostNotFound": "Couldn't find that host. Try refreshing the list.", "hostCount_one": "{{count}} host", "hostCount_other": "{{count}} hosts", "credentialCount_one": "{{count}} credential", diff --git a/src/ui/manage/ManageTab.tsx b/src/ui/manage/ManageTab.tsx index 9df4b3954..16d75fdcf 100644 --- a/src/ui/manage/ManageTab.tsx +++ b/src/ui/manage/ManageTab.tsx @@ -20,6 +20,7 @@ import { type SSHHostWithStatus, } from "@/main-axios"; import { getFolderDefaultsId } from "@/api/host-defaults-api"; +import { invalidateHostsAndStatusCaches } from "@/lib/hosts-request-cache"; import { registerTabCloseGuard } from "@/shell/tab-close-guards"; import { HostEditor } from "@/sidebar/HostEditor"; import { CredentialEditorView } from "@/sidebar/CredentialEditorView"; @@ -109,12 +110,20 @@ export function ManageTab() { const reloadHosts = useCallback(() => { return getSSHHosts() - .then((raw) => setHosts(raw.map(sshHostToHost))) + .then((raw) => { + const list = raw.map(sshHostToHost); + hostsRef.current = list; + setHosts(list); + }) .catch(() => {}); }, []); const reloadCredentials = useCallback(() => { return getCredentials() - .then((res) => setCredentials(mapCredentials(res))) + .then((res) => { + const list = mapCredentials(res); + credentialsRef.current = list; + setCredentials(list); + }) .catch(() => {}); }, []); @@ -207,17 +216,30 @@ export function ManageTab() { if (!(await confirmDiscard())) return; await loaded.current; if (request.kind === "host") { - const host = request.hostId - ? (hostsRef.current.find((h) => h.id === request.hostId) ?? null) - : null; - if (request.hostId && !host) return; + const find = () => + hostsRef.current.find((h) => h.id === request.hostId) ?? null; + let host = request.hostId ? find() : null; + // Our list can lag the sidebar's, so refetch once before giving up. + if (request.hostId && !host) { + invalidateHostsAndStatusCaches(); + await reloadHosts(); + host = find(); + if (!host) { + toast.error(t("manage.hostNotFound")); + return; + } + } openHost(host, request.draft); } else if (request.kind === "credential") { - const credential = request.credentialId - ? (credentialsRef.current.find( - (c) => c.id === request.credentialId, - ) ?? null) - : null; + const find = () => + credentialsRef.current.find( + (c) => String(c.id) === String(request.credentialId), + ) ?? null; + let credential = request.credentialId ? find() : null; + if (request.credentialId && !credential) { + await reloadCredentials(); + credential = find(); + } void openCredential(credential); } else if (request.kind === "defaults") { void openDefaults(request); @@ -227,7 +249,15 @@ export function ManageTab() { setMode(request.mode); } }, - [confirmDiscard, openHost, openCredential, openDefaults], + [ + confirmDiscard, + openHost, + openCredential, + openDefaults, + reloadHosts, + reloadCredentials, + t, + ], ); // The request that opened this tab was parked before it mounted.