@devries-cameron20 / t3code Mirror · read-only / commits / 1ae5590a32
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 09:45 UTC

fix(web): find in thread no longer announces streamed count refreshes (#37204)

Julius Marminge committed Nov 16, 2026 at 08:18 UTC 1ae5590a329b14f9e35a94c02faf405f6c67a56e
4 files changed +106 -5
apps/web/src/components/chat/ThreadFindBar.tsx
+25 -5
@@ -1,9 +1,13 @@
1 -import { useEffect, useRef, type KeyboardEvent } from "react";
1 +import { useEffect, useRef, useState, type KeyboardEvent } from "react";
2 import { ChevronDownIcon, ChevronUpIcon, XIcon } from "lucide-react";
3 import { Button } from "../ui/button";
4 import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group";
5 import { cn } from "~/lib/utils";
6 -import { formatThreadFindCount } from "./threadFind";
6 +import {
7 + formatThreadFindCount,
8 + nextThreadFindAnnouncement,
9 + type ThreadFindAnnouncement,
10 +} from "./threadFind";
11 import { THREAD_DETAILS_CARD_GAP } from "./threadDetailsCardLayout";
12
13 interface ThreadFindBarProps {
@@ -14,6 +18,10 @@ interface ThreadFindBarProps {
18 readonly status: "loading" | "error" | null;
19 readonly onRetry: () => void;
20 readonly activeIndex: number;
21 + /** Bumped by each user search or step; background refreshes keep it. */
22 + readonly navigationId: number;
23 + /** Whether the label shows the outcome of `navigationId`: a count or a failure. */
24 + readonly settled: boolean;
25 readonly focusRequestId: number;
26 readonly onQueryChange: (query: string) => void;
27 readonly onNext: () => void;
@@ -37,8 +45,6 @@ export function ThreadFindBar(props: ThreadFindBarProps) {
45 props.open,
46 ]);
47
40 - if (!props.open) return null;
41 -
48 const hasQuery = props.query.trim().length > 0;
49 const noResults = hasQuery && !props.status && props.matchCount === 0;
50 let label = "";
@@ -47,6 +53,17 @@ export function ThreadFindBar(props: ThreadFindBarProps) {
53 }
54 if (props.status === "loading") label = "Searching…";
55 if (props.status === "error") label = "Search failed";
56 + const [storedAnnouncement, setAnnouncement] = useState<ThreadFindAnnouncement | null>(null);
57 + const announcement = nextThreadFindAnnouncement(storedAnnouncement, {
58 + navigationId: props.navigationId,
59 + text: label,
60 + settled: props.settled || props.status === "loading",
61 + provisional: props.status !== null,
62 + });
63 + if (announcement !== storedAnnouncement) setAnnouncement(announcement);
64 +
65 + if (!props.open) return null;
66 +
67 const navigationDisabled =
68 props.matchCount === 0 || props.status === "loading" || props.counting === true;
69 const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
@@ -87,8 +104,11 @@ export function ThreadFindBar(props: ThreadFindBarProps) {
104 onKeyDown={handleKeyDown}
105 />
106 <InputGroupAddon align="inline-end" inset="pill">
107 + <span aria-live="polite" className="sr-only">
108 + {announcement.text}
109 + </span>
110 <span
91 - aria-live="polite"
111 + aria-hidden
112 className={cn(
113 "min-w-10 text-center text-xs tabular-nums",
114 noResults ? "text-destructive" : "text-muted-foreground",
apps/web/src/components/chat/threadFind.test.ts new
+53
@@ -0,0 +1,53 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +import { nextThreadFindAnnouncement, type ThreadFindAnnouncement } from "./threadFind";
3 +
4 +type Step = Omit<ThreadFindAnnouncement, "provisional"> & { readonly provisional?: boolean };
5 +
6 +function replay(steps: readonly Step[]) {
7 + let current: ThreadFindAnnouncement | null = null;
8 + const spoken: string[] = [];
9 + for (const step of steps) {
10 + const next = nextThreadFindAnnouncement(current, { provisional: false, ...step });
11 + if (next.text !== (current?.text ?? "")) spoken.push(next.text);
12 + current = next;
13 + }
14 + return spoken;
15 +}
16 +
17 +describe("nextThreadFindAnnouncement", () => {
18 + it("speaks each settled search or step once and stays silent through streamed refreshes", () => {
19 + expect(
20 + replay([
21 + { navigationId: 1, text: "Searching…", settled: true, provisional: true },
22 + { navigationId: 1, text: "1/…", settled: false },
23 + { navigationId: 1, text: "1/3", settled: true },
24 + { navigationId: 1, text: "1/…", settled: false },
25 + { navigationId: 1, text: "1/4", settled: true },
26 + { navigationId: 2, text: "1/4", settled: false },
27 + { navigationId: 2, text: "2/4", settled: true },
28 + { navigationId: 2, text: "2/5", settled: true },
29 + ]),
30 + ).toEqual(["Searching…", "1/3", "2/4"]);
31 + });
32 +
33 + it("speaks a failure and the result of retrying it", () => {
34 + expect(
35 + replay([
36 + { navigationId: 1, text: "Search failed", settled: true, provisional: true },
37 + { navigationId: 1, text: "1/3", settled: true },
38 + { navigationId: 1, text: "1/4", settled: true },
39 + ]),
40 + ).toEqual(["Search failed", "1/3"]);
41 + });
42 +
43 + it("speaks a new search that ends on the same count as the last one", () => {
44 + expect(
45 + replay([
46 + { navigationId: 1, text: "Searching…", settled: true, provisional: true },
47 + { navigationId: 1, text: "0/0", settled: true },
48 + { navigationId: 2, text: "Searching…", settled: true, provisional: true },
49 + { navigationId: 2, text: "0/0", settled: true },
50 + ]),
51 + ).toEqual(["Searching…", "0/0", "Searching…", "0/0"]);
52 + });
53 +});
apps/web/src/components/chat/threadFind.ts
+25
@@ -23,3 +23,28 @@ export function stepThreadFindIndex(index: number, total: number, delta: number)
23 export function formatThreadFindCount(index: number, total: number): string {
24 return total <= 0 ? "0/0" : `${clampThreadFindIndex(index, total) + 1}/${total}`;
25 }
26 +
27 +export interface ThreadFindAnnouncement {
28 + readonly navigationId: number;
29 + readonly text: string;
30 + /** The label shows the outcome of `navigationId`: a count, a search or a failure. */
31 + readonly settled: boolean;
32 + /** "Searching…" or a failure: spoken, but a later count for the same navigation is too. */
33 + readonly provisional: boolean;
34 +}
35 +
36 +/**
37 + * What the find counter's live region says: the settled outcome of each
38 + * user search or step, once. Background refreshes during streaming keep the
39 + * navigation, so they stay silent. A new query passes through "Searching…",
40 + * so its count is spoken even when it equals the last one.
41 + */
42 +export function nextThreadFindAnnouncement(
43 + previous: ThreadFindAnnouncement | null,
44 + next: ThreadFindAnnouncement,
45 +): ThreadFindAnnouncement {
46 + if (!next.settled) return previous ?? { ...next, text: "" };
47 + if (previous?.navigationId !== next.navigationId) return next;
48 + if (previous.settled && !previous.provisional) return previous;
49 + return previous.text === next.text ? previous : next;
50 +}
apps/web/src/components/chat/useThreadFind.ts
+3
@@ -214,6 +214,9 @@ export function useThreadFind({
214 counting,
215 activeIndex,
216 status,
217 + navigationId: state.navigationId,
218 + settled:
219 + status === "error" || (status === null && !counting && navigationId === state.navigationId),
220 focusRequestId: state.focusRequestId,
221 onRetry: remote.refresh,
222 onQueryChange: (query: string) => {