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
This commit is contained in:
Fusion
2026-05-24 23:15:15 +02:00
parent 0d10caf489
commit 9e88acaa36
+12 -7
View File
@@ -229,8 +229,6 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
// 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<TerminalProps> = ({
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<TerminalProps> = ({
}
}
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<TerminalProps> = ({
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);