fix: use requestAnimationFrame before fit() on window resize

When window resize fires, CSS layout hasn't settled yet. Adding
requestAnimationFrame ensures the browser has calculated new sizes
before xterm.js fit() reads the container dimensions. Reduced
debounce from 250ms to 100ms since rAF handles the layout timing.
This commit is contained in:
Fusion
2026-05-24 17:03:25 +02:00
parent 8b4e1a7428
commit 7b23618ae7
+5 -3
View File
@@ -254,13 +254,15 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
ws.send(data);
});
// Handle window resize with debounce
// Handle window resize with debounce - use rAF to ensure layout settled
let resizeTimeout: ReturnType<typeof setTimeout>;
const handleResize = () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
fitTerminal();
}, 250);
requestAnimationFrame(() => {
fitTerminal();
});
}, 100);
};
window.addEventListener("resize", handleResize);