@devries-cameron20 / t3code Mirror · read-only / commits / 45e0143cf1
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 22, 00:45 UTC

fix(web): thread title menu opens without a half-second wait on desktop (#33598)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

Theo Browne committed Nov 9, 2026 at 15:48 UTC 45e0143cf1a529e782077ecead4a921fa9430078
2 files changed +14 -42
apps/web/src/components/chat/ChatHeader.browser.test.tsx
+11 -2
@@ -3,6 +3,7 @@ import { expect, it, vi } from "vite-plus/test";
3 import { userEvent } from "vite-plus/test/browser";
4
5 const persisted = vi.hoisted(() => ({ title: "" }));
6 +const openMenu = vi.hoisted(() => vi.fn());
7 vi.mock(import("../../state/session"), async (importOriginal) => ({
8 ...(await importOriginal()),
9 useEnvironmentScope: () => true,
@@ -17,10 +18,10 @@ vi.mock(import("../../state/use-orchestration-command"), async (importOriginal)
18 }) as never,
19 }));
20 vi.mock(import("~/hooks/useThreadActionMenu"), () => ({
20 - useThreadActionMenu: () => ({ openMenu: () => {}, closeMenu: () => {} }),
21 + useThreadActionMenu: () => ({ openMenu, closeMenu: () => {} }),
22 }));
23
23 -import { render } from "../../../test/render";
24 +import { render, stubGlobal } from "../../../test/render";
25 import { ChatHeader } from "./ChatHeader";
26
27 function header(title: string) {
@@ -71,3 +72,11 @@ it.each(["blur", "Enter"] as const)(
72 expect(persisted.title).toBe("My edited title");
73 },
74 );
75 +
76 +it("opens the thread menu on a desktop title click without waiting", async () => {
77 + openMenu.mockClear();
78 + using _bridge = stubGlobal("desktopBridge", {});
79 + await using screen = await render(header("New thread"));
80 + await screen.getByRole("button", { name: "Thread actions for New thread" }).click();
81 + expect(openMenu).toHaveBeenCalledOnce();
82 +});
apps/web/src/components/chat/ChatHeader.tsx
+3 -40
@@ -68,8 +68,6 @@ function resolveRenameCommit(input: {
68 return { action: "commit", title: trimmed };
69 }
70
71 -// Delay the input-swallowing native menu through the double-click rename interval.
72 -const TITLE_MENU_OPEN_DELAY_MS = 500;
71 export const ChatHeader = memo(function ChatHeader({
72 activeThreadEnvironmentId,
73 activeThreadId,
@@ -205,54 +203,21 @@ export const ChatHeader = memo(function ChatHeader({
203 onFind: onFindInThread,
204 canShareWithGuest,
205 });
208 - const titleButtonRef = useRef<HTMLButtonElement | null>(null);
209 - const titleMenuTimerRef = useRef<number | null>(null);
210 - const cancelPendingTitleMenu = () => {
211 - if (titleMenuTimerRef.current === null) return;
212 - clearTimeout(titleMenuTimerRef.current);
213 - titleMenuTimerRef.current = null;
214 - };
215 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the pending title-menu timer when the thread switches or the header unmounts
216 - useEffect(
217 - () => () => {
218 - if (titleMenuTimerRef.current === null) return;
219 - clearTimeout(titleMenuTimerRef.current);
220 - titleMenuTimerRef.current = null;
221 - },
222 - // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A pending title menu belongs to the thread that was clicked, so switching threads drops it.
223 - [activeThreadEnvironmentId, activeThreadId],
224 - );
225 - const openTitleMenuNow = () => {
226 - cancelPendingTitleMenu();
227 - const rect = titleButtonRef.current?.getBoundingClientRect();
228 - if (!rect) return;
229 - openMenu({ x: rect.left, y: rect.bottom + 4 });
230 - };
206 const openMenuFromTitle = (event: ReactMouseEvent<HTMLButtonElement>) => {
207 if (isTrailingDoubleClick(event.detail)) return;
233 - const clickedChevron =
234 - (event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null;
235 - if (event.detail === 0 || clickedChevron || window.desktopBridge === undefined) {
236 - openTitleMenuNow();
237 - return;
238 - }
239 - cancelPendingTitleMenu();
240 - titleMenuTimerRef.current = window.setTimeout(() => {
241 - titleMenuTimerRef.current = null;
242 - openTitleMenuNow();
243 - }, TITLE_MENU_OPEN_DELAY_MS);
208 + const rect = event.currentTarget.getBoundingClientRect();
209 + openMenu({ x: rect.left, y: rect.bottom + 4 });
210 };
211 + // A native menu takes the second click, so only the in-page menu lets a double-click reach here.
212 const handleTitleDoubleClick = (event: ReactMouseEvent) => {
213 if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
214 if ((event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null) return;
248 - cancelPendingTitleMenu();
215 closeMenu();
216 startRename();
217 };
218 const handleHeaderContextMenu = (event: ReactMouseEvent) => {
219 if (renamingTitle !== null) return;
220 if (!isServerThread && onOpenProjectSettings === undefined) return;
255 - cancelPendingTitleMenu();
221 event.preventDefault();
222 if (!isServerThread) {
223 const api = readLocalApi();
@@ -380,13 +345,11 @@ export const ChatHeader = memo(function ChatHeader({
345 <TooltipTrigger
346 render={
347 <button
383 - ref={titleButtonRef}
348 type="button"
349 aria-label={`Thread actions for ${activeThreadTitle}`}
350 aria-haspopup="menu"
351 onClick={openMenuFromTitle}
352 onDoubleClick={canOperateThread ? handleTitleDoubleClick : undefined}
389 - onBlur={cancelPendingTitleMenu}
353 className="group/thread-title inline-flex min-w-0 max-w-full cursor-pointer items-center gap-1 rounded-sm text-left focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
354 />
355 }