Skip to content

Commit d7579ed

Browse files
committed
fix(workflow): finalize drag on unmount + clamp reads scoped output width
- useDragResize: unmounting mid-drag now runs endDrag (commit + drop the scoped override) instead of a bare cleanup, so navigating away can neither lose the resize nor strand an inline override on a surviving target element. - terminal output-panel clamp: read the live --output-panel-width from the terminal element first (where a drag writes its scoped override), then :root, then the store, so a mid-drag terminal/window resize can't clamp against a stale value.
1 parent 4b86960 commit d7579ed

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,10 +1255,10 @@ export const Terminal = memo(function Terminal() {
12551255
/**
12561256
* Adjust output panel width on resize.
12571257
* Closes the output panel if there's not enough space for the minimum width.
1258-
* The clamp compares against the live `--output-panel-width` CSS variable
1259-
* (the visual width — during a drag it runs ahead of the store, which only
1260-
* commits on release) so a resize mid-drag can never stomp the drag with a
1261-
* stale store value; the store value is the fallback before any write.
1258+
* The clamp compares against the live `--output-panel-width` — read from the
1259+
* terminal element first (where a drag writes its scoped override), then
1260+
* `:root` (the committed value), then the store — so a resize mid-drag can
1261+
* never stomp the drag with a stale value.
12621262
*/
12631263
useEffect(() => {
12641264
const el = terminalRef.current
@@ -1276,7 +1276,8 @@ export const Terminal = memo(function Terminal() {
12761276
}
12771277

12781278
const liveWidth = Number.parseFloat(
1279-
document.documentElement.style.getPropertyValue('--output-panel-width')
1279+
el.style.getPropertyValue('--output-panel-width') ||
1280+
document.documentElement.style.getPropertyValue('--output-panel-width')
12801281
)
12811282
const currentWidth = Number.isNaN(liveWidth) ? outputPanelWidth : liveWidth
12821283
if (currentWidth > maxWidth) {

apps/sim/hooks/use-drag-resize.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ interface UseDragResizeOptions {
7070
* (other pointers are ignored, so a second touch cannot kill the gesture) or
7171
* window `blur`, so an interrupted gesture can never leave the listeners or
7272
* body cursor stuck. A single-flight guard prevents stacking listeners across
73-
* rapid presses, and an unmount cleanup tears down a drag still in flight.
73+
* rapid presses, and unmounting mid-drag finalizes it the same way a release
74+
* does — committing the last value and dropping the scoped override — so
75+
* navigating away can neither lose the resize nor strand the override on a
76+
* surviving target element.
7477
*/
7578
export function useDragResize(options: UseDragResizeOptions) {
76-
const cleanupRef = useRef<(() => void) | null>(null)
79+
const teardownRef = useRef<(() => void) | null>(null)
7780
const optionsRef = useRef(options)
7881

7982
useEffect(() => {
8083
optionsRef.current = options
8184
}, [options])
8285

8386
const handlePointerDown = useCallback((e: React.PointerEvent<HTMLElement>) => {
84-
if (cleanupRef.current) return
87+
if (teardownRef.current) return
8588
if (optionsRef.current.onStart?.() === false) return
8689

8790
const handle = e.currentTarget
@@ -123,7 +126,7 @@ export function useDragResize(options: UseDragResizeOptions) {
123126
document.removeEventListener('pointerup', onPointerEnd)
124127
document.removeEventListener('pointercancel', onPointerEnd)
125128
window.removeEventListener('blur', endDrag)
126-
cleanupRef.current = null
129+
teardownRef.current = null
127130
}
128131

129132
function endDrag() {
@@ -144,14 +147,14 @@ export function useDragResize(options: UseDragResizeOptions) {
144147
endDrag()
145148
}
146149

147-
cleanupRef.current = cleanup
150+
teardownRef.current = endDrag
148151
document.addEventListener('pointermove', onPointerMove)
149152
document.addEventListener('pointerup', onPointerEnd)
150153
document.addEventListener('pointercancel', onPointerEnd)
151154
window.addEventListener('blur', endDrag)
152155
}, [])
153156

154-
useEffect(() => () => cleanupRef.current?.(), [])
157+
useEffect(() => () => teardownRef.current?.(), [])
155158

156159
return { handlePointerDown }
157160
}

0 commit comments

Comments
 (0)