From fa2c2d103cfb0bad66316924a135179dc22a447b Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:25:07 -0500 Subject: [PATCH] fix(web): Retry on the Pull Requests list only refetches the environments that failed Retry restarted every environment's list read, including ones still loading. It now reloads only failed reads, as the Issues page does since #38654. --- .../pullRequest/PullRequestsPage.tsx | 4 +- apps/web/src/state/pullRequests.test.ts | 47 +++++++++++++++---- apps/web/src/state/pullRequests.ts | 14 +++++- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestsPage.tsx b/apps/web/src/components/pullRequest/PullRequestsPage.tsx index 7702c9b266518..bd99b381c05ee 100644 --- a/apps/web/src/components/pullRequest/PullRequestsPage.tsx +++ b/apps/web/src/components/pullRequest/PullRequestsPage.tsx @@ -1269,7 +1269,7 @@ export function PullRequestsPage() { listQuery.refresh()} + onRetry={listQuery.retry} /> ) : carriedToNothing ? ( @@ -1313,7 +1313,7 @@ export function PullRequestsPage() { {listError && shownCount > 0 ? (
{gt("{error} Showing the last pull requests loaded.", { error: listError })} -
diff --git a/apps/web/src/state/pullRequests.test.ts b/apps/web/src/state/pullRequests.test.ts index c0839ff0a728e..e53c7539418f7 100644 --- a/apps/web/src/state/pullRequests.test.ts +++ b/apps/web/src/state/pullRequests.test.ts @@ -10,19 +10,20 @@ import { type PullRequestSummary, } from "@t3tools/contracts"; import * as Cause from "effect/Cause"; +import * as Effect from "effect/Effect"; import { AsyncResult, Atom } from "effect/reactivity"; import { describe, expect, it, vi } from "vite-plus/test"; const listAnswers = vi.hoisted(() => new Map()); +const registry = await vi.hoisted(async () => + (await import("effect/reactivity")).AtomRegistry.make(), +); -vi.mock("@effect/atom-react", async (importOriginal) => { - const { AtomRegistry } = await import("effect/reactivity"); - const registry = AtomRegistry.make(); - return { - ...(await importOriginal()), - useAtomValue: (atom: Atom.Atom) => registry.get(atom), - }; -}); +vi.mock("@effect/atom-react", async (importOriginal) => ({ + ...(await importOriginal()), + useAtomValue: (atom: Atom.Atom) => registry.get(atom), +})); +vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: registry })); vi.mock("@t3tools/client-runtime/state/pull-requests", async (importOriginal) => { const actual = await importOriginal(); @@ -551,6 +552,36 @@ describe("pull request list answers across a reload", () => { }); }); + it("retries only the environment whose list failed, leaving one still loading to finish", () => { + const requests: string[] = []; + const read = (environmentId: string, answer: Effect.Effect) => + Atom.make( + Effect.suspend(() => { + requests.push(environmentId); + return answer; + }), + ); + const slow = EnvironmentId.make("env-slow"); + const failing = EnvironmentId.make("env-failing"); + const reads = [read(slow, Effect.never), read(failing, Effect.fail("Unreachable"))]; + listAnswers.set(slow, reads[0]); + listAnswers.set(failing, reads[1]); + const unmounts = reads.map((atom) => registry.mount(atom)); + try { + const view = usePullRequestList([ + { environmentId: slow, input }, + { environmentId: failing, input }, + ]); + expect(view).toMatchObject({ isPending: true, error: { environmentId: failing } }); + + view.retry(); + + expect(requests).toEqual([slow, failing, failing]); + } finally { + for (const unmount of unmounts) unmount(); + } + }); + it("removes the composite snapshots it replaced", () => { const storage = makeStorage(); storage.held.set("t3.pullRequests.list:env-local,env-remote", "{}"); diff --git a/apps/web/src/state/pullRequests.ts b/apps/web/src/state/pullRequests.ts index 06abb20717212..aef612bbb41ed 100644 --- a/apps/web/src/state/pullRequests.ts +++ b/apps/web/src/state/pullRequests.ts @@ -701,7 +701,16 @@ function createMergedEnvironmentQuery( appAtomRegistry.refresh(atom); } }; - return { ...view, refresh }; + // Retry reloads only failed environments, so a read still in flight elsewhere is not restarted. + const retry = () => { + for (const atom of new Set( + (JSON.parse(key) as ReadonlyArray>).map(atomFor), + )) { + const result = appAtomRegistry.get(atom); + if (result._tag === "Failure" && !result.waiting) appAtomRegistry.refresh(atom); + } + }; + return { ...view, refresh, retry }; }; } @@ -753,6 +762,7 @@ export interface MergedPullRequestListView { readonly isPending: boolean; readonly observations: ReadonlyArray; readonly refresh: (targets?: ReadonlyArray>) => void; + readonly retry: () => void; } // Merge inside each hook: the React Compiler memoizes it on `query.values` only there, and @@ -768,6 +778,7 @@ export function usePullRequestList( isPending: query.isPending, observations: query.observations, refresh: query.refresh, + retry: query.retry, }; } @@ -782,6 +793,7 @@ export function usePullRequestHostList( isPending: query.isPending, observations: query.observations, refresh: query.refresh, + retry: query.retry, }; }