The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): bound huge native review diff payloads (#19240)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Quy Ngoc Nguyen committed
Oct 20, 2026 at 11:10 UTC
6fc3c9ee1f7fb705fb290e2d6f0002cf4a74cb6e
2 files changed
+100
-2
apps/mobile/src/features/review/nativeReviewDiffAdapter.test.ts
+85
@@ -252,6 +252,91 @@ describe("getCachedNativeReviewDiffData", () => {
252
});
253
});
254
255
+describe("buildNativeReviewDiffData row bound", () => {
256
+ function singleFilePatch(path: string, lineCount: number) {
257
+ return [
258
+ `diff --git a/${path} b/${path}`,
259
+ `--- a/${path}`,
260
+ `+++ b/${path}`,
261
+ `@@ -0,0 +1,${lineCount} @@`,
262
+ ...Array.from({ length: lineCount }, (_, index) => `+const value${index} = ${index};`),
263
+ ].join("\n");
264
+ }
265
+
266
+ it("caps each huge file excerpt while preserving full counts and ordinary files", () => {
267
+ const data = buildNativeReviewDiffData(
268
+ buildReviewParsedDiff(
269
+ [singleFilePatch("huge.ts", 200_000), singleFilePatch("ordinary.ts", 1_000)].join("\n"),
270
+ "native-review-row-bound",
271
+ ),
272
+ );
273
+ const hugeHeader = data.rows.find((row) => row.kind === "file" && row.filePath === "huge.ts");
274
+ const ordinaryHeader = data.rows.find(
275
+ (row) => row.kind === "file" && row.filePath === "ordinary.ts",
276
+ );
277
+ expect(hugeHeader).toMatchObject({ additions: 200_000, deletions: 0 });
278
+ expect(ordinaryHeader).toMatchObject({ additions: 1_000, deletions: 0 });
279
+ expect(data).toMatchObject({ additions: 201_000, deletions: 0 });
280
+ const hugeRows = data.rows.filter((row) => row.fileId === hugeHeader?.fileId);
281
+ expect(hugeRows.filter((row) => row.kind === "line" || row.kind === "hunk")).toHaveLength(
282
+ 2_000,
283
+ );
284
+ expect(hugeRows.at(-2)).toMatchObject({ kind: "line", newLineNumber: 1_999 });
285
+ expect(hugeRows.at(-1)).toMatchObject({
286
+ kind: "notice",
287
+ text: "This diff is too large to show in full.",
288
+ });
289
+ const ordinaryRows = data.rows.filter((row) => row.fileId === ordinaryHeader?.fileId);
290
+ expect(ordinaryRows.filter((row) => row.kind === "line")).toHaveLength(1_000);
291
+ expect(ordinaryRows.at(-1)).toMatchObject({
292
+ kind: "line",
293
+ newLineNumber: 1_000,
294
+ content: "const value999 = 999;",
295
+ });
296
+ expect(ordinaryRows.some((row) => row.kind === "notice")).toBe(false);
297
+ });
298
+
299
+ it("omits comments beyond the excerpt and retains overlapping ranges at its boundary", () => {
300
+ const diff = buildReviewParsedDiff(singleFilePatch("example.ts", 3_000), "excerpt-comments");
301
+ const visible = { ...makeComment("Visible"), id: "visible", startIndex: 10, endIndex: 10 };
302
+ const overlapping = {
303
+ ...makeComment("Overlapping"),
304
+ id: "overlapping",
305
+ startIndex: 1_998,
306
+ endIndex: 2_001,
307
+ rangeLabel: "+1999 to +2002",
308
+ };
309
+ const omitted = {
310
+ ...makeComment("Outside excerpt"),
311
+ id: "omitted",
312
+ startIndex: 1_999,
313
+ endIndex: 1_999,
314
+ rangeLabel: "+2000",
315
+ };
316
+ const data = getCachedNativeReviewDiffData({
317
+ parsedDiff: diff,
318
+ comments: [visible, overlapping, omitted],
319
+ });
320
+
321
+ const visibleIndex = data.rows.findIndex((row) => row.id === visible.id);
322
+ expect(data.rows[visibleIndex - 1]).toMatchObject({ kind: "line", newLineNumber: 11 });
323
+ const overlappingIndex = data.rows.findIndex((row) => row.id === overlapping.id);
324
+ expect(data.rows[overlappingIndex - 1]).toMatchObject({ kind: "line", newLineNumber: 1_999 });
325
+ expect(data.rows[overlappingIndex]).toMatchObject({
326
+ commentRangeLabel: overlapping.rangeLabel,
327
+ commentText: overlapping.text,
328
+ });
329
+ expect(data.rows.filter((row) => row.kind === "comment").map((row) => row.id)).toEqual([
330
+ visible.id,
331
+ overlapping.id,
332
+ ]);
333
+ expect(data.rows[overlappingIndex + 1]).toMatchObject({ kind: "notice" });
334
+ expect(getCachedNativeReviewDiffData({ parsedDiff: diff }).rows).toEqual(
335
+ data.rows.filter((row) => row.kind !== "comment"),
336
+ );
337
+ });
338
+});
339
+
340
describe("createNativeReviewDiffTheme", () => {
341
it("serializes every native color as cross-platform opaque hex", () => {
342
for (const themeId of MOBILE_THEME_IDS) {
apps/mobile/src/features/review/nativeReviewDiffAdapter.ts
+15
-2
@@ -19,6 +19,9 @@ import type { ReviewInlineComment } from "./reviewCommentSelection";
19
20
const NATIVE_REVIEW_MAX_WORD_DIFF_RANGE_COUNT = 4;
21
const NATIVE_REVIEW_MAX_WORD_DIFF_COVERAGE = 0.45;
22
+// Bound the rows serialized to the native heap before mapping and word matching.
23
+const NATIVE_REVIEW_MAX_FILE_ROWS = 2_000;
24
+const TRUNCATED_FILE_NOTICE = "This diff is too large to show in full.";
25
const NATIVE_HEX_COLOR = /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})?$/i;
26
const NATIVE_RGBA_COLOR =
27
/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)$/;
@@ -131,6 +134,7 @@ interface PreparedNativeReviewFileRows {
134
readonly fileId: string;
135
readonly filePath: string;
136
readonly lineCount: number;
137
+ readonly truncated: boolean;
138
readonly rows: ReadonlyArray<NativeReviewDiffRow>;
139
readonly commentTargetsByRowId: ReadonlyMap<string, NativeReviewDiffCommentTarget>;
140
readonly rowIdByCommentLineId: ReadonlyMap<string, string>;
@@ -435,9 +439,13 @@ function prepareFileRows(file: ReviewRenderableFile): PreparedNativeReviewFileRo
439
},
440
];
441
438
- const lineRows = file.rows.filter((row): row is ReviewRenderableLineRow => row.kind === "line");
442
+ const sourceRows =
443
+ file.rows.length > NATIVE_REVIEW_MAX_FILE_ROWS
444
+ ? file.rows.slice(0, NATIVE_REVIEW_MAX_FILE_ROWS)
445
+ : file.rows;
446
+ const lineRows = sourceRows.filter((row): row is ReviewRenderableLineRow => row.kind === "line");
447
let lineIndex = 0;
440
- file.rows.forEach((row, rowIndex) => {
448
+ sourceRows.forEach((row, rowIndex) => {
449
if (row.kind === "hunk") {
450
rows.push({
451
kind: "hunk",
@@ -459,11 +467,15 @@ function prepareFileRows(file: ReviewRenderableFile): PreparedNativeReviewFileRo
467
lineIndex += 1;
468
});
469
470
+ if (sourceRows !== file.rows) {
471
+ rows.push(createNoticeRow(file.id, "truncated", TRUNCATED_FILE_NOTICE));
472
+ }
473
rows.push(...noticeRowsForFile(file));
474
const prepared: PreparedNativeReviewFileRows = {
475
fileId: file.id,
476
filePath: file.path,
477
lineCount: lineRows.length,
478
+ truncated: sourceRows !== file.rows,
479
// Comments must not split the source deletion/addition runs used for word matching.
480
rows: addNativeWordDiffRanges(rows),
481
commentTargetsByRowId,
@@ -489,6 +501,7 @@ function insertFileComments(
501
502
const commentsByEndIndex = new Map<number, ReviewInlineComment[]>();
503
for (const comment of comments) {
504
+ if (file.truncated && comment.startIndex >= file.lineCount) continue;
505
const endIndex = Math.min(comment.endIndex, file.lineCount - 1);
506
if (endIndex < 0) continue;
507
const existing = commentsByEndIndex.get(endIndex);