The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 15:45 UTC
fix(mobile): pull request rows refresh their diff stats after a new push (#25713)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 26, 2026 at 19:07 UTC
354f6c86ddb0a431351e59fa38a5d5d16b1bb81f
4 files changed
+128
-16
apps/mobile/src/features/pull-requests/pullRequestList.test.ts
+37
@@ -8,6 +8,7 @@ import {
8
import {
9
appendPullRequestListPage,
10
DEFAULT_PR_LIST_CONTROLS,
11
+ EMPTY_PULL_REQUEST_STATS_CACHE,
12
filterPullRequestList,
13
mergePullRequestListEntries,
14
mergeEnvironmentPullRequestPages,
@@ -21,6 +22,8 @@ import {
22
scopedPullRequestListKey,
23
shownPullRequestListPages,
24
pullRequestListRowsAreEqual,
25
+ withAnsweredPullRequestStats,
26
+ withListedPullRequests,
27
withShownPullRequestStats,
28
withoutScratchProjectScope,
29
} from "./pullRequestList";
@@ -435,3 +438,37 @@ describe("shown PR diff stats", () => {
438
expect(filled[1]).toBe(rows[1]);
439
});
440
});
441
+
442
+describe("cached PR diff stats", () => {
443
+ const stat = (number: number, additions: number) => ({
444
+ projectId: "project" as PullRequestListEntry["projectId"],
445
+ repository: "org/repo",
446
+ number,
447
+ additions,
448
+ deletions: 0,
449
+ });
450
+
451
+ it("drops a row's stat and refreshes its stats query when its updatedAt moves", () => {
452
+ const query = {
453
+ refs: [1, 2].map((number) => ({
454
+ projectId: stat(number, 0).projectId,
455
+ repository: "org/repo",
456
+ number,
457
+ })),
458
+ };
459
+ const listed = withListedPullRequests(EMPTY_PULL_REQUEST_STATS_CACHE, [entry(1), entry(2)]);
460
+ expect(listed.refresh).toEqual([]);
461
+ const answered = withAnsweredPullRequestStats(listed.cache, query, [stat(1, 5), stat(2, 7)]);
462
+ expect(withListedPullRequests(answered, [entry(1), entry(2)])).toEqual({
463
+ cache: answered,
464
+ refresh: [],
465
+ });
466
+
467
+ const pushed = withListedPullRequests(answered, [
468
+ entry(1, { updatedAt: "2026-10-20T00:00:00Z" }),
469
+ entry(2),
470
+ ]);
471
+ expect([...pushed.cache.stats.values()]).toEqual([stat(2, 7)]);
472
+ expect(pushed.refresh).toEqual([query]);
473
+ });
474
+});
apps/mobile/src/features/pull-requests/pullRequestList.ts
+66
@@ -7,6 +7,7 @@ import {
7
type PullRequestListEntry,
8
type PullRequestListInput,
9
type PullRequestListResult,
10
+ type PullRequestListStatsInput,
11
} from "@t3tools/contracts";
12
import type { PullRequestListControls } from "../../persistence/mobile-preferences";
13
@@ -50,6 +51,71 @@ export const pullRequestStatKey = (
51
row: Pick<PullRequestDiffStat, "projectId" | "repository" | "number">,
52
) => `${row.projectId}:${row.repository}:${row.number}`;
53
54
+/**
55
+ * Diff stats an environment has answered, the stats query that answered each, and each row's
56
+ * `updatedAt` as its list last answered it.
57
+ */
58
+export interface PullRequestStatsCache {
59
+ readonly stats: ReadonlyMap<string, PullRequestDiffStat>;
60
+ readonly answeredBy: ReadonlyMap<string, PullRequestListStatsInput>;
61
+ readonly updatedAt: ReadonlyMap<string, string>;
62
+}
63
+
64
+export const EMPTY_PULL_REQUEST_STATS_CACHE: PullRequestStatsCache = {
65
+ stats: new Map(),
66
+ answeredBy: new Map(),
67
+ updatedAt: new Map(),
68
+};
69
+
70
+/**
71
+ * Records the rows a list answered. Stats carry no head, so a row whose `updatedAt` moved (a push,
72
+ * among other changes) drops its cached stat, and the stats queries that answered it are returned
73
+ * to refresh: one can still be fresh and would otherwise answer the row's next read with the old
74
+ * counts.
75
+ */
76
+export function withListedPullRequests(
77
+ cache: PullRequestStatsCache,
78
+ entries: readonly Pick<
79
+ PullRequestListEntry,
80
+ "projectId" | "repository" | "number" | "updatedAt"
81
+ >[],
82
+): {
83
+ readonly cache: PullRequestStatsCache;
84
+ readonly refresh: readonly PullRequestListStatsInput[];
85
+} {
86
+ const moved = entries.filter(
87
+ (entry) => cache.updatedAt.get(pullRequestStatKey(entry)) !== entry.updatedAt,
88
+ );
89
+ if (!moved.length) return { cache, refresh: [] };
90
+ const stats = new Map(cache.stats);
91
+ const answeredBy = new Map(cache.answeredBy);
92
+ const updatedAt = new Map(cache.updatedAt);
93
+ const refresh = new Set<PullRequestListStatsInput>();
94
+ for (const entry of moved) {
95
+ const key = pullRequestStatKey(entry);
96
+ const query = answeredBy.get(key);
97
+ if (query) refresh.add(query);
98
+ stats.delete(key);
99
+ answeredBy.delete(key);
100
+ updatedAt.set(key, entry.updatedAt);
101
+ }
102
+ return { cache: { stats, answeredBy, updatedAt }, refresh: [...refresh] };
103
+}
104
+
105
+export function withAnsweredPullRequestStats(
106
+ cache: PullRequestStatsCache,
107
+ input: PullRequestListStatsInput,
108
+ answered: readonly PullRequestDiffStat[],
109
+): PullRequestStatsCache {
110
+ const stats = new Map(cache.stats);
111
+ const answeredBy = new Map(cache.answeredBy);
112
+ for (const row of answered) {
113
+ stats.set(pullRequestStatKey(row), row);
114
+ answeredBy.set(pullRequestStatKey(row), input);
115
+ }
116
+ return { ...cache, stats, answeredBy };
117
+}
118
+
119
/**
120
* Fills rows that have no diff stat yet from the stats answers on screen. Returns `entries`
121
* itself when no row changes, so the list keeps its identity across renders.
apps/mobile/src/features/pull-requests/usePullRequestList.ts
+1
-1
@@ -185,7 +185,7 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
185
pages: {
186
...pages,
187
entries: pages.entries.map((entry) => {
188
- const stat = stats.get(statKey(entry));
188
+ const stat = stats.stats.get(statKey(entry));
189
return stat
190
? { ...entry, additions: stat.additions, deletions: stat.deletions }
191
: entry;
apps/mobile/src/state/pull-requests.ts
+24
-15
@@ -2,15 +2,18 @@ import {
2
createPullRequestEnvironmentAtoms,
3
createPullRequestStackAtomFamily,
4
} from "@t3tools/client-runtime/state/pull-requests";
5
-import type { EnvironmentId, PullRequestDiffStat, PullRequestListInput } from "@t3tools/contracts";
5
+import type { EnvironmentId, PullRequestListInput } from "@t3tools/contracts";
6
import * as Effect from "effect/Effect";
7
import * as Option from "effect/Option";
8
import { AsyncResult, Atom } from "effect/reactivity";
9
import { connectionAtomRuntime } from "../connection/runtime";
10
import {
11
+ EMPTY_PULL_REQUEST_STATS_CACHE,
12
pullRequestListHead,
12
- pullRequestStatKey,
13
+ withAnsweredPullRequestStats,
14
+ withListedPullRequests,
15
type PullRequestListPages,
16
+ type PullRequestStatsCache,
17
} from "../features/pull-requests/pullRequestList";
18
19
export const pullRequestListPagesKey = (target: {
@@ -25,7 +28,9 @@ export const pullRequestListPagesFamily = Atom.family((_key: string) =>
28
29
/** Diff stats each environment has answered so far, so rows keep them when they scroll away. */
30
export const pullRequestListStatsFamily = Atom.family((_environmentId: string) =>
28
- Atom.make<ReadonlyMap<string, PullRequestDiffStat>>(new Map()).pipe(Atom.setIdleTTL(5 * 60_000)),
31
+ Atom.make<PullRequestStatsCache>(EMPTY_PULL_REQUEST_STATS_CACHE).pipe(
32
+ Atom.setIdleTTL(5 * 60_000),
33
+ ),
34
);
35
36
export const composerPullRequests = createPullRequestEnvironmentAtoms(connectionAtomRuntime, {
@@ -38,20 +43,24 @@ export const composerPullRequests = createPullRequestEnvironmentAtoms(connection
43
registry.refresh(composerPullRequests.filesViewed(target));
44
}),
45
list: (target, value, registry) =>
41
- target.input.cursors === undefined
42
- ? Effect.sync(() =>
43
- registry.update(pullRequestListPagesFamily(pullRequestListPagesKey(target)), (previous) =>
44
- pullRequestListHead(previous, value),
45
- ),
46
- )
47
- : Effect.void,
46
+ Effect.sync(() => {
47
+ const statsAtom = pullRequestListStatsFamily(target.environmentId);
48
+ const { cache, refresh } = withListedPullRequests(registry.get(statsAtom), value.entries);
49
+ registry.set(statsAtom, cache);
50
+ for (const input of refresh)
51
+ registry.refresh(
52
+ composerPullRequests.listStats({ environmentId: target.environmentId, input }),
53
+ );
54
+ if (target.input.cursors === undefined)
55
+ registry.update(pullRequestListPagesFamily(pullRequestListPagesKey(target)), (previous) =>
56
+ pullRequestListHead(previous, value),
57
+ );
58
+ }),
59
listStats: (target, value, registry) =>
60
Effect.sync(() =>
50
- registry.update(pullRequestListStatsFamily(target.environmentId), (previous) => {
51
- const next = new Map(previous);
52
- for (const row of value.stats) next.set(pullRequestStatKey(row), row);
53
- return next;
54
- }),
61
+ registry.update(pullRequestListStatsFamily(target.environmentId), (previous) =>
62
+ withAnsweredPullRequestStats(previous, target.input, value.stats),
63
+ ),
64
),
65
});
66
export const pullRequestStackAtom = createPullRequestStackAtomFamily(