@devries-cameron20 / t3code-1 / commits / 44ebe67195
Fork 0

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

fix(web): preserve citations when adding review comments (#35300)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Jake Leventhal committed Nov 17, 2026 at 00:35 UTC 44ebe671951f1331db8e7bebbe8af30a2db665bd
6 files changed +65 -11
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+2 -1
@@ -97,6 +97,7 @@ import { cn } from "~/lib/utils";
97 import { createPullRequestDiffFileContentsLoader } from "~/lib/diffFileContents";
98 import {
99 buildDiffReviewComment,
100 + diffReviewSelectionId,
101 resolveDiffReviewAnchor,
102 type ReviewCommentContext,
103 } from "~/reviewCommentContext";
@@ -1076,7 +1077,7 @@ function PullRequestCodeTab({
1077 file === undefined
1078 ? null
1079 : buildDiffReviewComment({
1079 - id: `pull-request-selection:${anchor.fileKey}:${anchor.range.start}:${anchor.range.end}`,
1080 + id: `pull-request-selection:${diffReviewSelectionId(anchor.fileKey, anchor.range)}`,
1081 sectionId: `pull-request:${detail.number}`,
1082 sectionTitle: `PR #${detail.number} review`,
1083 filePath: anchor.path,
apps/web/src/components/pullRequest/guide/GuideExcerpt.tsx
+2 -1
@@ -18,6 +18,7 @@ import {
18 import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
19 import {
20 buildDiffReviewComment,
21 + diffReviewSelectionId,
22 resolveDiffReviewAnchor,
23 type ReviewCommentContext,
24 } from "~/reviewCommentContext";
@@ -237,7 +238,7 @@ function ExcerptDiff({
238 const askAgent = (request: string) => {
239 if (draft === null || onAskAgent === null) return;
240 const comment = buildDiffReviewComment({
240 - id: `pull-request-guide:${excerpt.path}:${draft.range.start}:${draft.range.end}`,
241 + id: `pull-request-guide:${diffReviewSelectionId(excerpt.path, draft.range)}`,
242 sectionId: `pull-request-guide:${excerpt.path}`,
243 sectionTitle: "Review guide",
244 filePath: excerpt.path,
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+39 -8
@@ -13,7 +13,14 @@ import {
13 type ThreadPullRequestLink,
14 } from "@t3tools/contracts";
15 import { describe, expect, it } from "vite-plus/test";
16 -import { reviewCommentContextLabel } from "~/lib/composerContextRecords";
16 +import {
17 + formatComposerContextReference,
18 + projectComposerContextForProvider,
19 +} from "@t3tools/shared/composerContextReferences";
20 +import {
21 + reviewCommentContextLabel,
22 + reviewCommentContextRecord,
23 +} from "~/lib/composerContextRecords";
24
25 import {
26 buildAddSelectionToAgentHandoff,
@@ -1027,35 +1034,59 @@ describe("asking about a change rather than working on it", () => {
1034 });
1035
1036 it("keeps both pull requests when two repositories share a number", () => {
1030 - const selection = (id: string) => ({
1037 + const selection = (id: string, line = 12) => ({
1038 id,
1039 sectionId: "pull-request:42",
1040 sectionTitle: "PR #42 review",
1041 filePath: "apps/web/src/page.tsx",
1035 - startIndex: 11,
1036 - endIndex: 17,
1037 - rangeLabel: "L12-L18",
1042 + startIndex: line - 1,
1043 + endIndex: line + 5,
1044 + rangeLabel: `L${line}-L${line + 6}`,
1045 text: "",
1046 diff: "+const answer = 42;",
1047 });
1048 const otherUrl = "https://github.com/acme/other/pull/42";
1049 const first = buildAddSelectionToAgentHandoff({
1050 ...base,
1044 - comment: selection("pull-request-selection:t3code:page.tsx:12:18"),
1051 + comment: selection("pull-request-selection:page.tsx:12:18"),
1052 request: "why?",
1053 });
1054 const second = buildAddSelectionToAgentHandoff({
1055 ...base,
1056 url: otherUrl,
1050 - comment: selection("pull-request-selection:other:page.tsx:12:18"),
1057 + comment: selection("pull-request-selection:page.tsx:12:18"),
1058 request: "and here?",
1059 });
1053 - const draft = appendHandoff(appendHandoff({ prompt: "", reviewComments: [] }, first), second);
1060 + const third = buildAddSelectionToAgentHandoff({
1061 + ...base,
1062 + comment: selection("pull-request-selection:page.tsx:20:26", 20),
1063 + request: "and this other range in the first pull request?",
1064 + });
1065 + const draft = appendHandoff(
1066 + appendHandoff(appendHandoff({ prompt: "", reviewComments: [] }, first), second),
1067 + third,
1068 + );
1069 expect(draft.reviewComments.map((comment) => comment.pullRequest?.url)).toEqual([
1070 base.url,
1071 undefined,
1072 otherUrl,
1073 undefined,
1074 + undefined,
1075 + ]);
1076 + expect(
1077 + draft.reviewComments
1078 + .filter((comment) => comment.diff !== "")
1079 + .map((comment) => {
1080 + const record = reviewCommentContextRecord(comment);
1081 + return projectComposerContextForProvider({
1082 + text: formatComposerContextReference(record),
1083 + records: [record],
1084 + });
1085 + }),
1086 + ).toEqual([
1087 + expect.stringContaining(base.url),
1088 + expect.stringContaining(otherUrl),
1089 + expect.stringContaining(base.url),
1090 ]);
1091 });
1092
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+9 -1
@@ -1342,7 +1342,15 @@ export function buildAddSelectionToAgentHandoff(input: {
1342 }): FixFindingsHandoff {
1343 return {
1344 prompt: bounded(input.request),
1345 - reviewComments: [pullRequestContextComment(input, []), { ...input.comment, text: "" }],
1345 + reviewComments: [
1346 + pullRequestContextComment(input, []),
1347 + {
1348 + ...input.comment,
1349 + id: `pull-request-selection:${input.url}:${input.comment.id}`,
1350 + sectionTitle: `${input.comment.sectionTitle} (${boundedField(input.url)})`,
1351 + text: "",
1352 + },
1353 + ],
1354 };
1355 }
1356
apps/web/src/reviewCommentContext.test.ts
+9
@@ -6,6 +6,7 @@ import {
6 buildDiffReviewComment,
7 buildFileReviewComment,
8 buildReviewCommentRenderablePatch,
9 + diffReviewSelectionId,
10 formatReviewCommentFence,
11 resolveDiffReviewAnchor,
12 resolveDiffReviewPosition,
@@ -74,6 +75,14 @@ describe("review comment context parsing", () => {
75 fenceLanguage: "diff",
76 }),
77 );
78 + const ids = (
79 + [
80 + { start: 2, end: 2, side: "deletions" },
81 + { start: 2, end: 2, side: "additions" },
82 + { start: 2, end: 2, side: "deletions", endSide: "additions" },
83 + ] as const
84 + ).map((range) => diffReviewSelectionId("src/app.ts", range));
85 + expect(new Set(ids).size).toBe(ids.length);
86 });
87
88 it("keeps a selection's trailing blank line and whitespace in the rendered excerpt", () => {
apps/web/src/reviewCommentContext.ts
+4
@@ -452,6 +452,10 @@ function formatDiffReviewRangeLabel(lines: ReadonlyArray<DiffReviewLine>): strin
452 : `${marker}${firstNumber} to ${marker}${lastNumber}`;
453 }
454
455 +export function diffReviewSelectionId(fileKey: string, range: SelectedLineRange): string {
456 + return `${fileKey}:${range.side ?? "additions"}:${range.start}:${range.endSide ?? range.side ?? "additions"}:${range.end}`;
457 +}
458 +
459 export function buildDiffReviewComment(input: {
460 id: string;
461 sectionId: string;