Skip to content
TypeScript

perf(web): hidden terminal drawers no longer keep full thread history in memory (#13686)

Theo Browne6989856aa630
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index f5c3825cee3..cacb432f870 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -917,7 +917,14 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write");
const closeTerminalMutation = useAtomCommand(terminalEnvironment.close, "terminal close");
const draftThread = useComposerDraftStore((store) => store.getDraftThreadByRef(threadRef));
- const serverThread = useThread(threadRef, { waitForShell: draftThread !== null });
+ // Hidden drawers stay mounted (see MAX_HIDDEN_MOUNTED_TERMINAL_THREADS), so they read only
+ // the shell: a detail subscription would keep each hidden thread's history in memory. The
+ // active drawer shares ChatView's detail, which also covers archived threads (no shell).
+ const activeServerThread = useThread(active ? threadRef : null, {
+ waitForShell: draftThread !== null,
+ });
+ const serverThreadShell = useThreadShell(threadRef);
+ const serverThread = activeServerThread ?? serverThreadShell;
const projectRef = serverThread
? scopeProjectRef(serverThread.environmentId, serverThread.projectId)
: draftThread