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, 18:30 UTC
fix(web): opening a thread on a touch tablet no longer focuses the composer (#29496)
Julius Marminge committed
Nov 12, 2026 at 19:31 UTC
87a772a3c6afc8780f1b85b40599278f70c739a5
2 files changed
+62
-4
apps/web/src/components/ChatView.browser.test.tsx
+46
-1
@@ -24,7 +24,7 @@ import {
24
threadWithHistory,
25
type FakeDriver,
26
} from "../../test/fakeEnvironment";
27
-import { act, render } from "../../test/render";
27
+import { act, fakeTimers, render } from "../../test/render";
28
29
// The socket is the only fake layer; see test/appScenarios.renders.tsx.
30
vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
@@ -258,3 +258,48 @@ it("Enter on an empty prompt resumes an interrupted thread", async () => {
258
),
259
);
260
});
261
+
262
+it("opening a thread or returning to the window on a touch tablet does not focus the composer", async () => {
263
+ const realMatchMedia = window.matchMedia.bind(window);
264
+ using _touch = vi
265
+ .spyOn(window, "matchMedia")
266
+ .mockImplementation((query) => realMatchMedia(query === "(pointer: coarse)" ? "all" : query));
267
+ const first = threadWithHistory("thread-29469-a", 1);
268
+ const second = threadWithHistory("thread-29469-b", 1);
269
+ using _environment = installFakeEnvironment([first, second]);
270
+ // iPad Pro 11 in landscape: the desktop layout, above max-sm.
271
+ await page.viewport(1194, 834);
272
+ __setClientSettingsForTests({
273
+ ...DEFAULT_CLIENT_SETTINGS,
274
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
275
+ });
276
+ const router = getRouter(
277
+ createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${first.id}`] }),
278
+ );
279
+ await router.load();
280
+ await using _app = await render(<AppRoot router={router} />, {
281
+ // AppRoot brings its own router.
282
+ router: false,
283
+ });
284
+ const composer = page.getByTestId("composer-editor");
285
+ await expect.element(page.getByText(`Answer 0 for ${first.id}.`)).toBeVisible();
286
+
287
+ // Fake frames hold the next thread entry's focus frame until the test advances it.
288
+ using _timers = fakeTimers();
289
+ await act(() =>
290
+ router.navigate({
291
+ to: "/$environmentId/$threadId",
292
+ params: { environmentId: ENVIRONMENT_ID, threadId: second.id },
293
+ }),
294
+ );
295
+ await expect.element(page.getByText(`Answer 0 for ${second.id}.`)).toBeVisible();
296
+ vi.advanceTimersToNextFrame();
297
+ // Focusing the editor raises the on-screen keyboard, which shrinks the page on iPadOS.
298
+ expect(document.activeElement).not.toBe(composer.element());
299
+
300
+ // ChatView waits two frames after window focus before refocusing the composer.
301
+ window.dispatchEvent(new FocusEvent("focus"));
302
+ vi.advanceTimersToNextFrame();
303
+ vi.advanceTimersToNextFrame();
304
+ expect(document.activeElement).not.toBe(composer.element());
305
+});
apps/web/src/components/ChatView.tsx
+16
-3
@@ -423,6 +423,8 @@ type ChatViewProps =
423
424
const DismissedFallbackWindowSchema = Schema.NullOr(Schema.String);
425
426
+const ignoreComposerFocus = () => {};
427
+
428
export default function ChatView(props: ChatViewProps) {
429
const {
430
environmentId,
@@ -713,6 +715,8 @@ export default function ChatView(props: ChatViewProps) {
715
}, [isWorkspaceFileDragActive]);
716
const prefersPlanSidebarSheet = useMediaQuery(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY);
717
const isMobileViewport = useMediaQuery("max-sm");
718
+ // Focusing the composer without a tap raises the on-screen keyboard on touch devices.
719
+ const isCoarsePointer = useMediaQuery({ pointer: "coarse" });
720
const [workspaceLayoutElement, setWorkspaceLayoutElement] = useState<HTMLDivElement | null>(null);
721
const threadPanelPopoverAnchorRef = useRef<HTMLElement | null>(null);
722
const [terminalUiLaunchContext, setTerminalUiLaunchContext] =
@@ -2146,12 +2150,20 @@ export default function ChatView(props: ChatViewProps) {
2150
workspaceLayoutElement,
2151
!embedded,
2152
terminalUiState.terminalOpen,
2149
- focusComposerStable,
2153
+ isCoarsePointer ? ignoreComposerFocus : focusComposerStable,
2154
);
2155
2152
- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window focus listener that refocuses the composer after the window regains focus
2156
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window focus listener that refocuses the composer after the window regains focus on a fine pointer
2157
useEffect(() => {
2154
- if (embedded || !activeThread?.id || terminalUiState.terminalOpen || isMobileViewport) return;
2158
+ if (
2159
+ embedded ||
2160
+ !activeThread?.id ||
2161
+ terminalUiState.terminalOpen ||
2162
+ isMobileViewport ||
2163
+ isCoarsePointer
2164
+ ) {
2165
+ return;
2166
+ }
2167
let frame: number | null = null;
2168
const onWindowFocus = () => {
2169
if (frame !== null) window.cancelAnimationFrame(frame);
@@ -2178,6 +2190,7 @@ export default function ChatView(props: ChatViewProps) {
2190
activeThread?.id,
2191
embedded,
2192
focusComposerStable,
2193
+ isCoarsePointer,
2194
isMobileViewport,
2195
terminalUiState.terminalOpen,
2196
]);