Skip to content

Commit 8c5a928

Browse files
committed
fix(web): cancel dictation sends after controller completion
1 parent 956c6cb commit 8c5a928

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21042104
if (activePendingProgress) {
21052105
return activePendingProgress.isLastQuestion && Boolean(activePendingResolvedAnswers);
21062106
}
2107-
return composerSendState.hasSendableContent;
2107+
return composerSendState.hasSendableContent || voiceInputActive;
21082108
};
21092109

21102110
const submitComposerRef = useRef<

‎apps/web/src/speech/useEnvironmentSpeechInput.browser.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,41 @@ function SubmissionProbe({
398398
return null;
399399
}
400400

401+
it("does not retain a send when transcription finishes before the editor rerenders", async () => {
402+
setup({ destination: "env-a" });
403+
let finish!: (text: string) => void;
404+
mocks.transcripts = [
405+
new Promise<string>((resolve) => {
406+
finish = resolve;
407+
}),
408+
];
409+
mocks.drafts = { "thread-a": "Fix", "thread-b": "" };
410+
const submit = vi.fn();
411+
const cancel = vi.fn();
412+
await using screen = await render(<SubmissionProbe owner="thread-a" />);
413+
await act(() => mocks.voice.start());
414+
let stopping!: Promise<void>;
415+
await act(() => {
416+
stopping = mocks.voice.stop();
417+
});
418+
await vi.waitFor(() => expect(mocks.voice.state.phase).toBe("transcribing"));
419+
const stale = mocks.voice;
420+
await act(async () => {
421+
finish("the login bug");
422+
await stopping;
423+
expect(mocks.voice).toBe(stale);
424+
stale.submitAfterDictation(submit, cancel);
425+
});
426+
expect(cancel).toHaveBeenCalledOnce();
427+
expect(submit).not.toHaveBeenCalled();
428+
expect(mocks.drafts["thread-a"]).toBe("Fix the login bug");
429+
await screen.rerender(<div />);
430+
await screen.rerender(<SubmissionProbe owner="thread-b" />);
431+
await act(() => mocks.voice.start());
432+
expect(mocks.microphoneRequests).toEqual(["env-a", "env-a"]);
433+
await act(() => mocks.voice.cancel());
434+
});
435+
401436
it.each([
402437
["transcribing", "finish"],
403438
["post-processing", "finish"],

‎apps/web/src/speech/useEnvironmentSpeechInput.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ export function useEnvironmentSpeechInput(input: HookInput) {
596596
submit(current.readDraft().text);
597597
return;
598598
}
599+
if (!voiceInputBlocksSubmission(controller.currentState)) {
600+
cancel?.();
601+
return;
602+
}
599603
const pending: PendingSubmission = {
600604
environmentId: current.environmentId,
601605
ownerKey: current.ownerKey,

0 commit comments

Comments
 (0)