Skip to content

Commit 08bb859

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
fix(web): a failed issue list refresh reads as stale and keeps its rows
## What Changed Rows from a failed refresh now read as stale: dimmed, under a caption, and still visible. | File | Change | | --- | --- | | `pullRequests.fork.ts` | merged query gains `stale` | | `githubIssues.ts` | list hook passes `stale` through | | `_chat.issues.tsx` | stale rows dim; caption without spinner | | `GitHubIssueGhosts.tsx` | the stale caption text | | `pullRequests.fork.test.tsx` | new: 5 cases for the fold | `stale` is set when an environment's latest read failed but its previous success still supplies rows. Only a read in flight sets `aria-busy`. ## Why A failed read carries its previous success, so the old rows stayed at full opacity with no caption and read as current. Closes #1447 ## Close conditions - [x] **Stale:** rows after a failed refresh look stale - [x] **Kept:** the old rows stay visible - [x] **Test:** refresh failure after success A per-repository `gh` error arrives inside a successful read, so this path covers an environment the refresh could not reach. ## Checks ```text vp test run <touched tests> → exit 0 (12 passed) typecheck apps/web → exit 0 vp run knip:check → exit 0 vp run fork:ci → exit 0 ``` ## Evidence Loaded the list, paused the dev server backend, then pressed Refresh. Before, with trunk list code: full-opacity rows, no caption. ![stale-before-crop.png](https://github.com/user-attachments/assets/a27728e5-5c10-45bf-8f98-6d4905c8d969) After: dimmed rows under "Couldn't refresh · showing last results". ![stale-after-crop.png](https://github.com/user-attachments/assets/234c1eae-1dcf-4dca-9020-9cc78155e78a) ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [x] I included before/after screenshots for any UI changes - [x] I included a video for animation/interaction changes No motion changed. Pi peer worker, hosted by Opus 5.5 via Claude Code in T3 Code. ## Fork trailers Squashes: - d954b80 fix(web): a failed issue list refresh reads as stale, not current (#1457) (#1457) - 1b7c519 fix(web): an issue refresh that failed for every project keeps its rows (#1462) (#1462) Fork-Domain: github-issues Fork-Tier: bugfix Fork-Upstreamable: no
1 parent a743556 commit 08bb859

6 files changed

Lines changed: 348 additions & 23 deletions

File tree

‎apps/web/src/components/githubIssue/GitHubIssueGhosts.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export function searchingCaption(query?: string): string {
1212
: "Reading issues from GitHub";
1313
}
1414

15+
/** Names the rows a failed refresh left behind: readable, but not what GitHub says right now. */
16+
export const staleRefreshCaption = "Couldn't refresh · showing last results";
17+
1518
/** The pull request list's ghost, named for what is actually on its way. */
1619
export function GitHubIssueListGhosts({ query }: { readonly query?: string }) {
1720
return <PullRequestListGhost rows={7} caption={searchingCaption(query)} />;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2+
import type {
3+
EnvironmentGitHubIssueListEntry,
4+
MergedGitHubIssueList,
5+
} from "@t3tools/client-runtime/state/github-issues";
6+
import { describe, expect, it } from "vite-plus/test";
7+
8+
import {
9+
gitHubIssueListReadFailed,
10+
holdGitHubIssueList,
11+
keepGitHubIssueListRows,
12+
} from "./githubIssueListKeep.logic";
13+
14+
function entry(number: number, title: string): EnvironmentGitHubIssueListEntry {
15+
return {
16+
environmentId: "env",
17+
projectId: "project",
18+
projectTitle: "Project",
19+
repository: "acme/app",
20+
number,
21+
title,
22+
url: `https://github.com/acme/app/issues/${number}`,
23+
author: { login: "octo" },
24+
assignees: [],
25+
labels: [],
26+
state: "open",
27+
createdAt: "2026-01-01T00:00:00.000Z",
28+
updatedAt: "2026-01-01T00:00:00.000Z",
29+
} as unknown as EnvironmentGitHubIssueListEntry;
30+
}
31+
32+
const goodList: MergedGitHubIssueList = {
33+
entries: [entry(1, "Fork fold absorbs repairs"), entry(2, "Sync blocked on nightly")],
34+
errors: [],
35+
environmentErrors: [],
36+
truncated: true,
37+
};
38+
39+
const allFailed: MergedGitHubIssueList = {
40+
entries: [],
41+
errors: [
42+
{
43+
environmentId: EnvironmentId.make("env"),
44+
projectId: ProjectId.make("project"),
45+
projectTitle: "Project",
46+
message: "acme/app could not be read: gh: auth failed",
47+
},
48+
],
49+
environmentErrors: [],
50+
truncated: false,
51+
};
52+
53+
describe("gitHubIssueListReadFailed", () => {
54+
it("reads a no-rows answer that carries project errors as a failure", () => {
55+
expect(gitHubIssueListReadFailed(allFailed)).toBe(true);
56+
});
57+
58+
it("leaves a good list alone", () => {
59+
expect(gitHubIssueListReadFailed(goodList)).toBe(false);
60+
});
61+
62+
it("leaves an environment-level failure alone, which the failed-read path already keeps", () => {
63+
expect(
64+
gitHubIssueListReadFailed({
65+
...goodList,
66+
entries: [],
67+
environmentErrors: [
68+
{ environmentId: EnvironmentId.make("env"), message: "The environment did not answer." },
69+
],
70+
}),
71+
).toBe(false);
72+
});
73+
});
74+
75+
describe("keepGitHubIssueListRows", () => {
76+
it("keeps the held rows under the failed answer's current errors", () => {
77+
const kept = keepGitHubIssueListRows(allFailed, goodList);
78+
expect(kept?.entries.map((issue) => issue.number)).toEqual([1, 2]);
79+
expect(kept?.errors).toEqual(allFailed.errors);
80+
expect(kept?.environmentErrors).toEqual([]);
81+
});
82+
83+
it("keeps the truncation the held rows were read with", () => {
84+
expect(keepGitHubIssueListRows(allFailed, goodList)?.truncated).toBe(true);
85+
expect(keepGitHubIssueListRows(allFailed, { ...goodList, truncated: false })?.truncated).toBe(
86+
false,
87+
);
88+
});
89+
90+
it("keeps nothing before any rows were read, leaving the failure as the answer", () => {
91+
expect(keepGitHubIssueListRows(allFailed, null)).toBeNull();
92+
expect(keepGitHubIssueListRows(allFailed, { ...goodList, entries: [] })).toBeNull();
93+
});
94+
});
95+
96+
describe("holdGitHubIssueList", () => {
97+
const scope = `[{"environmentId":"env","input":{"projectId":"p"}}]`;
98+
99+
it("keeps the held answer when the read failed for every project in a held scope", () => {
100+
const store = new Map([[scope, goodList]]);
101+
holdGitHubIssueList(store, allFailed, scope);
102+
expect(store.get(scope)).toBe(goodList);
103+
expect(store.size).toBe(1);
104+
});
105+
106+
it("stores a read that answered, and a failure before anything is held", () => {
107+
const store = new Map<string, MergedGitHubIssueList>();
108+
holdGitHubIssueList(store, goodList, scope);
109+
expect(store.get(scope)).toBe(goodList);
110+
const empty = new Map<string, MergedGitHubIssueList>();
111+
holdGitHubIssueList(empty, allFailed, scope);
112+
expect(empty.get(scope)).toBe(allFailed);
113+
});
114+
115+
it("stores a failure for a scope nothing is held for, leaving other scopes alone", () => {
116+
const store = new Map([["other", goodList]]);
117+
holdGitHubIssueList(store, allFailed, scope);
118+
expect(store.get(scope)).toBe(allFailed);
119+
expect(store.get("other")).toBe(goodList);
120+
});
121+
122+
it("writes nothing when the answer is the one already held, so a re-render stays idle", () => {
123+
const store = new Map<string, MergedGitHubIssueList>([[scope, allFailed]]);
124+
holdGitHubIssueList(store, allFailed, scope);
125+
expect(store.get(scope)).toBe(allFailed);
126+
});
127+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { MergedGitHubIssueList } from "@t3tools/client-runtime/state/github-issues";
2+
3+
/**
4+
* True when a list read no rows at all but carries project errors: every read behind it failed, so
5+
* it is a failure shape, not an answer — and never a reason to drop the rows already shown.
6+
*/
7+
export function gitHubIssueListReadFailed(list: MergedGitHubIssueList): boolean {
8+
return list.entries.length === 0 && list.errors.length > 0;
9+
}
10+
11+
/**
12+
* Records a landed answer for its scope, keeping the last good one: a read that failed for every
13+
* project never replaces what the scope holds — its rows must outlive the failure. A scope with
14+
* nothing held stores even a failed read, so the fold below can tell "failure" from "no read yet".
15+
* Writes only on change, so a render-phase call is idempotent.
16+
*/
17+
export function holdGitHubIssueList(
18+
store: Map<string, MergedGitHubIssueList>,
19+
answered: MergedGitHubIssueList,
20+
scope: string,
21+
): void {
22+
if (gitHubIssueListReadFailed(answered) && store.has(scope)) return;
23+
if (store.get(scope) !== answered) store.set(scope, answered);
24+
}
25+
26+
/**
27+
* The list a failed refresh shows: the last good rows under the current errors, so the failure
28+
* names itself in the notices while the rows stay readable. Null when no rows are held — then the
29+
* failure is the answer, and the empty state may say so.
30+
*/
31+
export function keepGitHubIssueListRows(
32+
answered: MergedGitHubIssueList,
33+
held: MergedGitHubIssueList | null,
34+
): MergedGitHubIssueList | null {
35+
if (held === null || held.entries.length === 0) return null;
36+
return {
37+
...answered,
38+
entries: held.entries,
39+
truncated: answered.truncated || held.truncated,
40+
};
41+
}

‎apps/web/src/state/githubIssues.ts‎

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import type {
88
GitHubIssueListInput,
99
GitHubIssueListResult,
1010
} from "@t3tools/contracts";
11-
import { useMemo, useState } from "react";
1211

1312
import {
1413
carryGitHubIssueList,
1514
gitHubIssueListScope,
1615
} from "../components/githubIssue/githubIssueListCarry.logic";
16+
import {
17+
gitHubIssueListReadFailed,
18+
holdGitHubIssueList,
19+
keepGitHubIssueListRows,
20+
} from "../components/githubIssue/githubIssueListKeep.logic";
1721
import { connectionAtomRuntime } from "../connection/runtime";
1822
import type { EnvironmentQueryTarget } from "./pullRequests";
1923
import { createMergedEnvironmentQueryFork } from "./pullRequests.fork";
@@ -35,6 +39,13 @@ const useGitHubIssueListsQuery = createMergedEnvironmentQueryFork<
3539
GitHubIssueListResult
3640
>("web-github-issues:list", githubIssueEnvironment.list);
3741

42+
/**
43+
* The last answer per scope, kept outside the component so it survives a scope switch and a
44+
* remount — the rows an all-failing refresh keeps come from here. Scopes are few: one per
45+
* environment and project the page asks about, so the store needs no eviction.
46+
*/
47+
const heldLists = new Map<string, MergedGitHubIssueList>();
48+
3849
/**
3950
* The merged list for these targets. A new state or search is a new query that starts empty, so
4051
* while it travels the last answer for the same projects stands in, narrowed to what the new
@@ -43,34 +54,38 @@ const useGitHubIssueListsQuery = createMergedEnvironmentQueryFork<
4354
export function useGitHubIssueList(targets: ReadonlyArray<GitHubIssueQueryTarget>): {
4455
readonly data: MergedGitHubIssueList | null;
4556
readonly carried: boolean;
57+
/** Rows on screen are not current: an environment's read failed, or every project's read did. */
58+
readonly stale: boolean;
4659
readonly isPending: boolean;
4760
readonly refresh: () => void;
4861
} {
4962
const query = useGitHubIssueListsQuery(targets);
50-
const answered = useMemo(
51-
() =>
52-
query.values.length === 0 && query.errors.length === 0
53-
? null
54-
: mergeGitHubIssueLists(query.values, query.errors),
55-
[query.errors, query.values],
56-
);
63+
const answered =
64+
query.values.length === 0 && query.errors.length === 0
65+
? null
66+
: mergeGitHubIssueLists(query.values, query.errors);
5767
const scope = gitHubIssueListScope(targets);
58-
const [held, setHeld] = useState<{ scope: string; list: MergedGitHubIssueList } | null>(null);
59-
if (answered !== null && (held?.list !== answered || held.scope !== scope)) {
60-
setHeld({ scope, list: answered });
61-
}
68+
// A render-phase write: idempotent by answer reference, so it can never loop the render.
69+
if (answered !== null) holdGitHubIssueList(heldLists, answered, scope);
70+
const held = heldLists.get(scope) ?? null;
6271
const input = targets[0]?.input;
63-
const carried = useMemo(
64-
() =>
65-
answered === null && query.isPending && input && held?.scope === scope
66-
? carryGitHubIssueList(held.list, input)
67-
: null,
68-
[answered, held, input, query.isPending, scope],
69-
);
72+
const carried =
73+
answered === null && query.isPending && input && held
74+
? carryGitHubIssueList(held, input)
75+
: null;
76+
// Rows a read that failed for every project keeps: the last good ones for this scope, stale the
77+
// way a failed refresh reads, while the current errors still ride the list for the notices.
78+
const kept =
79+
answered !== null && gitHubIssueListReadFailed(answered)
80+
? keepGitHubIssueListRows(answered, held)
81+
: null;
7082
return {
71-
data: answered ?? carried,
83+
data: kept ?? answered ?? carried,
7284
carried: carried !== null,
85+
stale: query.stale || kept !== null,
7386
isPending: query.isPending,
74-
refresh: query.refresh,
87+
// Wrapped: the fork's refresh takes an override target list, and an onClick that forwards a
88+
// click event as that argument would throw instead of refetching.
89+
refresh: () => query.refresh(),
7590
};
7691
}

0 commit comments

Comments
 (0)