From 6425161befe34d1d3c409437734d086c44f24bbc Mon Sep 17 00:00:00 2001 From: jwcrystal <121911854+jwcrystal@users.noreply.github.com> Date: Sun, 12 Apr 2026 04:42:02 +0800 Subject: [PATCH] fix(sidebar): auto-expand parent node when navigating to subagent session (#893) When a user navigates to a subagent (child) session, the parent session node in the left sidebar was not automatically expanded, making the child session invisible in the tree. This change adds a useEffect that detects when the current session has a parentID and automatically adds that parentID to expandedParents, ensuring the subagent session is visible in the sidebar hierarchy. --- .../src/components/session/SessionSidebar.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/ui/src/components/session/SessionSidebar.tsx b/packages/ui/src/components/session/SessionSidebar.tsx index 7c9396f8..878eaf67 100644 --- a/packages/ui/src/components/session/SessionSidebar.tsx +++ b/packages/ui/src/components/session/SessionSidebar.tsx @@ -732,6 +732,23 @@ export const SessionSidebar: React.FC = ({ }); }, [addProject, tauriIpcAvailable]); + // Auto-expand parent session when navigating to a subagent (child) session + React.useEffect(() => { + if (!currentSessionId) return; + const current = sessions.find((s) => s.id === currentSessionId); + const parentID = (current as Session & { parentID?: string | null })?.parentID; + if (!parentID) return; + setExpandedParents((prev) => { + if (prev.has(parentID)) return prev; + const next = new Set(prev); + next.add(parentID); + try { + safeStorage.setItem(SESSION_EXPANDED_STORAGE_KEY, JSON.stringify(Array.from(next))); + } catch { /* ignored */ } + return next; + }); + }, [currentSessionId, sessions, safeStorage]); + const toggleParent = React.useCallback((sessionId: string) => { setExpandedParents((prev) => { const next = new Set(prev);