From b96eafeb3123deb5fea4b47cea177a88fd2e186e Mon Sep 17 00:00:00 2001 From: suraj-markup Date: Sun, 1 Mar 2026 19:22:44 +0530 Subject: [PATCH] fix(terminal): use height stabilisation instead of fixed threshold for resize Replace the hardcoded `expectedHeight < 700` heuristic with a frame-to-frame height comparison. The loop now exits as soon as the container height stops changing (within 1px tolerance), which works correctly on all screen sizes. Previously, on viewports taller than ~1140px the non-fullscreen height exceeded 700px so the condition was never satisfied and the loop exhausted all attempts, introducing a ~1s delay on large screens. Co-Authored-By: Claude Opus 4.6 --- .../web/src/components/DirectTerminal.tsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/web/src/components/DirectTerminal.tsx b/packages/web/src/components/DirectTerminal.tsx index a05325565..9d7f505c1 100644 --- a/packages/web/src/components/DirectTerminal.tsx +++ b/packages/web/src/components/DirectTerminal.tsx @@ -279,22 +279,19 @@ export function DirectTerminal({ const maxAttempts = 60; let cancelled = false; let rafId = 0; + let lastHeight = -1; const resizeTerminal = () => { if (cancelled) return; resizeAttempts++; - // Get container dimensions - const rect = container.getBoundingClientRect(); - const expectedHeight = rect.height; + // Wait for the container height to stabilise (CSS transition finished) + const currentHeight = container.getBoundingClientRect().height; + const settled = lastHeight >= 0 && Math.abs(currentHeight - lastHeight) < 1; + lastHeight = currentHeight; - // Check if container has reached target dimensions (within 10px tolerance) - const isFullscreenTarget = fullscreen - ? expectedHeight > window.innerHeight - 100 - : expectedHeight < 700; - - if (!isFullscreenTarget && resizeAttempts < maxAttempts) { - // Container hasn't reached target size yet, try again + if (!settled && resizeAttempts < maxAttempts) { + // Container is still transitioning, try again next frame rafId = requestAnimationFrame(resizeTerminal); return; } @@ -322,6 +319,7 @@ export function DirectTerminal({ if (cancelled) return; if (e.target === container.parentElement) { resizeAttempts = 0; + lastHeight = -1; setTimeout(() => { if (!cancelled) rafId = requestAnimationFrame(resizeTerminal); }, 50); @@ -335,11 +333,13 @@ export function DirectTerminal({ const timer1 = setTimeout(() => { if (cancelled) return; resizeAttempts = 0; + lastHeight = -1; resizeTerminal(); }, 300); const timer2 = setTimeout(() => { if (cancelled) return; resizeAttempts = 0; + lastHeight = -1; resizeTerminal(); }, 600);