Skip to content

Commit 91ec7a8

Browse files
committed
fix(web): a focused pull request row keeps its prefetch when the pointer leaves
1 parent 4c8e3e8 commit 91ec7a8

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { SourceControlProviderKind } from "@t3tools/contracts";
2+
import { expect, it, vi } from "vite-plus/test";
3+
import { userEvent } from "vite-plus/test/browser";
4+
5+
vi.mock(import("~/state/query"), async (original) => ({
6+
...(await original()),
7+
useEnvironmentQuery: (() => ({})) as never,
8+
}));
9+
10+
import { act, render } from "../../../test/render";
11+
import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic";
12+
import { PullRequestRow } from "./PullRequestRow";
13+
14+
const entry = {
15+
environmentId: "env-1",
16+
provider: SourceControlProviderKind.make("github"),
17+
host: "github.com",
18+
projectId: "project-1",
19+
projectTitle: "t3code",
20+
repository: "pingdotgg/t3code",
21+
title: "Add the pull requests page",
22+
url: "https://github.com/pingdotgg/t3code/pull/7",
23+
author: { login: "octocat", name: null, avatarUrl: null },
24+
headBranch: "feat/branch-7",
25+
baseBranch: "main",
26+
state: "open",
27+
isDraft: false,
28+
mergeability: "mergeable",
29+
additions: 0,
30+
deletions: 0,
31+
createdAt: "2026-07-01T00:00:00Z",
32+
updatedAt: "2026-07-02T00:00:00Z",
33+
viewerReviewRequested: false,
34+
number: 7,
35+
labels: [],
36+
} as unknown as EnvironmentPullRequestEntry;
37+
38+
it("keeps a row's intent while either the pointer or focus is still on it", async () => {
39+
const onIntent = vi.fn();
40+
await using screen = await render(
41+
<PullRequestRow
42+
entry={entry}
43+
selected={false}
44+
showProjectTitle
45+
showProvider={false}
46+
onSelect={() => undefined}
47+
onIntent={onIntent}
48+
hostActions={new Set()}
49+
onActed={() => undefined}
50+
/>,
51+
);
52+
const row = screen.getByRole("button", { name: /Add the pull requests page/ });
53+
54+
await act(() => (row.element() as HTMLElement).focus());
55+
await userEvent.hover(row);
56+
await userEvent.unhover(row);
57+
expect(onIntent).toHaveBeenLastCalledWith(entry);
58+
59+
await userEvent.hover(row);
60+
await act(() => (row.element() as HTMLElement).blur());
61+
expect(onIntent).toHaveBeenLastCalledWith(entry);
62+
63+
await userEvent.unhover(row);
64+
expect(onIntent).toHaveBeenLastCalledWith(null);
65+
});

‎apps/web/src/components/pullRequest/PullRequestRow.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ function PullRequestRowImpl({
119119
aria-current={selected ? "true" : undefined}
120120
onClick={() => onSelect(entry)}
121121
onPointerEnter={() => onIntent?.(entry)}
122-
onPointerLeave={() => onIntent?.(null)}
122+
onPointerLeave={(event) => {
123+
if (event.currentTarget !== document.activeElement) onIntent?.(null);
124+
}}
123125
onFocus={() => onIntent?.(entry)}
124-
onBlur={() => onIntent?.(null)}
126+
onBlur={(event) => {
127+
if (!event.currentTarget.matches(":hover")) onIntent?.(null);
128+
}}
125129
className={cn(
126130
PULL_REQUEST_ROW_CLASS,
127131
PAGE_ROW_CLASS,

0 commit comments

Comments
 (0)