From 3705e72b6d96b1ee4e424e3744267476194ece4a Mon Sep 17 00:00:00 2001 From: Jaime Idolpx Date: Thu, 11 Jun 2026 00:22:11 -0400 Subject: [PATCH] feat(SerialConsolePage): enhance echo handling by implementing an echo queue to suppress self-echoes --- src/app/components/SerialConsolePage.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/components/SerialConsolePage.tsx b/src/app/components/SerialConsolePage.tsx index 01bdee1..626ec2e 100644 --- a/src/app/components/SerialConsolePage.tsx +++ b/src/app/components/SerialConsolePage.tsx @@ -12,6 +12,7 @@ export default function SerialConsolePage({ onBack }: Props) { const termRef = useRef(null); const fitRef = useRef(null); const lineBuffer = useRef(''); + const echoQueue = useRef([]); const { status, send, subscribe } = useWs(); // Keep a stable ref to `send` so the xterm onData closure never goes stale @@ -50,9 +51,11 @@ export default function SerialConsolePage({ onBack }: Props) { term.onData((data) => { for (const char of data) { if (char === '\r' || char === '\n') { - term.write('\r\n'); - sendRef.current(lineBuffer.current + '\r'); + const line = lineBuffer.current + '\r'; lineBuffer.current = ''; + term.write('\r\n'); + echoQueue.current.push(line); + sendRef.current(line); } else if (char === '\x7f' || char === '\b') { if (lineBuffer.current.length > 0) { lineBuffer.current = lineBuffer.current.slice(0, -1); @@ -79,9 +82,14 @@ export default function SerialConsolePage({ onBack }: Props) { }; }, []); - // Forward all incoming WS messages to the terminal + // Forward all incoming WS messages to the terminal, suppressing our own echoes useEffect(() => { return subscribe((msg) => { + const idx = echoQueue.current.indexOf(msg); + if (idx !== -1) { + echoQueue.current.splice(idx, 1); + return; + } termRef.current?.write(msg); }); }, [subscribe]);