From 3d9fdb2e2b07d5c637cb85a8d32cfe85a59ad5b7 Mon Sep 17 00:00:00 2001 From: Denis H <79399355+dplush@users.noreply.github.com> Date: Sat, 1 Aug 2026 17:33:21 +0200 Subject: [PATCH] fix(dashboard): avoid duplicate IME fallback input --- web/src/lib/pty-composition.test.ts | 18 ++++++++++++++++-- web/src/lib/pty-composition.ts | 11 ++++++----- web/src/pages/ChatPage.tsx | 5 ++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/web/src/lib/pty-composition.test.ts b/web/src/lib/pty-composition.test.ts index 45fb275b90..d60761857e 100644 --- a/web/src/lib/pty-composition.test.ts +++ b/web/src/lib/pty-composition.test.ts @@ -28,7 +28,7 @@ describe("createPtyCompositionForwarder", () => { expect(send).not.toHaveBeenCalled(); }); - it("keeps the fallback pending when xterm emits unrelated input", () => { + it("prefers xterm input in the grace window over the fallback", () => { vi.useFakeTimers(); const send = vi.fn(); const forwarder = createPtyCompositionForwarder(send); @@ -37,7 +37,21 @@ describe("createPtyCompositionForwarder", () => { forwarder.noteTerminalData("x"); vi.runAllTimers(); - expect(send).toHaveBeenCalledExactlyOnceWith("ä"); + expect(send).not.toHaveBeenCalled(); + }); + + it("forwards a second composition after the first fallback completes", () => { + vi.useFakeTimers(); + const send = vi.fn(); + const forwarder = createPtyCompositionForwarder(send); + + forwarder.onCompositionEnd("ä"); + vi.runAllTimers(); + forwarder.onCompositionEnd("ö"); + vi.runAllTimers(); + + expect(send).toHaveBeenNthCalledWith(1, "ä"); + expect(send).toHaveBeenNthCalledWith(2, "ö"); }); it("supersedes an earlier composition and cancels it on disposal", () => { diff --git a/web/src/lib/pty-composition.ts b/web/src/lib/pty-composition.ts index 329cb4c173..7944b8cb55 100644 --- a/web/src/lib/pty-composition.ts +++ b/web/src/lib/pty-composition.ts @@ -25,12 +25,13 @@ export function createPtyCompositionForwarder(send: (data: string) => void) { const committed = pending; clearPending(); if (committed) send(committed); - }, 0); + }, 16); }, - noteTerminalData(data: string) { - if (pending && data.startsWith(pending)) { - clearPending(); - } + noteTerminalData(_data: string) { + // Any xterm input in the short grace window is its own composition + // delivery (possibly chunked or normalization-different), so prefer it + // over the fallback to avoid duplicate text. + if (pending) clearPending(); }, dispose: clearPending, }; diff --git a/web/src/pages/ChatPage.tsx b/web/src/pages/ChatPage.tsx index b53f4086d6..a67525234a 100644 --- a/web/src/pages/ChatPage.tsx +++ b/web/src/pages/ChatPage.tsx @@ -1313,7 +1313,10 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) { // The deferred composition fallback is already committed text, so it // must not consume the mobile replacement window intended for xterm's // normal onData path. - sendComposedText = (data) => forwardPtyData(data, false); + sendComposedText = (data) => { + forwardPtyData(data, false); + mobileReplacementInputUntilRef.current = 0; + }; onDataDisposable = term.onData((data) => { compositionForwarder.noteTerminalData(data); forwardPtyData(data);