fix: force xterm.js canvas redraw on resize via internal renderer

This commit is contained in:
Fusion
2026-05-24 18:47:27 +02:00
parent d931f3071d
commit cc126b82df
+15 -2
View File
@@ -214,6 +214,19 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
term.open(container); term.open(container);
ws = connectWebSocket(); ws = connectWebSocket();
// Force xterm.js to fully redraw after resize
const forceRedraw = () => {
if (!termRef.current) return;
const term = termRef.current as any;
const rows = term.rows;
// Access internal renderer to force clear and redraw
if (term._core?.renderer) {
term._core.renderer.clear();
}
// Refresh all visible rows
term.refresh(0, rows - 1);
};
// Fit terminal and notify backend // Fit terminal and notify backend
const fitTerminal = () => { const fitTerminal = () => {
if (!fitAddonRef.current || !termRef.current) return; if (!fitAddonRef.current || !termRef.current) return;
@@ -221,9 +234,9 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
const oldRows = termRef.current.rows; const oldRows = termRef.current.rows;
fitAddonRef.current.fit(); fitAddonRef.current.fit();
const { cols, rows } = termRef.current; const { cols, rows } = termRef.current;
// Force refresh if dimensions changed // Force full redraw if dimensions changed
if (cols !== oldCols || rows !== oldRows) { if (cols !== oldCols || rows !== oldRows) {
termRef.current.refresh(0, rows - 1); forceRedraw();
} }
if (ws.readyState === WebSocket.OPEN) { if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: "resize", cols, rows })); ws.send(JSON.stringify({ type: "resize", cols, rows }));