From 7d246cf059bd371a34abfddd0c795715fc992a24 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Thu, 18 Dec 2025 16:31:35 -0800 Subject: [PATCH] fix(desktop): preserve terminal history across re-renders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reattaching to an existing terminal session, the previous logic skipped applying scrollback history if there were pending events queued. This caused terminal history loss when using fast-outputting processes like Claude Code, since data would queue during component unmount/remount cycles. The fix always applies the initial scrollback state first, then flushes pending events, ensuring no history is lost on reattach. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../ContentView/TabsContent/Terminal/Terminal.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx index 66c7f041da2..14bfdda99a6 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx @@ -322,10 +322,9 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => { if (initialCommands || initialCwd) { clearPaneInitialDataRef.current(paneId); } - const hasPendingEvents = pendingEventsRef.current.length > 0; - if (result.isNew || !hasPendingEvents) { - applyInitialState(result); - } + // Always apply initial state (scrollback) first, then flush pending events + // This ensures we don't lose terminal history when reattaching + applyInitialState(result); setSubscriptionEnabled(true); flushPendingEvents(); },