fix: terminal reconnect typing and reset functionality
Frontend: - Fix term.onData to use wsRef.current instead of captured ws variable - Fix fitTerminal to use wsRef.current for resize messages - Fix sendData callback to use wsRef.current - This fixes 'cannot type' after WebSocket reconnect Backend: - Add SessionRef class for mutable session reference - Update _read_loop and _write_loop to use SessionRef - Reset now updates session_ref.session instead of returning - This keeps the WebSocket alive after reset instead of closing it
This commit is contained in:
@@ -225,8 +225,9 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
if (cols !== oldCols || rows !== oldRows) {
|
||||
termRef.current.refresh(0, rows - 1);
|
||||
}
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: "resize", cols, rows }));
|
||||
const currentWs = wsRef.current;
|
||||
if (currentWs?.readyState === WebSocket.OPEN) {
|
||||
currentWs.send(JSON.stringify({ type: "resize", cols, rows }));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -244,20 +245,21 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
|
||||
// Handle terminal input
|
||||
term.onData((data) => {
|
||||
if (ws.readyState !== WebSocket.OPEN) return;
|
||||
const currentWs = wsRef.current;
|
||||
if (currentWs?.readyState !== WebSocket.OPEN) return;
|
||||
|
||||
// Apply active modifier to single-character input
|
||||
const modifier = activeModifierRef.current;
|
||||
if (modifier && data.length === 1) {
|
||||
const modified = applyModifierToChar(data, modifier);
|
||||
if (modified) {
|
||||
ws.send(modified);
|
||||
currentWs.send(modified);
|
||||
onModifierChange?.(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ws.send(data);
|
||||
currentWs.send(data);
|
||||
});
|
||||
|
||||
// Handle container resize with ResizeObserver for accurate dimension tracking
|
||||
@@ -302,8 +304,9 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
// Notify parent about terminal readiness
|
||||
if (onTerminalReadyRef.current) {
|
||||
const sendData = (data: string) => {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(data);
|
||||
const currentWs = wsRef.current;
|
||||
if (currentWs?.readyState === WebSocket.OPEN) {
|
||||
currentWs.send(data);
|
||||
}
|
||||
};
|
||||
const focusInput = () => {
|
||||
|
||||
Reference in New Issue
Block a user