Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/src/components/pullRequest/PullRequestsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ export function PullRequestsPage() {
<PullRequestsUnavailableState
error={listError}
refreshing={listQuery.isPending}
onRetry={() => listQuery.refresh()}
onRetry={listQuery.retry}
/>
) : carriedToNothing ? (
<PullRequestListGhost rows={7} />
Expand Down Expand Up @@ -1313,7 +1313,7 @@ export function PullRequestsPage() {
{listError && shownCount > 0 ? (
<div className="flex items-center justify-between gap-3 rounded-lg border border-warning/30 bg-warning-surface px-3 py-2 text-xs">
<span>{gt("{error} Showing the last pull requests loaded.", { error: listError })}</span>
<Button size="xs" variant="outline" onClick={() => listQuery.refresh()}>
<Button size="xs" variant="outline" onClick={listQuery.retry}>
<T>Retry</T>
</Button>
</div>
Expand Down
47 changes: 39 additions & 8 deletions apps/web/src/state/pullRequests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>());
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<typeof import("@effect/atom-react")>()),
useAtomValue: (atom: Atom.Atom<unknown>) => registry.get(atom),
};
});
vi.mock("@effect/atom-react", async (importOriginal) => ({
...(await importOriginal<typeof import("@effect/atom-react")>()),
useAtomValue: (atom: Atom.Atom<unknown>) => registry.get(atom),
}));
vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: registry }));
vi.mock("@t3tools/client-runtime/state/pull-requests", async (importOriginal) => {
const actual =
await importOriginal<typeof import("@t3tools/client-runtime/state/pull-requests")>();
Expand Down Expand Up @@ -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<never, string>) =>
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", "{}");
Expand Down
14 changes: 13 additions & 1 deletion apps/web/src/state/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,16 @@ function createMergedEnvironmentQuery<Input, A>(
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<EnvironmentQueryTarget<Input>>).map(atomFor),
)) {
const result = appAtomRegistry.get(atom);
if (result._tag === "Failure" && !result.waiting) appAtomRegistry.refresh(atom);
}
};
return { ...view, refresh, retry };
};
}

Expand Down Expand Up @@ -753,6 +762,7 @@ export interface MergedPullRequestListView {
readonly isPending: boolean;
readonly observations: ReadonlyArray<readonly [EnvironmentId, PullRequestListResult, number]>;
readonly refresh: (targets?: ReadonlyArray<EnvironmentQueryTarget<PullRequestListInput>>) => void;
readonly retry: () => void;
}

// Merge inside each hook: the React Compiler memoizes it on `query.values` only there, and
Expand All @@ -768,6 +778,7 @@ export function usePullRequestList(
isPending: query.isPending,
observations: query.observations,
refresh: query.refresh,
retry: query.retry,
};
}

Expand All @@ -782,6 +793,7 @@ export function usePullRequestHostList(
isPending: query.isPending,
observations: query.observations,
refresh: query.refresh,
retry: query.retry,
};
}

Expand Down
Loading