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
+4 -11
View File
@@ -26,7 +26,6 @@ export const TerminalPage: React.FC = () => {
const [isFullscreen, setIsFullscreen] = useState(false);
const terminalRefs = useRef<Record<string, React.RefObject<TerminalRef>>>({});
const headerAutoHide = useAutoHide({ timeout: 3000, enabled: isMobile });
const hasAutoCreated = useRef(false);
const {
sessions,
@@ -40,16 +39,9 @@ export const TerminalPage: React.FC = () => {
error,
} = useTerminalSessions(instanceId ?? "");
// Auto-create default session if none exist (guard against double-fire)
// Auto-create default session if none exist after loading completes
useEffect(() => {
if (
!loading &&
sessions.length === 0 &&
!error &&
instanceId &&
!hasAutoCreated.current
) {
hasAutoCreated.current = true;
if (!loading && sessions.length === 0 && !error && instanceId) {
void createSession("Session 1");
}
}, [loading, sessions.length, error, instanceId, createSession]);
@@ -70,13 +62,14 @@ export const TerminalPage: React.FC = () => {
}
}, [sessions]);
// Fit active terminal when switching tabs
// Fit and focus active terminal when switching tabs
useEffect(() => {
if (activeSessionId && terminalRefs.current[activeSessionId]) {
const ref = terminalRefs.current[activeSessionId];
// Small delay to allow display:block to apply
const timer = setTimeout(() => {
ref.current?.fit();
ref.current?.focus();
}, 50);
return () => clearTimeout(timer);
}