Skip to content

Commit 003e931

Browse files
authored
improvement(terminal): resize output panel on any layout change via ResizeObserver (#4220)
Replaces MutationObserver on document.documentElement (watching CSS variable changes) + window resize listener with a ResizeObserver on the terminal element itself. The terminal now measures its own rendered width directly, so it responds correctly to all layout changes — sidebar, workflow panel, and mothership resize — without indirect CSS variable plumbing or cross-component coupling.
1 parent 948cdbc commit 003e931

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-mothership-resize.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { MOTHERSHIP_WIDTH } from '@/stores/constants'
1212
*/
1313
export function useMothershipResize() {
1414
const mothershipRef = useRef<HTMLDivElement | null>(null)
15-
// Stored so the useEffect cleanup can tear down listeners if the component unmounts mid-drag
1615
const cleanupRef = useRef<(() => void) | null>(null)
1716

1817
const handleResizePointerDown = useCallback((e: React.PointerEvent) => {

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

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,20 +1246,14 @@ export const Terminal = memo(function Terminal() {
12461246
* Closes the output panel if there's not enough space for the minimum width.
12471247
*/
12481248
useEffect(() => {
1249+
const el = terminalRef.current
1250+
if (!el) return
1251+
12491252
const handleResize = () => {
12501253
if (!selectedEntry) return
12511254

1252-
const sidebarWidth = Number.parseInt(
1253-
getComputedStyle(document.documentElement).getPropertyValue('--sidebar-width') || '0'
1254-
)
1255-
const panelWidth = Number.parseInt(
1256-
getComputedStyle(document.documentElement).getPropertyValue('--panel-width') || '0'
1257-
)
1258-
1259-
const terminalWidth = window.innerWidth - sidebarWidth - panelWidth
1260-
const maxWidth = terminalWidth - TERMINAL_CONFIG.BLOCK_COLUMN_WIDTH_PX
1255+
const maxWidth = el.getBoundingClientRect().width - TERMINAL_CONFIG.BLOCK_COLUMN_WIDTH_PX
12611256

1262-
// Close output panel if there's not enough space for minimum width
12631257
if (maxWidth < MIN_OUTPUT_PANEL_WIDTH_PX) {
12641258
setAutoSelectEnabled(false)
12651259
setSelectedEntryId(null)
@@ -1273,21 +1267,10 @@ export const Terminal = memo(function Terminal() {
12731267

12741268
handleResize()
12751269

1276-
window.addEventListener('resize', handleResize)
1277-
1278-
const observer = new MutationObserver(() => {
1279-
handleResize()
1280-
})
1270+
const observer = new ResizeObserver(handleResize)
1271+
observer.observe(el)
12811272

1282-
observer.observe(document.documentElement, {
1283-
attributes: true,
1284-
attributeFilter: ['style'],
1285-
})
1286-
1287-
return () => {
1288-
window.removeEventListener('resize', handleResize)
1289-
observer.disconnect()
1290-
}
1273+
return () => observer.disconnect()
12911274
}, [selectedEntry, outputPanelWidth, setOutputPanelWidth])
12921275

12931276
return (

0 commit comments

Comments
 (0)