Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ export const Terminal = memo(function Terminal() {
const terminalRef = useRef<HTMLElement>(null)
const prevEntriesLengthRef = useRef(0)
const prevWorkflowEntriesLengthRef = useRef(0)
const hasInitializedEntriesRef = useRef(false)
const isTerminalFocusedRef = useRef(false)
const lastExpandedHeightRef = useRef<number>(DEFAULT_EXPANDED_HEIGHT)
const setTerminalHeight = useTerminalStore((state) => state.setTerminalHeight)
Expand Down Expand Up @@ -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
Expand All @@ -1026,7 +1048,14 @@ export const Terminal = memo(function Terminal() {
}

prevWorkflowEntriesLengthRef.current = currentLength
}, [allWorkflowEntries.length, expandToLastHeight, openOnRun, isExpanded])
}, [
allWorkflowEntries.length,
expandToLastHeight,
openOnRun,
isExpanded,
hasConsoleHydrated,
activeWorkflowId,
])

/**
* Handle row click - toggle if clicking same entry
Expand Down