fix(terminal): loading state, focus handling, debug logging

- Initialize loading=true in useTerminalSessions to prevent auto-create
  from firing before initial load completes
- Remove hasAutoCreated ref from TerminalPage (no longer needed)
- Add focus() to TerminalRef, call on tab switch
- Add term.focus() after term.open() in TerminalComponent
- Add console logging for WebSocket send/receive to debug no-i/o
- Revert backend _read_loop retry logic to original break-on-error
This commit is contained in:
2026-05-28 20:14:54 +02:00
parent b6e71e32f5
commit a3d01dd0a5
4 changed files with 19 additions and 21 deletions
+11
View File
@@ -37,6 +37,7 @@ export interface TerminalProps {
export interface TerminalRef {
fit: () => void;
focus: () => void;
}
const FONT_SIZE_KEY = "terminal-font-size";
@@ -106,6 +107,7 @@ export const TerminalComponent = React.forwardRef<TerminalRef, TerminalProps>(
wsRef.current = ws;
ws.onopen = () => {
console.log(`[Terminal ${sessionId ?? "default"}] WebSocket opened`);
setStatus("connected");
setError(null);
reconnectAttemptsRef.current = 0;
@@ -137,6 +139,8 @@ export const TerminalComponent = React.forwardRef<TerminalRef, TerminalProps>(
if (!termRef.current) return;
if (event.data instanceof Blob) {
// eslint-disable-next-line no-console
console.log(`[Terminal ${sessionId ?? "default"}] received ${(event.data as Blob).size} bytes`);
event.data.arrayBuffer().then((buffer) => {
const data = new Uint8Array(buffer);
termRef.current?.write(data);
@@ -306,6 +310,8 @@ export const TerminalComponent = React.forwardRef<TerminalRef, TerminalProps>(
// Open xterm first (must happen before fit)
term.open(container);
term.focus();
console.log(`[Terminal ${sessionId ?? "default"}] xterm opened and focused`);
const ws = connectWebSocket();
// Initial fit after layout settles (terminal must be opened first)
@@ -330,6 +336,8 @@ export const TerminalComponent = React.forwardRef<TerminalRef, TerminalProps>(
// Handle terminal input
term.onData((data) => {
// eslint-disable-next-line no-console
console.log(`[Terminal ${sessionId ?? "default"}] sending:`, JSON.stringify(data));
const currentWs = wsRef.current;
if (currentWs?.readyState !== WebSocket.OPEN) return;
@@ -466,6 +474,9 @@ export const TerminalComponent = React.forwardRef<TerminalRef, TerminalProps>(
}
}
},
focus: () => {
termRef.current?.focus();
},
}));
// Update parent about status changes