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, }; }