fix(vault): keep KnownHostsManager mounted after first visit

Addresses Codex P2 review finding on PR #4481:
- Keep KnownHostsManager lazy on cold startup (unmounted until first visit)
- Once visited, keep it mounted and hidden via display:none so hasScannedRef
  is not reset on section switches and deleted OpenSSH entries are not
  silently re-imported
This commit is contained in:
陈大猫 committed 2026-11-27 11:45:08 +00:00
1 parent 35bb8b1e99
commit 0ef9b23556
1 file changed
+8 -2
+8 -2
View File
@@ -570,6 +570,12 @@ export function VaultViewLayout({ ctx }: { ctx: VaultViewLayoutContext }) {
const [isMoveHostsOpen, setIsMoveHostsOpen] = React.useState(false);
const [moveTargetGroup, setMoveTargetGroup] = React.useState("");
const [isSidebarResizing, setIsSidebarResizing] = React.useState(false);
const [hasMountedKnownHosts, setHasMountedKnownHosts] = React.useState(
currentSection === "knownhosts",
);
if (currentSection === "knownhosts" && !hasMountedKnownHosts) {
setHasMountedKnownHosts(true);
}
const keyListRef = React.useRef(keys);
keyListRef.current = keys;
const newHostActionsRef = React.useRef<HTMLDivElement>(null);
@@ -1581,8 +1587,8 @@ export function VaultViewLayout({ ctx }: { ctx: VaultViewLayoutContext }) {
</LazyLoadBoundary>
)}
{/* Mount KnownHostsManager lazily on first visit, then keep hidden with CSS */}
{currentSection === "knownhosts" ? (
<div style={{ display: "contents" }}>
{hasMountedKnownHosts ? (
<div style={{ display: currentSection === "knownhosts" ? "contents" : "none" }}>
<Suspense fallback={<VaultSectionLoading />}>
{knownHostsManagerElement}
</Suspense>