From 2dceaa125fe4014286ee909939946fb9ca6c1b88 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 27 Jan 2026 11:17:09 -0800 Subject: [PATCH 1/2] fix(terminal): persist collapsed state across page refresh --- .../components/terminal/terminal.tsx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx index b1e7ca1b6c..4495eef220 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx @@ -796,6 +796,7 @@ export const Terminal = memo(function Terminal() { const terminalRef = useRef(null) const prevEntriesLengthRef = useRef(0) const prevWorkflowEntriesLengthRef = useRef(0) + const hasInitializedEntriesRef = useRef(false) const isTerminalFocusedRef = useRef(false) const lastExpandedHeightRef = useRef(DEFAULT_EXPANDED_HEIGHT) const setTerminalHeight = useTerminalStore((state) => state.setTerminalHeight) @@ -1007,12 +1008,33 @@ export const Terminal = memo(function Terminal() { return JSON.stringify(outputData, null, 2) }, [outputData]) + /** + * Reset entry tracking when switching workflows to ensure auto-open + * works correctly for each workflow independently. + */ + useEffect(() => { + hasInitializedEntriesRef.current = false + }, [activeWorkflowId]) + /** * Auto-open the terminal on new entries when "Open on run" is enabled. * This mirrors the header toggle behavior by using expandToLastHeight, * ensuring we always get the same smooth height transition. + * + * Skips the initial sync after console hydration to avoid auto-opening + * when persisted entries are restored on page refresh. */ useEffect(() => { + if (!hasConsoleHydrated) { + return + } + + if (!hasInitializedEntriesRef.current) { + hasInitializedEntriesRef.current = true + prevWorkflowEntriesLengthRef.current = allWorkflowEntries.length + return + } + if (!openOnRun) { prevWorkflowEntriesLengthRef.current = allWorkflowEntries.length return @@ -1026,7 +1048,7 @@ export const Terminal = memo(function Terminal() { } prevWorkflowEntriesLengthRef.current = currentLength - }, [allWorkflowEntries.length, expandToLastHeight, openOnRun, isExpanded]) + }, [allWorkflowEntries.length, expandToLastHeight, openOnRun, isExpanded, hasConsoleHydrated]) /** * Handle row click - toggle if clicking same entry From e653ebd2fbcda228978f45843b2160cfaed466ae Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 27 Jan 2026 11:28:55 -0800 Subject: [PATCH 2/2] fix(terminal): add activeWorkflowId to auto-open effect deps --- .../w/[workflowId]/components/terminal/terminal.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx index 4495eef220..bd8334c459 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx @@ -1048,7 +1048,14 @@ export const Terminal = memo(function Terminal() { } prevWorkflowEntriesLengthRef.current = currentLength - }, [allWorkflowEntries.length, expandToLastHeight, openOnRun, isExpanded, hasConsoleHydrated]) + }, [ + allWorkflowEntries.length, + expandToLastHeight, + openOnRun, + isExpanded, + hasConsoleHydrated, + activeWorkflowId, + ]) /** * Handle row click - toggle if clicking same entry