mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(native-chat): remember only live chat tabs as shown
Recording every active tab id and never dropping closed ones let the set grow with tab churn, and each new chat copied all of it.
This commit is contained in:
+19
@@ -76,6 +76,25 @@ describe('StructuredAgentSessionPaneOverlayLayer', () => {
|
||||
expect(mountedChats(view.container)).toEqual(['chat-1', 'chat-2'])
|
||||
expect(mocks.mounts).toEqual(['chat-1', 'chat-2'])
|
||||
})
|
||||
|
||||
it('forgets a closed chat, so a reopened tab with its id waits until it is shown', () => {
|
||||
mocks.store?.setState({
|
||||
unifiedTabsByWorktree: { [WORKTREE_ID]: TAB_IDS.map(chatTab) },
|
||||
groupsByWorktree: { [WORKTREE_ID]: [group('chat-2')] },
|
||||
activeGroupIdByWorktree: { [WORKTREE_ID]: GROUP_ID }
|
||||
})
|
||||
const view = render(
|
||||
<StructuredAgentSessionPaneOverlayLayer worktreeId={WORKTREE_ID} isWorktreeActive />
|
||||
)
|
||||
act(() =>
|
||||
mocks.store?.setState({
|
||||
unifiedTabsByWorktree: { [WORKTREE_ID]: ['chat-1', 'chat-3'].map(chatTab) },
|
||||
groupsByWorktree: { [WORKTREE_ID]: [group('chat-3')] }
|
||||
})
|
||||
)
|
||||
act(() => mocks.store?.setState({ unifiedTabsByWorktree: { [WORKTREE_ID]: TAB_IDS.map(chatTab) } }))
|
||||
expect(mountedChats(view.container)).toEqual(['chat-3'])
|
||||
})
|
||||
})
|
||||
|
||||
function mountedChats(container: HTMLElement): string[] {
|
||||
|
||||
+15
-10
@@ -113,22 +113,27 @@ const StructuredAgentSessionPaneOverlayLayer = memo(
|
||||
() => new Map(groups.map((group) => [group.id, group.activeTabId] as const)),
|
||||
[groups]
|
||||
)
|
||||
const structuredTabs = useMemo(
|
||||
() => unifiedTabs.filter((tab): tab is StructuredAgentSessionTab => isStructuredTab(tab)),
|
||||
[unifiedTabs]
|
||||
)
|
||||
const { structuredTabs, structuredTabIds } = useMemo(() => {
|
||||
const tabs = unifiedTabs.filter((tab): tab is StructuredAgentSessionTab => isStructuredTab(tab))
|
||||
return { structuredTabs: tabs, structuredTabIds: new Set(tabs.map((tab) => tab.id)) }
|
||||
}, [unifiedTabs])
|
||||
// Why: a chat holds no view state until it is first shown, and mounting every restored chat runs the renderer out of memory at thousands of tabs.
|
||||
const [shownTabIds, setShownTabIds] = useState(NO_SHOWN_TAB_IDS)
|
||||
const newlyShownTabIds = groups.flatMap((group) =>
|
||||
group.activeTabId && !shownTabIds.has(group.activeTabId) ? [group.activeTabId] : []
|
||||
)
|
||||
if (newlyShownTabIds.length > 0) {
|
||||
setShownTabIds(new Set([...shownTabIds, ...newlyShownTabIds]))
|
||||
}
|
||||
const mountedTabs = useMemo(
|
||||
() => structuredTabs.filter((tab) => shownTabIds.has(tab.id)),
|
||||
[structuredTabs, shownTabIds]
|
||||
)
|
||||
const newlyShownTabIds = groups.flatMap((group) =>
|
||||
group.activeTabId &&
|
||||
structuredTabIds.has(group.activeTabId) &&
|
||||
!shownTabIds.has(group.activeTabId)
|
||||
? [group.activeTabId]
|
||||
: []
|
||||
)
|
||||
if (newlyShownTabIds.length > 0) {
|
||||
// Rebuild from live mounted chats so closed tabs' ids don't accumulate.
|
||||
setShownTabIds(new Set([...mountedTabs.map((tab) => tab.id), ...newlyShownTabIds]))
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user