@devries-cameron20 / t3code-1 / commits / 5432ce0df9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): preserve line counts for withheld pull request hunks (#18836)

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Alex Southwell committed Oct 19, 2026 at 06:26 UTC 5432ce0df966d0588265e57b17de2bc5d9d8fea8
2 files changed +79 -1
apps/mobile/src/features/pull-requests/pullRequestDiffPages.test.ts
+63
@@ -11,7 +11,70 @@ function diff(path: string): PullRequestDiffResult {
11 };
12 }
13
14 +function withheldDiff(): PullRequestDiffResult {
15 + return {
16 + patch: "diff --git a/large.ts b/large.ts\n--- a/large.ts\n+++ b/large.ts\n",
17 + truncated: true,
18 + nextCursor: null,
19 + omittedFileStats: [{ path: "large.ts", additions: 3000, deletions: 1800 }],
20 + };
21 +}
22 +
23 describe("paged mobile pull request diffs", () => {
24 + it("withheld PR hunks must retain provider line counts", () => {
25 + const result = withheldDiff();
26 + const cache = new WeakMap<PullRequestDiffResult, ReviewParsedDiff>();
27 + const pages = [{ cursor: null, result }];
28 + const parsed = combinePullRequestDiffPages(pages, cache, "pr");
29 + if (parsed.kind !== "files") throw new Error("Expected structured diff");
30 + expect(parsed.files[0]).toMatchObject({
31 + path: "large.ts",
32 + additions: 3000,
33 + deletions: 1800,
34 + rows: [],
35 + });
36 + expect(parsed.additions).toBe(3000);
37 + expect(parsed.deletions).toBe(1800);
38 + expect(parsed.notice).toBe(
39 + "Some file contents are unavailable. Open the pull request on its provider to see the full changes.",
40 + );
41 + const cached = combinePullRequestDiffPages(pages, cache, "pr");
42 + if (cached.kind !== "files") throw new Error("Expected structured diff");
43 + expect(cached.files[0]).toBe(parsed.files[0]);
44 + });
45 +
46 + it("combines normal and withheld pages and refreshes counts with unchanged patch text", () => {
47 + const first = { ...diff("first.ts"), nextCursor: "second" };
48 + const withheld = withheldDiff();
49 + const cache = new WeakMap<PullRequestDiffResult, ReviewParsedDiff>();
50 + const pages = retainPullRequestDiffPage(
51 + retainPullRequestDiffPage([], null, first),
52 + "second",
53 + withheld,
54 + );
55 + const before = combinePullRequestDiffPages(pages, cache, "pr");
56 + if (before.kind !== "files") throw new Error("Expected structured diff");
57 + expect(before.files.map((file) => [file.path, file.additions, file.deletions])).toEqual([
58 + ["first.ts", 1, 1],
59 + ["large.ts", 3000, 1800],
60 + ]);
61 + expect(before.additions).toBe(3001);
62 + expect(before.deletions).toBe(1801);
63 +
64 + const refreshed = retainPullRequestDiffPage(pages, "second", {
65 + ...withheld,
66 + omittedFileStats: [{ path: "large.ts", additions: 4000, deletions: 2000 }],
67 + });
68 + const after = combinePullRequestDiffPages(refreshed, cache, "pr");
69 + if (after.kind !== "files") throw new Error("Expected structured diff");
70 + expect(after.files[0]).toBe(before.files[0]);
71 + expect(after.files[1]?.id).toBe(before.files[1]?.id);
72 + expect(after.files[1]).toMatchObject({ additions: 4000, deletions: 2000, rows: [] });
73 + expect(after.additions).toBe(4001);
74 + expect(after.deletions).toBe(2001);
75 + expect(after.notice).toBe(before.notice);
76 + expect(before.additions).toBe(3001);
77 + });
78 it("retains file order and IDs when another page arrives", () => {
79 const first = { ...diff("first.ts"), nextCursor: "second" };
80 const pages = retainPullRequestDiffPage([], null, first);
apps/mobile/src/features/pull-requests/pullRequestDiffPages.ts
+16 -1
@@ -35,7 +35,22 @@ export function combinePullRequestDiffPages(
35 const parsed = pages.map((page) => {
36 const cached = cache.get(page.result);
37 if (cached) return cached;
38 - const value = buildReviewParsedDiff(page.result.patch, `${scope}:${page.cursor ?? "first"}`);
38 + let value = buildReviewParsedDiff(page.result.patch, `${scope}:${page.cursor ?? "first"}`);
39 + if (value.kind === "files" && page.result.omittedFileStats?.length) {
40 + const omittedFileStats = new Map(
41 + page.result.omittedFileStats.map((stat) => [stat.path, stat]),
42 + );
43 + const files = value.files.map((file) => {
44 + const stat = omittedFileStats.get(file.path);
45 + return stat ? { ...file, additions: stat.additions, deletions: stat.deletions } : file;
46 + });
47 + value = {
48 + ...value,
49 + files,
50 + additions: files.reduce((total, file) => total + file.additions, 0),
51 + deletions: files.reduce((total, file) => total + file.deletions, 0),
52 + };
53 + }
54 cache.set(page.result, value);
55 return value;
56 });