From 8b5acf9215b5a86aa52d95dd4bfd38de003930fb Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:04:01 -0500 Subject: [PATCH 1/2] fix(web): Cmd/Ctrl+F opens the browser find bar while a pull request is maximized The hidden pull request list and the preview.find command both claimed the key with nothing to answer it. Co-authored-by: only21mil <263261067+only21mil@users.noreply.github.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> --- .../PullRequestsColumn.browser.test.tsx | 59 ++++++ .../pullRequest/PullRequestsColumn.tsx | 3 +- .../src/shortcuts/chatRouteCommands.test.ts | 17 ++ apps/web/src/shortcuts/chatRouteCommands.ts | 8 +- ...ed-pull-request-leaves-browser-find.e2e.ts | 175 ++++++++++++++++++ 5 files changed, 260 insertions(+), 2 deletions(-) create mode 100644 apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx create mode 100644 scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx new file mode 100644 index 0000000000000..1e4de32289e69 --- /dev/null +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx @@ -0,0 +1,59 @@ +import { createRef, type RefObject } from "react"; +import { describe, expect, it } from "vite-plus/test"; + +import { render } from "../../../test/render"; +import { PullRequestsColumn } from "./PullRequestsColumn"; + +function createColumn(maximizedAway: boolean, scrollRef: RefObject) { + return ( + {}} + searchValue="" + involvement="all" + state="open" + host={undefined} + hostMenuOptions={[]} + onInvolvement={() => {}} + onState={() => {}} + onHost={() => {}} + searchInput={} + sortMenu={null} + filtersMenu={null} + savedViewsMenu={null} + rightPanelControl={null} + titlebarControls={null} + rightPanelOpen={maximizedAway} + maximizedAway={maximizedAway} + listBody={null} + scrollRef={scrollRef} + /> + ); +} + +function dispatchFindShortcut() { + const event = new KeyboardEvent("keydown", { + key: "f", + ctrlKey: true, + bubbles: true, + cancelable: true, + }); + window.dispatchEvent(event); + return event; +} + +describe("PullRequestsColumn find shortcut", () => { + it("leaves Cmd/Ctrl+F to the browser while the detail panel is maximized", async () => { + const scrollRef = createRef(); + await using screen = await render(createColumn(false, scrollRef)); + + await screen.rerender(createColumn(true, scrollRef)); + expect(dispatchFindShortcut().defaultPrevented).toBe(false); + + await screen.rerender(createColumn(false, scrollRef)); + expect(dispatchFindShortcut().defaultPrevented).toBe(true); + await expect + .element(screen.getByRole("textbox", { name: "Search pull requests" })) + .toHaveFocus(); + }); +}); diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.tsx index fdfe825790ba6..d4ca6d0d3b7e2 100644 --- a/apps/web/src/components/pullRequest/PullRequestsColumn.tsx +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.tsx @@ -138,6 +138,7 @@ export function PullRequestsColumn({ const searchExpanded = searchOpen || searchValue.length > 0; // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window keydown listener focuses the visible search input on Cmd/Ctrl+F useEffect(() => { + if (maximizedAway) return; const onKeyDown = (event: KeyboardEvent) => { if (event.defaultPrevented) return; if (event.key.toLowerCase() !== "f" || !(event.metaKey || event.ctrlKey)) return; @@ -151,7 +152,7 @@ export function PullRequestsColumn({ }; window.addEventListener("keydown", onKeyDown); return () => window.removeEventListener("keydown", onKeyDown); - }, [condensed]); + }, [condensed, maximizedAway]); if (!condensed && searchOpen) setSearchOpen(false); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- moves DOM focus to the in-flow search when the topbar search it was typed in unmounts useEffect(() => { diff --git a/apps/web/src/shortcuts/chatRouteCommands.test.ts b/apps/web/src/shortcuts/chatRouteCommands.test.ts index 3979368ff9032..db332610cd923 100644 --- a/apps/web/src/shortcuts/chatRouteCommands.test.ts +++ b/apps/web/src/shortcuts/chatRouteCommands.test.ts @@ -105,4 +105,21 @@ describe("preview commands", () => { expect(dispatch).toHaveBeenCalledWith(action); }); + + it("preview.find leaves the key unclaimed on non-thread chat routes", () => { + using dispatch = vi.spyOn(previewActions, "dispatchPreviewAction").mockImplementation(() => {}); + using register = vi.spyOn(dispatcher, "registerCommands").mockReturnValue(() => {}); + const router = { + state: { matches: [{ routeId: "/_chat/pull-requests", params: {} }] }, + } as unknown as AnyRouter; + using stack = new DisposableStack(); + stack.defer(installChatRouteCommands(router)); + const event = { preventDefault: vi.fn(), stopPropagation: vi.fn() } as unknown as KeyboardEvent; + + const result = register.mock.calls[0]![0]["preview.find"]!(event); + + expect(result).toBe(false); + expect(event.preventDefault).not.toHaveBeenCalled(); + expect(dispatch).not.toHaveBeenCalled(); + }); }); diff --git a/apps/web/src/shortcuts/chatRouteCommands.ts b/apps/web/src/shortcuts/chatRouteCommands.ts index 7cca45fbd81db..90ccf9fc2023f 100644 --- a/apps/web/src/shortcuts/chatRouteCommands.ts +++ b/apps/web/src/shortcuts/chatRouteCommands.ts @@ -186,7 +186,13 @@ export function installChatRouteCommands(router: AnyRouter): () => void { "preview.zoomIn": zoomCommand("zoom-in"), "preview.zoomOut": zoomCommand("zoom-out"), "preview.resetZoom": zoomCommand("reset-zoom"), - "preview.find": previewCommand("find"), + // Unclaimed, the browser's own find runs when no thread handles panel find. + "preview.find": (event) => { + const environmentId = readRouteEnvironmentId(); + if (!environmentId || !canOperatePreview(environmentId)) return false; + claim(event); + dispatchPreviewAction("find"); + }, }, { when: () => diff --git a/scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts b/scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts new file mode 100644 index 0000000000000..a1fa45202b5e8 --- /dev/null +++ b/scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts @@ -0,0 +1,175 @@ +/// +import { ProjectSnapshot } from "@t3tools/contracts"; +import { expect } from "e2e"; +import * as Effect from "effect/Effect"; +import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http"; + +import { T3_HOME } from "../e2e.config.ts"; +import { makeState, runPromise, test, WEB } from "./t3.ts"; + +const DESCRIPTION = "The review description should stay searchable with the browser find bar."; + +test( + "Cmd/Ctrl+F reaches the browser while a pull request is maximized", + WEB, + async ({ t3, app, browser, screen }) => { + const project = await t3.project("demo"); + const { projects } = await runPromise( + Effect.gen(function* () { + const issued = yield* makeState(T3_HOME).cli(["auth", "session", "issue", "--token-only"]); + return yield* HttpClient.execute( + HttpClientRequest.get(`${app.baseUrl}/api/projects`).pipe( + HttpClientRequest.bearerToken(issued.stdout.trim()), + ), + ).pipe( + Effect.flatMap(HttpClientResponse.filterStatusOk), + Effect.flatMap(HttpClientResponse.schemaBodyJson(ProjectSnapshot)), + ); + }).pipe(Effect.provide(FetchHttpClient.layer)), + ); + const projectId = projects.find((entry) => entry.workspaceRoot === project)!.id; + await browser.addInitScript( + ({ projectId, project, description }) => { + const entry = { + provider: "github", + host: "github.com", + projectId, + projectTitle: "demo", + repository: "example/demo", + number: 42, + title: "Keep the description searchable", + url: "https://github.com/example/demo/pull/42", + author: { login: "demo-author", name: null, avatarUrl: null }, + headBranch: "fix/search", + baseBranch: "main", + state: "open", + isDraft: false, + mergeability: "mergeable", + additions: 12, + deletions: 3, + createdAt: "2026-11-20T12:00:00Z", + updatedAt: "2026-11-20T12:00:00Z", + viewerReviewRequested: false, + labels: [], + }; + const routing = { + accountId: "demo", + host: "github.com", + provider: "github", + viewer: "demo-viewer", + }; + const responses: Record = { + "pullRequests.list": { + viewers: { "github.com": "demo-viewer" }, + providers: [ + { + host: "github.com", + kind: "github", + searchesOnHost: true, + projectCount: 1, + configured: true, + detail: null, + projectIds: [projectId], + }, + ], + entries: [entry], + errors: [], + truncated: false, + nextCursors: {}, + }, + "pullRequests.detail": { + ...entry, + workspaceRoot: project, + body: description, + changedFiles: 1, + mergedAt: null, + closedAt: null, + reviewers: [], + checks: [], + mergeCapabilities: { merge: false, squash: false, rebase: false }, + capabilities: { + diff: false, + comment: false, + actions: [], + mergeMethods: [], + search: true, + review: { inlineComment: false, reply: false, resolve: false, verdicts: [] }, + reviewers: { request: false, listCandidates: false }, + }, + viewerPermissions: { + actions: [], + comment: false, + resolve: false, + verdicts: [], + requestReviewers: false, + }, + }, + "pullRequests.summary": entry, + "pullRequests.preview": entry, + "pullRequests.activity": { + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], + }, + "pullRequests.checks": { state: "open", checks: [] }, + "pullRequests.listStats": { stats: [] }, + "pullRequests.filterOptions": { + labels: [], + authors: [], + references: [], + truncated: false, + }, + "pullRequests.stack": null, + "pullRequests.linkedThreads": { threads: [] }, + "pullRequests.routing": { ...routing, projectTitle: "demo", workspaceRoot: project }, + "pullRequests.routingIdentity": routing, + }; + const send = WebSocket.prototype.send; + WebSocket.prototype.send = function (data) { + const request: { _tag: string; id: string; tag: string } | null = + typeof data === "string" ? JSON.parse(data) : null; + if (request?._tag !== "Request" || !(request.tag in responses)) { + return send.call(this, data); + } + queueMicrotask(() => + this.dispatchEvent( + new MessageEvent("message", { + data: JSON.stringify({ + _tag: "Exit", + requestId: request.id, + exit: { _tag: "Success", value: responses[request.tag] }, + }), + }), + ), + ); + }; + }, + { projectId, project, description: DESCRIPTION }, + ); + + await t3.open("/pull-requests"); + await screen.getByRole("button", /^Open #42 /).tap(); + await screen.getByRole("button", "Maximize panel", { exact: true }).tap(); + await screen.getByText(DESCRIPTION).tap(); + await browser.evaluate(() => { + window.addEventListener( + "keydown", + (event) => { + if (event.key === "f") Object.assign(window, { findShortcut: event }); + }, + { capture: true }, + ); + return null; + }); + await browser.keyboard.press("ControlOrMeta+f"); + await app.screenshot("maximized-find"); + expect( + await browser.evaluate( + () => (window as { findShortcut?: KeyboardEvent }).findShortcut?.defaultPrevented ?? null, + ), + "The app leaves Cmd/Ctrl+F to the browser's find bar", + ).toBe(false); + }, +); From 74e1b2ff831e00e147bf7ce09e89a6d7a931b170 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 24 Nov 2026 02:41:13 +0000 Subject: [PATCH 2/2] test(web): drop the mocked-RPC find scenario The unit and browser tests already fail without the fix; the scenario replaced about fifteen pull request RPC responses by patching WebSocket. Co-Authored-By: Claude Opus 5.5 --- ...ed-pull-request-leaves-browser-find.e2e.ts | 175 ------------------ 1 file changed, 175 deletions(-) delete mode 100644 scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts diff --git a/scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts b/scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts deleted file mode 100644 index a1fa45202b5e8..0000000000000 --- a/scripts/scenarios/maximized-pull-request-leaves-browser-find.e2e.ts +++ /dev/null @@ -1,175 +0,0 @@ -/// -import { ProjectSnapshot } from "@t3tools/contracts"; -import { expect } from "e2e"; -import * as Effect from "effect/Effect"; -import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http"; - -import { T3_HOME } from "../e2e.config.ts"; -import { makeState, runPromise, test, WEB } from "./t3.ts"; - -const DESCRIPTION = "The review description should stay searchable with the browser find bar."; - -test( - "Cmd/Ctrl+F reaches the browser while a pull request is maximized", - WEB, - async ({ t3, app, browser, screen }) => { - const project = await t3.project("demo"); - const { projects } = await runPromise( - Effect.gen(function* () { - const issued = yield* makeState(T3_HOME).cli(["auth", "session", "issue", "--token-only"]); - return yield* HttpClient.execute( - HttpClientRequest.get(`${app.baseUrl}/api/projects`).pipe( - HttpClientRequest.bearerToken(issued.stdout.trim()), - ), - ).pipe( - Effect.flatMap(HttpClientResponse.filterStatusOk), - Effect.flatMap(HttpClientResponse.schemaBodyJson(ProjectSnapshot)), - ); - }).pipe(Effect.provide(FetchHttpClient.layer)), - ); - const projectId = projects.find((entry) => entry.workspaceRoot === project)!.id; - await browser.addInitScript( - ({ projectId, project, description }) => { - const entry = { - provider: "github", - host: "github.com", - projectId, - projectTitle: "demo", - repository: "example/demo", - number: 42, - title: "Keep the description searchable", - url: "https://github.com/example/demo/pull/42", - author: { login: "demo-author", name: null, avatarUrl: null }, - headBranch: "fix/search", - baseBranch: "main", - state: "open", - isDraft: false, - mergeability: "mergeable", - additions: 12, - deletions: 3, - createdAt: "2026-11-20T12:00:00Z", - updatedAt: "2026-11-20T12:00:00Z", - viewerReviewRequested: false, - labels: [], - }; - const routing = { - accountId: "demo", - host: "github.com", - provider: "github", - viewer: "demo-viewer", - }; - const responses: Record = { - "pullRequests.list": { - viewers: { "github.com": "demo-viewer" }, - providers: [ - { - host: "github.com", - kind: "github", - searchesOnHost: true, - projectCount: 1, - configured: true, - detail: null, - projectIds: [projectId], - }, - ], - entries: [entry], - errors: [], - truncated: false, - nextCursors: {}, - }, - "pullRequests.detail": { - ...entry, - workspaceRoot: project, - body: description, - changedFiles: 1, - mergedAt: null, - closedAt: null, - reviewers: [], - checks: [], - mergeCapabilities: { merge: false, squash: false, rebase: false }, - capabilities: { - diff: false, - comment: false, - actions: [], - mergeMethods: [], - search: true, - review: { inlineComment: false, reply: false, resolve: false, verdicts: [] }, - reviewers: { request: false, listCandidates: false }, - }, - viewerPermissions: { - actions: [], - comment: false, - resolve: false, - verdicts: [], - requestReviewers: false, - }, - }, - "pullRequests.summary": entry, - "pullRequests.preview": entry, - "pullRequests.activity": { - comments: [], - commentCount: 0, - commentsTruncated: false, - reviewThreads: [], - commits: [], - }, - "pullRequests.checks": { state: "open", checks: [] }, - "pullRequests.listStats": { stats: [] }, - "pullRequests.filterOptions": { - labels: [], - authors: [], - references: [], - truncated: false, - }, - "pullRequests.stack": null, - "pullRequests.linkedThreads": { threads: [] }, - "pullRequests.routing": { ...routing, projectTitle: "demo", workspaceRoot: project }, - "pullRequests.routingIdentity": routing, - }; - const send = WebSocket.prototype.send; - WebSocket.prototype.send = function (data) { - const request: { _tag: string; id: string; tag: string } | null = - typeof data === "string" ? JSON.parse(data) : null; - if (request?._tag !== "Request" || !(request.tag in responses)) { - return send.call(this, data); - } - queueMicrotask(() => - this.dispatchEvent( - new MessageEvent("message", { - data: JSON.stringify({ - _tag: "Exit", - requestId: request.id, - exit: { _tag: "Success", value: responses[request.tag] }, - }), - }), - ), - ); - }; - }, - { projectId, project, description: DESCRIPTION }, - ); - - await t3.open("/pull-requests"); - await screen.getByRole("button", /^Open #42 /).tap(); - await screen.getByRole("button", "Maximize panel", { exact: true }).tap(); - await screen.getByText(DESCRIPTION).tap(); - await browser.evaluate(() => { - window.addEventListener( - "keydown", - (event) => { - if (event.key === "f") Object.assign(window, { findShortcut: event }); - }, - { capture: true }, - ); - return null; - }); - await browser.keyboard.press("ControlOrMeta+f"); - await app.screenshot("maximized-find"); - expect( - await browser.evaluate( - () => (window as { findShortcut?: KeyboardEvent }).findShortcut?.defaultPrevented ?? null, - ), - "The app leaves Cmd/Ctrl+F to the browser's find bar", - ).toBe(false); - }, -);