Skip to content

Commit 65250a4

Browse files
t3dotggclaude
andcommitted
fix(web): thread title menu opens without a half-second wait on desktop
A single click on the chat header title waited 500 ms on desktop so a double-click could start a rename before the native menu opened. The menu now opens at once on every surface. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 3e4d449 commit 65250a4

2 files changed

Lines changed: 14 additions & 42 deletions

File tree

‎apps/web/src/components/chat/ChatHeader.browser.test.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect, it, vi } from "vite-plus/test";
33
import { userEvent } from "vite-plus/test/browser";
44

55
const persisted = vi.hoisted(() => ({ title: "" }));
6+
const openMenu = vi.hoisted(() => vi.fn());
67
vi.mock(import("../../state/session"), async (importOriginal) => ({
78
...(await importOriginal()),
89
useEnvironmentScope: () => true,
@@ -17,10 +18,10 @@ vi.mock(import("../../state/use-orchestration-command"), async (importOriginal)
1718
}) as never,
1819
}));
1920
vi.mock(import("~/hooks/useThreadActionMenu"), () => ({
20-
useThreadActionMenu: () => ({ openMenu: () => {}, closeMenu: () => {} }),
21+
useThreadActionMenu: () => ({ openMenu, closeMenu: () => {} }),
2122
}));
2223

23-
import { render } from "../../../test/render";
24+
import { render, stubGlobal } from "../../../test/render";
2425
import { ChatHeader } from "./ChatHeader";
2526

2627
function header(title: string) {
@@ -71,3 +72,11 @@ it.each(["blur", "Enter"] as const)(
7172
expect(persisted.title).toBe("My edited title");
7273
},
7374
);
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‎

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ function resolveRenameCommit(input: {
6868
return { action: "commit", title: trimmed };
6969
}
7070

71-
// Delay the input-swallowing native menu through the double-click rename interval.
72-
const TITLE_MENU_OPEN_DELAY_MS = 500;
7371
export const ChatHeader = memo(function ChatHeader({
7472
activeThreadEnvironmentId,
7573
activeThreadId,
@@ -205,54 +203,21 @@ export const ChatHeader = memo(function ChatHeader({
205203
onFind: onFindInThread,
206204
canShareWithGuest,
207205
});
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-
};
231206
const openMenuFromTitle = (event: ReactMouseEvent<HTMLButtonElement>) => {
232207
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 });
244210
};
211+
// A native menu takes the second click, so only the in-page menu lets a double-click reach here.
245212
const handleTitleDoubleClick = (event: ReactMouseEvent) => {
246213
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
247214
if ((event.target as HTMLElement).closest("[data-thread-title-chevron]") !== null) return;
248-
cancelPendingTitleMenu();
249215
closeMenu();
250216
startRename();
251217
};
252218
const handleHeaderContextMenu = (event: ReactMouseEvent) => {
253219
if (renamingTitle !== null) return;
254220
if (!isServerThread && onOpenProjectSettings === undefined) return;
255-
cancelPendingTitleMenu();
256221
event.preventDefault();
257222
if (!isServerThread) {
258223
const api = readLocalApi();
@@ -380,13 +345,11 @@ export const ChatHeader = memo(function ChatHeader({
380345
<TooltipTrigger
381346
render={
382347
<button
383-
ref={titleButtonRef}
384348
type="button"
385349
aria-label={`Thread actions for ${activeThreadTitle}`}
386350
aria-haspopup="menu"
387351
onClick={openMenuFromTitle}
388352
onDoubleClick={canOperateThread ? handleTitleDoubleClick : undefined}
389-
onBlur={cancelPendingTitleMenu}
390353
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"
391354
/>
392355
}

0 commit comments

Comments
 (0)