From 9e88acaa36cbaf3fd3b5ab69663188fcbfe1c917 Mon Sep 17 00:00:00 2001 From: Fusion Date: Sun, 24 May 2026 23:15:15 +0200 Subject: [PATCH] fix: remove 0-dimension check blocking terminal fit and add debug logging - Remove chicken-and-egg check that prevented fit() when cols/rows were 0 - Add console logging for container dimensions and fit results - Add retry limit (50 attempts) for initial fit to prevent infinite loops --- apps/web/src/components/terminal.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/terminal.tsx b/apps/web/src/components/terminal.tsx index 6403cc6..a8ca77c 100644 --- a/apps/web/src/components/terminal.tsx +++ b/apps/web/src/components/terminal.tsx @@ -229,8 +229,6 @@ export const TerminalComponent: React.FC = ({ // Define fitTerminal before connectWebSocket so it's available in onmessage const fitTerminal = () => { if (!fitAddonRef.current || !termRef.current) return; - // Ensure terminal is opened and has valid dimensions - if (termRef.current.cols === 0 || termRef.current.rows === 0) return; const oldCols = termRef.current.cols; const oldRows = termRef.current.rows; try { @@ -240,8 +238,9 @@ export const TerminalComponent: React.FC = ({ return; } const { cols, rows } = termRef.current; - // Force refresh if dimensions changed and are valid - if ((cols !== oldCols || rows !== oldRows) && cols > 0 && rows > 0) { + console.log(`[Terminal] fit() result: ${cols}x${rows} (was ${oldCols}x${oldRows})`); + // Force refresh if dimensions are valid + if (cols > 0 && rows > 0) { try { termRef.current.refresh(0, rows - 1); } catch { @@ -249,7 +248,7 @@ export const TerminalComponent: React.FC = ({ } } const currentWs = wsRef.current; - if (currentWs?.readyState === WebSocket.OPEN) { + if (currentWs?.readyState === WebSocket.OPEN && cols > 0 && rows > 0) { currentWs.send(JSON.stringify({ type: "resize", cols, rows })); } }; @@ -259,14 +258,20 @@ export const TerminalComponent: React.FC = ({ ws = connectWebSocket(); // Initial fit after layout settles (terminal must be opened first) + let fitAttempts = 0; const doInitialFit = () => { if (!container.isConnected) return; + fitAttempts++; // Ensure container has dimensions before fitting if (container.clientWidth > 0 && container.clientHeight > 0) { + console.log(`[Terminal] Container ready: ${container.clientWidth}x${container.clientHeight} (attempt ${fitAttempts})`); fitTerminal(); - } else { - // Container not ready yet, try again + } else if (fitAttempts < 50) { + // Container not ready yet, try again (max 50 attempts ~ 1s) + console.log(`[Terminal] Container not ready: ${container.clientWidth}x${container.clientHeight} (attempt ${fitAttempts})`); requestAnimationFrame(doInitialFit); + } else { + console.warn(`[Terminal] Container never got dimensions after ${fitAttempts} attempts`); } }; requestAnimationFrame(doInitialFit);