Skip to content

Commit 2dceaa1

Browse files
committed
fix(terminal): persist collapsed state across page refresh
1 parent 46ba315 commit 2dceaa1

File tree

1 file changed

+23
-1
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal

1 file changed

+23
-1
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ export const Terminal = memo(function Terminal() {
796796
const terminalRef = useRef<HTMLElement>(null)
797797
const prevEntriesLengthRef = useRef(0)
798798
const prevWorkflowEntriesLengthRef = useRef(0)
799+
const hasInitializedEntriesRef = useRef(false)
799800
const isTerminalFocusedRef = useRef(false)
800801
const lastExpandedHeightRef = useRef<number>(DEFAULT_EXPANDED_HEIGHT)
801802
const setTerminalHeight = useTerminalStore((state) => state.setTerminalHeight)
@@ -1007,12 +1008,33 @@ export const Terminal = memo(function Terminal() {
10071008
return JSON.stringify(outputData, null, 2)
10081009
}, [outputData])
10091010

1011+
/**
1012+
* Reset entry tracking when switching workflows to ensure auto-open
1013+
* works correctly for each workflow independently.
1014+
*/
1015+
useEffect(() => {
1016+
hasInitializedEntriesRef.current = false
1017+
}, [activeWorkflowId])
1018+
10101019
/**
10111020
* Auto-open the terminal on new entries when "Open on run" is enabled.
10121021
* This mirrors the header toggle behavior by using expandToLastHeight,
10131022
* ensuring we always get the same smooth height transition.
1023+
*
1024+
* Skips the initial sync after console hydration to avoid auto-opening
1025+
* when persisted entries are restored on page refresh.
10141026
*/
10151027
useEffect(() => {
1028+
if (!hasConsoleHydrated) {
1029+
return
1030+
}
1031+
1032+
if (!hasInitializedEntriesRef.current) {
1033+
hasInitializedEntriesRef.current = true
1034+
prevWorkflowEntriesLengthRef.current = allWorkflowEntries.length
1035+
return
1036+
}
1037+
10161038
if (!openOnRun) {
10171039
prevWorkflowEntriesLengthRef.current = allWorkflowEntries.length
10181040
return
@@ -1026,7 +1048,7 @@ export const Terminal = memo(function Terminal() {
10261048
}
10271049

10281050
prevWorkflowEntriesLengthRef.current = currentLength
1029-
}, [allWorkflowEntries.length, expandToLastHeight, openOnRun, isExpanded])
1051+
}, [allWorkflowEntries.length, expandToLastHeight, openOnRun, isExpanded, hasConsoleHydrated])
10301052

10311053
/**
10321054
* Handle row click - toggle if clicking same entry

0 commit comments

Comments
 (0)