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, 21:00 UTC
fix(web): double-clicking another thread in the sidebar renames it instead of focusing its composer (#27287)
Julius Marminge committed
Nov 11, 2026 at 15:39 UTC
ea3e20a0e283ba3bf7c3d6004142d8f13b603319
3 files changed
+63
-10
apps/web/src/components/ChatView.tsx
+6
-10
@@ -5,6 +5,7 @@ import { resolveNewThreadModelSelection } from "@t3tools/shared/usageLimits";
5
import { queuedRunEditBlockedReason } from "@t3tools/client-runtime/queued-run-edit";
6
import { ScrollToEndButton, WorkspaceFileDropOverlay } from "./chat/TimelineOverlays";
7
import { usePasteToFocusComposer } from "./chat/usePasteToFocusComposer";
8
+import { useFocusComposerOnThreadOpen } from "./chat/useFocusComposerOnThreadOpen";
9
import { configuredHostedAppUrl } from "../hostedPairing";
10
import { announcedRun, isDetailBehindShell } from "./chat/threadActivityAnnouncement";
11
import {
@@ -2116,16 +2117,11 @@ export default function ChatView(props: ChatViewProps) {
2117
setTimelineAnchor,
2118
});
2119
2119
- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- schedules a frame to focus the composer DOM element when a thread opens with the terminal closed
2120
- useEffect(() => {
2121
- if (embedded || !activeThread?.id || terminalUiState.terminalOpen) return;
2122
- const frame = window.requestAnimationFrame(() => {
2123
- focusComposerStable();
2124
- });
2125
- return () => {
2126
- window.cancelAnimationFrame(frame);
2127
- };
2128
- }, [activeThread?.id, embedded, focusComposerStable, terminalUiState.terminalOpen]);
2120
+ useFocusComposerOnThreadOpen(
2121
+ activeThread?.id,
2122
+ !embedded && !terminalUiState.terminalOpen,
2123
+ focusComposerStable,
2124
+ );
2125
2126
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window focus listener that refocuses the composer after the window regains focus
2127
useEffect(() => {
apps/web/src/components/chat/useFocusComposerOnThreadOpen.browser.test.tsx
new
+36
@@ -0,0 +1,36 @@
1
+import { useRef } from "react";
2
+import { expect, it, vi } from "vite-plus/test";
3
+
4
+import { act, fakeTimers, render } from "../../../test/render";
5
+import { useFocusComposerOnThreadOpen } from "./useFocusComposerOnThreadOpen";
6
+
7
+function ThreadProbe(props: { threadId: string }) {
8
+ const composerRef = useRef<HTMLTextAreaElement>(null);
9
+ useFocusComposerOnThreadOpen(props.threadId, true, () => composerRef.current?.focus());
10
+ return (
11
+ <>
12
+ <div data-sidebar-row="thread:beta">
13
+ <input aria-label="Thread title" />
14
+ </div>
15
+ <textarea aria-label="Message" ref={composerRef} />
16
+ </>
17
+ );
18
+}
19
+
20
+// regression: #27195 double-clicking another thread's row lost its rename field to the composer
21
+it("keeps the sidebar rename input when a double-click opens another thread", async () => {
22
+ // The first render schedules the frame.
23
+ using _frames = fakeTimers();
24
+ await using screen = await render(<ThreadProbe threadId="alpha" />, {
25
+ // A bare hook probe; nothing here navigates.
26
+ router: false,
27
+ });
28
+ await act(() => vi.advanceTimersToNextFrame());
29
+ await expect.element(screen.getByRole("textbox", { name: "Message" })).toHaveFocus();
30
+
31
+ const renameInput = screen.getByRole("textbox", { name: "Thread title" });
32
+ renameInput.element().focus();
33
+ await screen.rerender(<ThreadProbe threadId="beta" />);
34
+ await act(() => vi.advanceTimersToNextFrame());
35
+ await expect.element(renameInput).toHaveFocus();
36
+});
apps/web/src/components/chat/useFocusComposerOnThreadOpen.ts
new
+21
@@ -0,0 +1,21 @@
1
+import { useEffect } from "react";
2
+
3
+/** Lands the caret in the composer a frame after a thread opens. */
4
+export function useFocusComposerOnThreadOpen(
5
+ threadId: string | undefined,
6
+ enabled: boolean,
7
+ focusComposer: () => void,
8
+) {
9
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- schedules a frame to focus the composer DOM element when a thread opens with the terminal closed
10
+ useEffect(() => {
11
+ if (!threadId || !enabled) return;
12
+ const frame = window.requestAnimationFrame(() => {
13
+ // Double-clicking a sidebar row opens its thread and its rename field in one gesture.
14
+ if (document.activeElement?.matches("[data-sidebar-row] input")) return;
15
+ focusComposer();
16
+ });
17
+ return () => {
18
+ window.cancelAnimationFrame(frame);
19
+ };
20
+ }, [threadId, enabled, focusComposer]);
21
+}