mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-28 00:08:21 -05:00
fix(terminal): persist collapsed state across page refresh (#3023)
* fix(terminal): persist collapsed state across page refresh * fix(terminal): add activeWorkflowId to auto-open effect deps
This commit is contained in:
@@ -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)
|
||||
@@ -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,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
|
||||
|
||||
Reference in New Issue
Block a user