fix(web): respect manual session path collapse (#656)

This commit is contained in:
CoColate
2026-05-21 21:18:27 +08:00
committed by GitHub
parent 611c4eec49
commit 5b90a48b33
2 changed files with 120 additions and 10 deletions
+20 -9
View File
@@ -739,6 +739,7 @@ export function SessionList(props: {
const [collapseOverrides, setCollapseOverrides] = useState<Map<string, boolean>>(
() => new Map()
)
const autoExpandedSelectedSessionKeyRef = useRef<string | null>(null)
const isGroupCollapsed = (group: SessionGroup): boolean => {
if (isSearching) return false
const override = collapseOverrides.get(group.key)
@@ -812,16 +813,26 @@ export function SessionList(props: {
})
}
// Auto-expand group (and machine) containing selected session
// Auto-expand group (and machine) containing the selected session only when
// the selected-session/group pair changes. Without this guard, every live
// session-list refresh (for example tool-call updates from a running selected
// session) reopens a path the user just collapsed.
useEffect(() => {
if (!selectedSessionId) return
setCollapseOverrides(prev => {
const group = allGroups.find(g =>
g.sessions.some(s => s.id === selectedSessionId)
)
if (!group) return prev
return expandSelectedSessionCollapseOverrides(prev, group)
})
if (!selectedSessionId) {
autoExpandedSelectedSessionKeyRef.current = null
return
}
const group = allGroups.find(g =>
g.sessions.some(s => s.id === selectedSessionId)
)
if (!group) return
const autoExpandKey = `${selectedSessionId}::${group.key}`
if (autoExpandedSelectedSessionKeyRef.current === autoExpandKey) return
autoExpandedSelectedSessionKeyRef.current = autoExpandKey
setCollapseOverrides(prev => expandSelectedSessionCollapseOverrides(prev, group))
}, [selectedSessionId, allGroups])
// Clean up stale collapse overrides