diff --git a/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.browser.test.tsx b/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.browser.test.tsx index 366fb4cfe76e4..81b558f96312f 100644 --- a/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.browser.test.tsx +++ b/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.browser.test.tsx @@ -9,6 +9,7 @@ vi.mock(import("~/state/pullRequests"), async (original) => { pullRequestEnvironment: { ...actual.pullRequestEnvironment, detail: ((target: unknown) => target) as never, + activity: ((target: unknown) => ({ activity: target })) as never, }, }; }); @@ -46,7 +47,7 @@ function Rows() { ); } -it("reads the panel's detail once intent rests on a row for 150 ms", async () => { +it("reads the panel's detail and activity once intent rests on a row for 150 ms", async () => { state.reads = []; await using screen = await render(, { // A bare hook probe; nothing here navigates. @@ -68,19 +69,17 @@ it("reads the panel's detail once intent rests on a row for 150 ms", async () => expect(state.reads).toEqual([]); await act(() => vi.advanceTimersByTime(1)); // Query atoms key on JSON order: this is the order the PRs page panel reads. - expect(JSON.stringify(state.reads.at(-1))).toBe( - JSON.stringify({ - environmentId, - input: { - projectId: row.projectId, - repository: "owner/repo", - number: 7, - host: "github.com", - allowStale: false, - }, - }), - ); + const reference = { + projectId: row.projectId, + repository: "owner/repo", + number: 7, + host: "github.com", + }; + expect(state.reads.slice(-2).map((read) => JSON.stringify(read))).toEqual([ + JSON.stringify({ environmentId, input: { ...reference, allowStale: false } }), + JSON.stringify({ activity: { environmentId, input: reference } }), + ]); await act(() => leave.click()); - expect(state.reads.at(-1)).toBeNull(); + expect(state.reads.slice(-2)).toEqual([null, null]); }); diff --git a/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.ts b/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.ts index a078ce2c94ff7..5d70a208b12a5 100644 --- a/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.ts +++ b/apps/web/src/components/pullRequest/usePullRequestIntentPrefetch.ts @@ -18,8 +18,9 @@ interface PullRequestIntentTarget { } /** - * Reads the detail a row's panel will ask for once the pointer or focus rests on it, so the - * click paints from it. Passing over rows asks the host nothing, and leaving a row stops reading it. + * Reads the detail and activity a row's panel will ask for once the pointer or focus rests on it, + * so the click paints from them. Passing over rows asks the host nothing, and leaving a row stops + * reading it. */ export function usePullRequestIntentPrefetch( isListed: (target: PullRequestIntentTarget) => boolean, @@ -29,17 +30,23 @@ export function usePullRequestIntentPrefetch( // A removed row fires no leave event. const listed = target !== null && isListed(target); if (target !== null && !listed) setTarget(null); - useEnvironmentQuery( + const reference = target === null || !listed + ? null + : pullRequestPanelReference({ ...target, host: target.host.toLowerCase() }); + useEnvironmentQuery( + target === null || reference === null ? null : pullRequestEnvironment.detail({ environmentId: target.environmentId, - input: { - ...pullRequestPanelReference({ ...target, host: target.host.toLowerCase() }), - allowStale: false, - }, + input: { ...reference, allowStale: false }, }), ); + useEnvironmentQuery( + target === null || reference === null + ? null + : pullRequestEnvironment.activity({ environmentId: target.environmentId, input: reference }), + ); return useStableCallback((next: PullRequestIntentTarget | null) => { clearTimeout(timer.current); if (next === null) {