Skip to content

Commit 7cf4785

Browse files
Bil0000claude
andcommitted
fix(pr): list seeds keep newer previews, and equal updates pick the later read
A list read that started before a direct preview no longer replaces it. When two held summaries share updatedAt, mobile seeds from the later read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6fc1c8c commit 7cf4785

4 files changed

Lines changed: 43 additions & 16 deletions

File tree

‎apps/mobile/src/state/thread-pr-presentation.ts‎

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,42 @@ export function knownPullRequestSummary(
158158
): PullRequestSummary | undefined {
159159
const key = threadPullRequestKeyOf(pullRequest);
160160
let newest: PullRequestSummary | undefined;
161-
const consider = (summary: PullRequestSummary) => {
162-
if (newest === undefined || summary.updatedAt > newest.updatedAt) newest = summary;
161+
let newestReadAt: number | undefined;
162+
const consider = (summary: PullRequestSummary, readAt: number | undefined) => {
163+
const laterRead =
164+
summary.updatedAt === newest?.updatedAt &&
165+
readAt !== undefined &&
166+
newestReadAt !== undefined &&
167+
readAt > newestReadAt;
168+
if (newest === undefined || summary.updatedAt > newest.updatedAt || laterRead) {
169+
newest = summary;
170+
newestReadAt = readAt;
171+
}
163172
};
164173
for (const summary of summaries) {
165-
if (threadPullRequestKeyOf(legacyThreadPullRequestKey(summary)) === key) consider(summary);
174+
if (threadPullRequestKeyOf(legacyThreadPullRequestKey(summary)) === key) {
175+
consider(summary, summary.observedAt);
176+
}
166177
}
167178
for (const thread of threads) {
168179
for (const link of thread.pullRequests) {
169180
const snapshot = link.snapshot;
170181
if (snapshot?.updatedAt == null || threadPullRequestKeyOf(link) !== key) continue;
171-
consider({
172-
...snapshot,
173-
updatedAt: snapshot.updatedAt,
174-
provider: (
175-
sourceControlClients.findByChangeRequestUrl(link.url) ??
176-
sourceControlClients.get(undefined)
177-
).kind,
178-
projectId: thread.projectId,
179-
repository: link.repository,
180-
number: link.number,
181-
url: link.url,
182-
});
182+
consider(
183+
{
184+
...snapshot,
185+
updatedAt: snapshot.updatedAt,
186+
provider: (
187+
sourceControlClients.findByChangeRequestUrl(link.url) ??
188+
sourceControlClients.get(undefined)
189+
).kind,
190+
projectId: thread.projectId,
191+
repository: link.repository,
192+
number: link.number,
193+
url: link.url,
194+
},
195+
Date.parse(snapshot.syncedAt),
196+
);
183197
}
184198
}
185199
return newest;

‎apps/mobile/src/state/use-thread-pr.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ describe("knownPullRequestSummary", () => {
166166
[otherRepository, newer],
167167
)?.title,
168168
).toBe("Newer title");
169+
const sameUpdate = { ...newer, updatedAt: "2026-09-08T00:00:00.000Z", title: "Same update" };
170+
const seed = (observedAt: number) =>
171+
knownPullRequestSummary(
172+
{ host: "github.com", repository: "t3tools/t3code", number: 7 },
173+
threads,
174+
[{ ...sameUpdate, observedAt }],
175+
)?.title;
176+
expect(seed(Date.parse("2026-09-07T00:00:00.000Z"))).toBe("Change 7");
177+
expect(seed(Date.parse("2026-09-09T00:00:00.000Z"))).toBe("Same update");
169178
});
170179
});
171180

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ it.effect("shows a listed pull request's preview without asking the host again",
229229
yield* service.refreshAfterTurn(ref.projectId);
230230
assert.strictEqual((yield* service.preview(ref)).title, "Renamed");
231231
assert.strictEqual(previewReads, 1);
232+
yield* service.list({ state: "open", limit: 1 });
233+
assert.strictEqual((yield* service.preview(ref)).title, "Renamed");
232234
}),
233235
);
234236

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,9 @@ export const make = Effect.gen(function* () {
15601560
.slice(0, DETAIL_CACHE_CAPACITY / 2)
15611561
.map((entry) => [refCacheKey(entry), previewFields(entry)] as const)
15621562
.toReversed();
1563-
for (const [key, value] of seeds) yield* Cache.set(previewCache, key, value);
1563+
for (const [key, value] of seeds) {
1564+
if (!(yield* Cache.has(previewCache, key))) yield* Cache.set(previewCache, key, value);
1565+
}
15641566
}
15651567

15661568
return {

0 commit comments

Comments
 (0)