Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PullRequestCodeTab.tsx

1,235 lines51.1 KB

1import type { CodeViewItem, DiffLineAnnotation, SelectedLineRange } from "@pierre/diffs";
2import type { CodeViewDiffItem } from "@pierre/diffs/react";
3import type {
4 EnvironmentId,
5 PullRequestDetailView,
6 PullRequestDiffSide,
7 PullRequestRef,
8 PullRequestReviewThread,
9} from "@t3tools/contracts";
10import {
11 ChevronDownIcon,
12 ChevronRightIcon,
13 ChevronsDownUpIcon,
14 ChevronsUpDownIcon,
15 Columns2Icon,
16 MessageSquareIcon,
17 MessageSquareOffIcon,
18 Rows3Icon,
19 SparklesIcon,
20 TextWrapIcon,
21 TriangleAlertIcon,
22 XIcon,
23} from "lucide-react";
24import { useAtomRefresh } from "@effect/atom-react";
25import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
26​
27import { useClientSettings } from "~/hooks/useSettings";
28import { useTheme } from "~/hooks/useTheme";
29import { areAllDiffFilesCollapsed } from "~/lib/diffCollapse";
30import { pullRequestFindingKey, type PullRequestFinding } from "./pullRequestDetail.logic";
31import {
32 buildFileDiffRenderKey,
33 fnv1a32,
34 getDiffLineStat,
35 getRenderablePatch,
36 resolveDiffThemeName,
37 resolveFileDiffPath,
38 resolveFileDiffPreviousPath,
39 type RenderablePatch,
40} from "~/lib/diffRendering";
41import { cn } from "~/lib/utils";
42import { createPullRequestDiffFileContentsLoader } from "~/lib/diffFileContents";
43import { buildDiffReviewComment, type ReviewCommentContext } from "~/reviewCommentContext";
44import { pullRequestEnvironment } from "~/state/pullRequests";
45import { useEnvironmentQuery } from "~/state/query";
46import { useAtomCommand } from "~/state/use-atom-command";
47​
48import { DiffPanelLoadingState } from "../DiffPanelShell";
49import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider";
50import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation";
51import { StyledDiffCodeView } from "../diffs/StyledDiffCodeView";
52import { Button } from "../ui/button";
53import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
54import {
55 DropdownMenu,
56 DropdownMenuContent,
57 DropdownMenuItem,
58 DropdownMenuTrigger,
59} from "../ui/menu";
60import { toastManager } from "../ui/toast";
61import { Toggle, ToggleGroup } from "../ui/toggle-group";
62import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
63import { PendingReviewCommentCard, ReviewThreadCard } from "./PullRequestReviewAnnotation";
64import { PullRequestReviewBar } from "./PullRequestReviewBar";
65import {
66 isFileDiffCollapsed,
67 isLineInFileDiff,
68 type DiffFoldOverride,
69} from "./pullRequestDiff.logic";
70import { PullRequestDiffStat, PullRequestMetaLine } from "./pullRequestPresentation";
71import {
72 nextPendingReviewCommentId,
73 pullRequestReviewKey,
74 usePendingReviewComments,
75 usePullRequestReviewStore,
76 type PendingReviewComment,
77} from "./pullRequestReviewStore";
78​
79/** Everything pinned to one line of one file: what is already there, and what is being added. */
80interface ReviewAnnotationGroup {
81 readonly threads: ReadonlyArray<PullRequestReviewThread>;
82 readonly pending: ReadonlyArray<PendingReviewComment>;
83 readonly draft: boolean;
85​
86type ReviewAnnotation = DiffLineAnnotation<ReviewAnnotationGroup>;
87​
88/** Commits per press of "Show more" in the scope menu. */
89const COMMIT_PAGE_SIZE = 10;
90​
91/** One answer from the host: a whole number of files, and where the next one carries on. */
92interface DiffSlice {
93 /** What was asked for, null being the first slice. Identifies the slice among the loaded ones. */
94 readonly cursor: string | null;
95 readonly patch: string;
96 readonly truncated: boolean;
97 readonly nextCursor: string | null;
99​
100/** Nothing loaded yet, as one identity, so the memos below do not see a new array every render. */
101const NO_SLICES: ReadonlyArray<DiffSlice> = [];
102​
103/** A group while it is still gathering what belongs on its line. */
104interface MutableAnnotationGroup {
105 readonly side: PullRequestDiffSide;
106 readonly line: number;
107 readonly threads: PullRequestReviewThread[];
108 readonly pending: PendingReviewComment[];
109 draft: boolean;
111​
112interface DraftAnchor {
113 readonly fileKey: string;
114 readonly path: string;
115 /** What the file was called before the change, for the hosts that resolve a position by both. */
116 readonly oldPath: string | null;
117 readonly line: number;
118 readonly side: PullRequestDiffSide;
119 /** The whole selection, which the comment collapses to one line but a question keeps. */
120 readonly range: SelectedLineRange;
122​
123/** A range of the diff, and whatever the reader wants to know about it. */
124export interface PullRequestAskSelectionInput {
125 /** The marked lines, already in the shape the composer draws and the agent reads. */
126 readonly comment: ReviewCommentContext;
127 /** Empty where the reader pressed Ask without typing: the lines are the question. */
128 readonly question: string;
130​
131/** The contract's sides named the way the diff viewer names them, and back again. */
132function toViewerSide(side: PullRequestDiffSide) {
133 return side === "left" ? ("deletions" as const) : ("additions" as const);
135​
136function fromViewerSide(side: string | undefined): PullRequestDiffSide {
137 return side === "deletions" ? "left" : "right";
139​
140/**
141 * Whether the viewer draws this line at all. A line counts the new file on the right and the old
142 * one on the left, and each hunk covers one run of each; a line outside every run — a
143 * conversation the host could not mark outdated, or one under a hunk it withheld — has no row to
144 * be pinned to, however much its file looks like a match.
145 */
146/**
147 * The pull request's patch, with the review written against it. Conversations already on the
148 * host sit under the line they were written on, and a new comment joins the review being
149 * drafted rather than being posted as it is typed.
150 */
151export function PullRequestCodeTab({
152 environmentId,
153 reference,
154 detail,
155 selectedCommitOid,
156 onSelectedCommitChange,
157 pendingFinding,
158 onFixFinding,
159 onAskAboutSelection,
160 onRefresh,
161 refreshToken = 0,
162}: {
163 environmentId: EnvironmentId;
164 reference: PullRequestRef;
165 detail: PullRequestDetailView;
166 /** Commit whose diff is open. Null keeps the whole pull-request diff selected. */
167 selectedCommitOid: string | null;
168 onSelectedCommitChange: (oid: string | null) => void;
169 /** The hand-off currently preparing, if any, so only the finding it belongs to says so. */
170 pendingFinding?: string | null;
171 onFixFinding?: (finding: PullRequestFinding) => void;
172 /** Absent where a selection has no agent to go to, which takes the Ask button off the box. */
173 onAskAboutSelection?: (input: PullRequestAskSelectionInput) => void;
174 onRefresh: () => void;
175 /** Bumped by the panel's refresh button: drop the accumulated pages and re-read the diff. */
176 refreshToken?: number;
177}) {
178 const { resolvedTheme } = useTheme();
179 const settings = useClientSettings();
180 const [toggledFiles, setToggledFiles] = useState<ReadonlySet<string>>(() => new Set());
181 // A change of any size can carry hundreds of commits, and a menu that long is a scroll rather
182 // than a choice. The rest arrive ten at a time, on request.
183 const [visibleCommitCount, setVisibleCommitCount] = useState(COMMIT_PAGE_SIZE);
184 /** Set once the reader has asked for every file at once, until they pick a file apart again. */
185 const [foldOverride, setFoldOverride] = useState<DiffFoldOverride>(null);
186 const [diffRenderMode, setDiffRenderMode] = useState<"stacked" | "split">("stacked");
187 const [wordWrap, setWordWrap] = useState(settings.wordWrap);
188 const [selectedLines, setSelectedLines] = useState<{
189 id: string;
190 range: SelectedLineRange;
191 } | null>(null);
192 const [draft, setDraft] = useState<DraftAnchor | null>(null);
193 const [threadPending, setThreadPending] = useState(false);
194 const [orphansOpen, setOrphansOpen] = useState(false);
195 // Closed by default so the review form does not permanently eat vertical space below the
196 // diff; opened on demand as a floating overlay instead.
197 const [reviewOpen, setReviewOpen] = useState(false);
198 // Which pull request the slices belong to travels with them, so a render taken before the
199 // reset below cannot read the previous one's slices — or send its cursor to the host.
200 const [sliceState, setSliceState] = useState<{
201 readonly key: string;
202 readonly cursor: string | null;
203 readonly slices: ReadonlyArray<DiffSlice>;
204 }>({ key: "", cursor: null, slices: NO_SLICES });
205 const parseCache = useRef(new Map<string, RenderablePatch>());
206​
207 const referenceKey = pullRequestReviewKey(reference);
208 const commit = selectedCommitOid;
209 // One commit's own changes and the whole change are two different diffs, paged separately, so
210 // everything below is keyed by both.
211 const scopeKey = commit === null ? referenceKey : `${referenceKey}@${commit}`;
212 // The panel keeps this mounted across pull requests, so an open composer would otherwise
213 // survive the switch and attach its comment to whichever one is on screen when it is sent.
214 useEffect(() => {
215 setDraft(null);
216 setSelectedLines(null);
217 setToggledFiles(new Set());
218 setFoldOverride(null);
219 setVisibleCommitCount(COMMIT_PAGE_SIZE);
220 setOrphansOpen(false);
221 setSliceState({ key: scopeKey, cursor: null, slices: NO_SLICES });
222 parseCache.current.clear();
223 }, [scopeKey]);
224​
225 const loadedSlices = sliceState.key === scopeKey ? sliceState.slices : NO_SLICES;
226 const cursor = sliceState.key === scopeKey ? sliceState.cursor : null;
227 const diffQuery = useEnvironmentQuery(
228 pullRequestEnvironment.diff({
229 environmentId,
230 input: {
231 ...reference,
232 ...(cursor === null ? {} : { cursor }),
233 ...(commit === null ? {} : { commit }),
234 },
235 }),
236 );
237 // Each answer is kept as its own slice. Concatenating the patches and re-parsing the growing
238 // text would cost more with every slice, which is the wall the slicing exists to remove.
239 useEffect(() => {
240 const data = diffQuery.data;
241 if (data === null) return;
242 setSliceState((previous) => {
243 const slices = previous.key === scopeKey ? previous.slices : NO_SLICES;
244 const next = {
245 cursor,
246 patch: data.patch,
247 truncated: data.truncated,
248 nextCursor: data.nextCursor,
249 };
250 const index = slices.findIndex((slice) => slice.cursor === cursor);
251 if (index === -1) {
252 return { key: scopeKey, cursor, slices: [...slices, next] };
253 }
254 const existing = slices[index];
255 if (
256 existing !== undefined &&
257 existing.patch === next.patch &&
258 existing.truncated === next.truncated &&
259 existing.nextCursor === next.nextCursor
260 ) {
261 return previous;
262 }
263 // A page that came back different means the diff moved under the review. The slices
264 // after it go with the replacement: their cursors were positions in the old diff.
265 return { key: scopeKey, cursor, slices: [...slices.slice(0, index), next] };
266 });
267 }, [cursor, diffQuery.data, scopeKey]);
268 // The refresh button rereads from the first page rather than the page the reader is on:
269 // pages are positions in one snapshot of the diff, and a fresh snapshot starts over.
270 const refreshFirstDiffPage = useAtomRefresh(
271 pullRequestEnvironment.diff({
272 environmentId,
273 input: { ...reference, ...(commit === null ? {} : { commit }) },
274 }),
275 );
276 const appliedRefreshToken = useRef(refreshToken);
277 useEffect(() => {
278 if (appliedRefreshToken.current === refreshToken) return;
279 appliedRefreshToken.current = refreshToken;
280 setSliceState({ key: scopeKey, cursor: null, slices: NO_SLICES });
281 refreshFirstDiffPage();
282 }, [refreshToken, scopeKey, refreshFirstDiffPage]);
283 const reviewKey = referenceKey;
284 const pendingComments = usePendingReviewComments(reference);
285 const addComment = usePullRequestReviewStore((store) => store.addComment);
286 const removeComment = usePullRequestReviewStore((store) => store.removeComment);
287 const replyToThread = useAtomCommand(pullRequestEnvironment.replyToThread, {
288 reportFailure: false,
289 });
290 const setThreadResolution = useAtomCommand(pullRequestEnvironment.setThreadResolution, {
291 reportFailure: false,
292 });
293 const getDiffFileContents = useAtomCommand(pullRequestEnvironment.diffFileContents);
294 const loadDiffFiles = useMemo(
295 () =>
296 createPullRequestDiffFileContentsLoader(getDiffFileContents, {
297 environmentId,
298 reference,
299 commit,
300 cacheKey: `pull-request:${referenceKey}:${detail.updatedAt}:${commit ?? "all"}`,
301 }),
302 [commit, detail.updatedAt, environmentId, getDiffFileContents, reference, referenceKey],
303 );
304​
305 // What is offered is the intersection of two different questions: what this host can do at
306 // all, and what this account may do on this repository. Either one saying no means a control
307 // that would only ever end in a refusal.
308 const review = useMemo(() => {
309 const hostReview = detail.capabilities.review;
310 const viewer = detail.viewerPermissions;
311 return {
312 inlineComment: hostReview.inlineComment && viewer.comment,
313 reply: hostReview.reply && viewer.comment,
314 resolve: hostReview.resolve && viewer.resolve,
315 verdicts: hostReview.verdicts.filter((verdict) => viewer.verdicts.includes(verdict)),
316 };
317 }, [detail.capabilities.review, detail.viewerPermissions]);
318 // A comment is posted against the pull request's head diff, so a line number taken from one
319 // commit's own diff would land somewhere else entirely. Commenting waits for the whole change.
320 const canCommentOnLines = review.inlineComment && commit === null;
321 // Every slice is parsed on its own and the result held, so a slice arriving costs one parse
322 // rather than one per slice already on screen. Its cache key carries the theme, which is what
323 // the tokenizer caches against, so a theme change is still a fresh parse.
324 const parsedSlices = useMemo(
325 () =>
326 loadedSlices.map((slice) => {
327 // The patch's own hash is part of the key: a refreshed page reuses its cursor, and a
328 // key of position alone would keep handing back the parse of the patch it replaced.
329 const cacheKey = `pull-request:${scopeKey}:${resolvedTheme}:${slice.cursor ?? "first"}:${fnv1a32(slice.patch)}`;
330 const cached = parseCache.current.get(cacheKey);
331 if (cached) return cached;
332 const parsed = getRenderablePatch(slice.patch, cacheKey, {
333 compactPartialHunkOffsets: true,
334 });
335 if (parsed) parseCache.current.set(cacheKey, parsed);
336 return parsed;
337 }),
338 [loadedSlices, resolvedTheme, scopeKey],
339 );
340 // Sorted within a slice rather than across them: sorting the accumulated set would let a late
341 // slice push a file the reader is part way through further down the page.
342 const files = useMemo(
343 () =>
344 parsedSlices.flatMap((parsed) =>
345 parsed?.kind === "files"
346 ? parsed.files.toSorted((left, right) =>
347 resolveFileDiffPath(left).localeCompare(resolveFileDiffPath(right)),
348 )
349 : [],
350 ),
351 [parsedSlices],
352 );
353 const nextCursor = loadedSlices.at(-1)?.nextCursor ?? null;
354 // What a slice withheld: the host declining to inline part of it, or a patch the viewer could
355 // not structure and so dropped. Neither says anything about there being more to fetch.
356 const withheldContent =
357 loadedSlices.some((slice) => slice.truncated) ||
358 parsedSlices.some((parsed) => parsed?.kind === "raw");
359​
360 // Placing a conversation takes more than its file being in the diff: its line has to fall
361 // inside a hunk that was rendered. One that does not is drawn nowhere, so it belongs in the
362 // off-diff list rather than disappearing between the two.
363 const placedThreadIds = useMemo(() => {
364 const placed = new Set<string>();
365 // A commit's diff counts lines within that commit; a review comment is anchored to the
366 // pull request's head diff. Pinning one onto the other would put the remark against
367 // whichever code happens to hold that line number in this commit, so while a commit is on
368 // screen every conversation is listed rather than placed.
369 if (commit !== null) return placed;
370 for (const file of files) {
371 const path = resolveFileDiffPath(file);
372 for (const thread of detail.reviewThreads) {
373 if (
374 thread.path === path &&
375 thread.line !== null &&
376 isLineInFileDiff(file, thread.side, thread.line)
377 ) {
378 placed.add(thread.id);
379 }
380 }
381 }
382 return placed;
383 }, [commit, detail.reviewThreads, files]);
384​
385 const items = useMemo<CodeViewDiffItem<ReviewAnnotationGroup>[]>(
386 () =>
387 files.map((fileDiff) => {
388 const fileKey = buildFileDiffRenderKey(fileDiff);
389 const path = resolveFileDiffPath(fileDiff);
390 // One annotation per line, so a line that already carries a conversation shows a new
391 // comment underneath it rather than in place of it.
392 const groups = new Map<string, MutableAnnotationGroup>();
393 const groupAt = (side: PullRequestDiffSide, line: number) => {
394 const key = `${side}:${line}`;
395 const existing = groups.get(key);
396 if (existing) return existing;
397 const created: MutableAnnotationGroup = {
398 side,
399 line,
400 threads: [],
401 pending: [],
402 draft: false,
403 };
404 groups.set(key, created);
405 return created;
406 };
407​
408 for (const thread of detail.reviewThreads) {
409 if (thread.path !== path || thread.line === null) continue;
410 if (!placedThreadIds.has(thread.id)) continue;
411 groupAt(thread.side, thread.line).threads.push(thread);
412 }
413 // Pending comments anchor to the head diff exactly like host threads do, so a
414 // commit's diff must not place them either — the same line means other code there.
415 if (commit === null) {
416 for (const comment of pendingComments) {
417 if (comment.path !== path) continue;
418 groupAt(comment.side, comment.line).pending.push(comment);
419 }
420 }
421 if (draft?.fileKey === fileKey) groupAt(draft.side, draft.line).draft = true;
422​
423 const collapsed = isFileDiffCollapsed(fileKey, foldOverride, toggledFiles);
424​
425 const annotations: ReviewAnnotation[] = [...groups.values()].map((group) => ({
426 side: toViewerSide(group.side),
427 lineNumber: group.line,
428 metadata: { threads: group.threads, pending: group.pending, draft: group.draft },
429 }));
430 return {
431 id: fileKey,
432 type: "diff" as const,
433 fileDiff,
434 annotations,
435 collapsed,
436 // The viewer re-renders an item only when its version changes, so everything the
437 // annotations show has to be part of it.
438 version: fnv1a32(
439 `${collapsed ? "1" : "0"}:${annotations
440 .map(
441 ({ side, lineNumber, metadata }) =>
442 `${side}:${lineNumber}:${metadata.draft ? "d" : ""}:${metadata.pending
443 .map((comment) => `${comment.id}:${comment.body}`)
444 .join(",")}:${metadata.threads
445 .map(
446 (thread) =>
447 `${thread.id}:${thread.isResolved ? "r" : ""}:${
448 thread.isOutdated ? "o" : ""
449 }:${thread.comments
450 .map(
451 (comment) =>
452 `${comment.id}:${comment.author?.login ?? ""}:${comment.createdAt}:${comment.body}`,
453 )
454 .join(";")}`,
455 )
456 .join(",")}`,
457 )
458 .join("|")}`,
459 ),
460 };
461 }),
462 [
463 commit,
464 detail.reviewThreads,
465 draft,
466 files,
467 foldOverride,
468 pendingComments,
469 placedThreadIds,
470 toggledFiles,
471 ],
472 );
473 const lineStat = useMemo(() => getDiffLineStat(files), [files]);
474 const fileKeys = useMemo(() => items.map((item) => item.id), [items]);
475 const collapsedFileKeys = useMemo(
476 () => new Set(items.filter((item) => item.collapsed === true).map((item) => item.id)),
477 [items],
478 );
479 const allFilesCollapsed = areAllDiffFilesCollapsed(fileKeys, collapsedFileKeys);
480​
481 // The sentinel is held as state rather than a ref because the viewer mounts its own footer:
482 // an effect reading a ref could run before that node exists and would never arm the observer.
483 const [sentinel, setSentinel] = useState<HTMLDivElement | null>(null);
484 useEffect(() => {
485 // A failed slice must stop the observer. The files already loaded keep the sentinel on
486 // screen, so re-arming it after a failure would ask for the same slice again, forever.
487 if (
488 sentinel === null ||
489 nextCursor === null ||
490 nextCursor === cursor ||
491 diffQuery.isPending ||
492 diffQuery.error !== null
493 ) {
494 return;
495 }
496 const observer = new IntersectionObserver(
497 (observed) => {
498 if (observed.some((entry) => entry.isIntersecting)) {
499 setSliceState((previous) => ({ ...previous, cursor: nextCursor }));
500 }
501 },
502 // Start the next slice slightly before the sentinel is on screen.
503 { rootMargin: "240px" },
504 );
505 observer.observe(sentinel);
506 return () => observer.disconnect();
507 }, [cursor, diffQuery.error, diffQuery.isPending, nextCursor, sentinel]);
508​
509 // A stable identity: the viewer's SlotPortals memoizes each file's header/annotation portal on
510 // these render props, so a fresh function here would recreate every visible file's portal on
511 // every tab re-render (a line-selection drag, a keystroke in the draft, a review-store update).
512 const toggleFile = useCallback(
513 (fileKey: string) =>
514 setToggledFiles((current) => {
515 // The override becomes this file's new default the moment it is folded into the set below,
516 // so nothing has to be re-derived when the reader goes back to choosing one at a time.
517 const next = new Set(current);
518 if (next.has(fileKey)) next.delete(fileKey);
519 else next.add(fileKey);
520 return next;
521 }),
522 [],
523 );
524​
525 const toggleAllFiles = () => {
526 // Held as an override of the default rather than as the file keys on screen: a diff that is
527 // still paging would otherwise bring its next slice in folded, moments after the reader
528 // asked for everything to be open.
529 setFoldOverride(areAllDiffFilesCollapsed(fileKeys, collapsedFileKeys) ? "expanded" : "folded");
530 setToggledFiles(new Set());
531 };
532​
533 // Newest first: the last commit is the one a reader coming back to a change is looking for.
534 const orderedCommits = useMemo(
535 () =>
536 // By instant, not by the text: GitLab keeps a commit's own UTC offset, so two commits
537 // from different zones would sort by how they were written rather than when they landed.
538 detail.commits.toSorted(
539 (left, right) => Date.parse(right.committedDate) - Date.parse(left.committedDate),
540 ),
541 [detail.commits],
542 );
543​
544 const beginComment = useCallback(
545 (range: SelectedLineRange | null, context: { item: CodeViewItem<ReviewAnnotationGroup> }) => {
546 if (!range || !canCommentOnLines) return;
547 const item = context.item;
548 if (item.type !== "diff") return;
549 const file = files.find((candidate) => buildFileDiffRenderKey(candidate) === item.id);
550 if (!file) return;
551 // A range collapses to its last line: only GitHub carries a multi-line comment, and one
552 // that silently lost its first line on the other hosts would be worse than one line.
553 const path = resolveFileDiffPath(file);
554 const previousPath = resolveFileDiffPreviousPath(file);
555 setDraft({
556 fileKey: item.id,
557 path,
558 oldPath: previousPath === path ? null : previousPath,
559 line: range.end,
560 side: fromViewerSide(range.endSide ?? range.side),
561 range,
562 });
563 },
564 [canCommentOnLines, files],
565 );
566​
567 // Built here because the parsed diff only lives here, and built by the same function the
568 // thread panel's own line selection uses — the gesture is the same one, so a second reading of
569 // the hunks would only be a second place for it to drift.
570 const askAboutSelection = useCallback(
571 (anchor: DraftAnchor, question: string) => {
572 const file = files.find((candidate) => buildFileDiffRenderKey(candidate) === anchor.fileKey);
573 const comment =
574 file === undefined
575 ? null
576 : buildDiffReviewComment({
577 id: `pull-request-selection:${anchor.fileKey}:${anchor.range.start}:${anchor.range.end}`,
578 sectionId: `pull-request:${detail.number}`,
579 sectionTitle: `PR #${detail.number} review`,
580 filePath: anchor.path,
581 fileDiff: file,
582 range: anchor.range,
583 text: question,
584 });
585 setDraft(null);
586 setSelectedLines(null);
587 if (comment === null || !onAskAboutSelection) return;
588 onAskAboutSelection({ comment, question });
589 },
590 [detail.number, files, onAskAboutSelection],
591 );
592​
593 // The viewer's SlotPortals memoizes each visible file's header/annotation portal on these
594 // render props and on `options` below; a fresh identity on any of them — as a plain inline
595 // function or object literal would be — invalidates that memo and recreates every portal on
596 // screen on any tab re-render (a drag-selection, a keystroke in the draft, a review-store
597 // update), which is the jank this file is otherwise clean of.
598 const renderCodeViewFooter = useCallback(
599 () =>
600 // Only while something is still owed. A finished diff whose query fails on a later
601 // refresh — a reconnect re-runs every one of them — is whole on screen already, and
602 // saying otherwise sends the reader looking for files that are all there.
603 nextCursor === null ? null : (
604 <div
605 ref={setSentinel}
606 className="flex items-center justify-center gap-2 py-2 text-xs text-muted-foreground"
607 >
608 {diffQuery.error !== null ? (
609 <>
610 <span>The rest of this diff could not be loaded.</span>
611 <Button size="xs" variant="outline" onClick={() => diffQuery.refresh()}>
612 Retry
613 </Button>
614 </>
615 ) : diffQuery.isPending ? (
616 "Loading more files..."
617 ) : null}
618 </div>
619 ),
620 [nextCursor, diffQuery.error, diffQuery.isPending, diffQuery.refresh],
621 );
622​
623 const renderHeaderPrefix = useCallback(
624 (item: CodeViewItem<ReviewAnnotationGroup>) => {
625 // The item the viewer is drawing already carries the state the memo settled on, so the
626 // chevron follows it rather than recomputing the default here.
627 const collapsed = item.collapsed === true;
628 return (
629 <button
630 type="button"
631 aria-expanded={!collapsed}
632 aria-label={collapsed ? "Expand diff" : "Collapse diff"}
633 className={cn(
634 "mr-1 inline-flex size-5 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground",
635 )}
636 onClick={(event) => {
637 event.stopPropagation();
638 toggleFile(item.id);
639 }}
640 >
641 {collapsed ? (
642 <ChevronRightIcon className="size-4" />
643 ) : (
644 <ChevronDownIcon className="size-4" />
645 )}
646 </button>
647 );
648 },
649 [toggleFile],
650 );
651​
652 const diffViewOptions = useMemo(
653 () => ({
654 diffStyle: diffRenderMode === "split" ? ("split" as const) : ("unified" as const),
655 lineDiffType: "none" as const,
656 overflow: wordWrap ? ("wrap" as const) : ("scroll" as const),
657 theme: resolveDiffThemeName(resolvedTheme),
658 themeType: resolvedTheme,
659 stickyHeaders: true,
660 loadDiffFiles,
661 enableGutterUtility: canCommentOnLines && draft === null,
662 enableLineSelection: canCommentOnLines && draft === null,
663 // Two gestures reach the same place: dragging the line numbers selects a range, and the
664 // gutter's own button comments on the one line it sits on. They are separate callbacks in
665 // the viewer, so a reader who only ever presses the button gets nothing unless both are
666 // wired.
667 onGutterUtilityClick: beginComment,
668 onLineSelectionEnd: beginComment,
669 }),
670 [
671 diffRenderMode,
672 wordWrap,
673 resolvedTheme,
674 loadDiffFiles,
675 canCommentOnLines,
676 draft,
677 beginComment,
678 ],
679 );
680​
681 const runThreadCommand = useCallback(
682 async (label: string, run: () => Promise<{ readonly _tag: string }>): Promise<boolean> => {
683 if (threadPending) return false;
684 setThreadPending(true);
685 const result = await run();
686 setThreadPending(false);
687 if (result._tag === "Failure") {
688 toastManager.add({ type: "error", title: label });
689 return false;
690 }
691 onRefresh();
692 return true;
693 },
694 [onRefresh, threadPending],
695 );
696​
697 // A conversation is the same card wired to the same commands whether it sits on its line or
698 // was stranded off the diff; only where it is drawn differs.
699 const renderThreadCard = useCallback(
700 (thread: PullRequestReviewThread) => (
701 <ReviewThreadCard
702 key={thread.id}
703 thread={thread}
704 workspaceRoot={detail.workspaceRoot}
705 canReply={review.reply}
706 canResolve={review.resolve}
707 pending={threadPending}
708 fixPending={pendingFinding === pullRequestFindingKey({ kind: "thread", thread })}
709 {...(onFixFinding ? { onFix: () => onFixFinding({ kind: "thread", thread }) } : {})}
710 onReply={(body) =>
711 runThreadCommand("Reply could not be posted", () =>
712 replyToThread({
713 environmentId,
714 input: { ...reference, threadId: thread.id, body },
715 }),
716 )
717 }
718 onToggleResolved={() =>
719 void runThreadCommand("The conversation could not be updated", () =>
720 setThreadResolution({
721 environmentId,
722 input: { ...reference, threadId: thread.id, resolved: !thread.isResolved },
723 }),
724 )
725 }
726 />
727 ),
728 [
729 detail.workspaceRoot,
730 environmentId,
731 onFixFinding,
732 pendingFinding,
733 reference,
734 replyToThread,
735 review.reply,
736 review.resolve,
737 runThreadCommand,
738 setThreadResolution,
739 threadPending,
740 ],
741 );
742​
743 const renderAnnotation = useCallback(
744 (annotation: ReviewAnnotation) => (
745 <div className="py-1">
746 {annotation.metadata.threads.map(renderThreadCard)}
747 {annotation.metadata.pending.map((comment) => (
748 <PendingReviewCommentCard
749 key={comment.id}
750 comment={comment}
751 onRemove={() => removeComment(reviewKey, comment.id)}
752 />
753 ))}
754 {annotation.metadata.draft && draft ? (
755 <DiffCommentAnnotation
756 kind="draft"
757 rangeLabel={`${draft.path}:${draft.line}`}
758 text=""
759 submitLabel="Add to review"
760 {...(onAskAboutSelection
761 ? {
762 secondaryAction: {
763 label: "Ask",
764 icon: <SparklesIcon className="size-3" />,
765 allowEmpty: true,
766 onAction: (question: string) => askAboutSelection(draft, question),
767 },
768 }
769 : {})}
770 onCancel={() => {
771 setDraft(null);
772 setSelectedLines(null);
773 }}
774 onComment={(body) => {
775 addComment(reviewKey, {
776 id: nextPendingReviewCommentId(),
777 path: draft.path,
778 ...(draft.oldPath === null ? {} : { oldPath: draft.oldPath }),
779 line: draft.line,
780 side: draft.side,
781 body,
782 });
783 setDraft(null);
784 setSelectedLines(null);
785 }}
786 />
787 ) : null}
788 </div>
789 ),
790 [
791 addComment,
792 askAboutSelection,
793 draft,
794 onAskAboutSelection,
795 removeComment,
796 renderThreadCard,
797 reviewKey,
798 ],
799 );
800​
801 /**
802 * The review overlay belongs to the pull request, not to the patch: a change whose diff
803 * cannot be structured — or read at all — is still one a reviewer can approve or reject, so
804 * it survives every branch below. It floats over the scroll area rather than sitting in the
805 * layout flow, so the diff keeps the full height instead of permanently losing a strip to a
806 * footer most reviews never touch. Hidden entirely where the host offers no verdicts, same as
807 * the bar it wraps did.
808 */
809 const reviewOverlay =
810 review.verdicts.length === 0 ? null : (
811 <div className="pointer-events-none absolute inset-x-0 bottom-0 z-10">
812 {reviewOpen ? (
813 <div className="chat-composer-glass pointer-events-auto absolute inset-x-3 bottom-3 rounded-xl border border-border/60 shadow-lg">
814 <Button
815 type="button"
816 size="icon-sm"
817 variant="ghost"
818 aria-label="Close review"
819 className="absolute right-2 top-2"
820 onClick={() => setReviewOpen(false)}
821 >
822 <XIcon className="size-3.5" />
823 </Button>
824 <PullRequestReviewBar
825 environmentId={environmentId}
826 reference={reference}
827 verdicts={review.verdicts}
828 onSubmitted={() => {
829 onRefresh();
830 setReviewOpen(false);
831 }}
832 />
833 </div>
834 ) : (
835 // Bottom-right, clear of the vertical scrollbar the diff view keeps to its own right
836 // edge.
837 <button
838 type="button"
839 className="chat-composer-glass pointer-events-auto absolute bottom-3 right-4 flex items-center gap-1.5 rounded-full border border-border/60 px-3 py-1.5 text-xs font-medium shadow-lg"
840 onClick={() => setReviewOpen(true)}
841 >
842 <MessageSquareIcon className="size-3.5" />
843 Review
844 {pendingComments.length > 0 ? (
845 <span className="flex size-4 items-center justify-center rounded-full bg-accent text-[10px] tabular-nums text-accent-foreground">
846 {pendingComments.length}
847 </span>
848 ) : null}
849 </button>
850 )}
851 </div>
852 );
853 // A rebase or a force-push can take the scoped commit out of the change. Its diff may still
854 // be reachable on the host, but it is no longer part of what is being reviewed, so the scope
855 // goes back to the whole change rather than sitting under a name nothing matches.
856 //
857 // Including when the change reports no commits at all: the scope dropdown is the only way back
858 // to the whole diff and it is not drawn without commits to list, so a scope that outlived them
859 // would leave the tab reading one obsolete commit with nothing to press.
860 const selectedCommit = orderedCommits.find((entry) => entry.oid === commit);
861 useEffect(() => {
862 if (commit !== null && selectedCommit === undefined) {
863 onSelectedCommitChange(null);
864 }
865 }, [commit, onSelectedCommitChange, selectedCommit]);
866 const scopeLabel = selectedCommit ? selectedCommit.messageHeadline : "All commits";
867 /**
868 * The same controls the thread diff panel carries, in the same order, minus the
869 * ignore-whitespace toggle: that is `git diff -w` on the server, and no host's pull request
870 * diff API offers it.
871 */
872 const toolbar = (
873 <div className="surface-subheader justify-between gap-2 px-4 text-xs text-muted-foreground">
874 <div className="flex min-w-0 flex-1 items-center gap-3">
875 {/* A host that reports no commits has nothing to scope by, and a dropdown whose only
876 entry is the scope already showing is a control that does nothing. */}
877 {orderedCommits.length > 0 ? (
878 <DropdownMenu>
879 <DropdownMenuTrigger
880 className="inline-flex h-6 max-w-64 items-center gap-1 rounded-md bg-accent px-2 text-xs font-medium text-accent-foreground outline-none transition-colors hover:bg-accent/80 focus-visible:ring-2 focus-visible:ring-ring"
881 aria-label={`Diff scope: ${scopeLabel}`}
882 >
883 <span className="truncate">{scopeLabel}</span>
884 <ChevronDownIcon className="size-3.5 shrink-0 opacity-70" />
885 </DropdownMenuTrigger>
886 <DropdownMenuContent align="start" className="w-80">
887 <DropdownMenuItem
888 className={commit === null ? "bg-foreground/[0.08]" : undefined}
889 onClick={() => onSelectedCommitChange(null)}
890 >
891 <span>All commits</span>
892 </DropdownMenuItem>
893 {orderedCommits.slice(0, visibleCommitCount).map((entry) => (
894 <DropdownMenuItem
895 key={entry.oid}
896 className={entry.oid === commit ? "bg-foreground/[0.08]" : undefined}
897 onClick={() => onSelectedCommitChange(entry.oid)}
898 >
899 {/* Headlines run long, and the abbreviated oid after one is what a reader
900 matches against the commit list on the host. */}
901 <span className="min-w-0 truncate" title={entry.messageHeadline}>
902 {entry.messageHeadline}
903 </span>
904 <span className="ml-auto shrink-0 font-mono text-xs text-muted-foreground">
905 {entry.oid.slice(0, 7)}
906 </span>
907 </DropdownMenuItem>
908 ))}
909 {orderedCommits.length > visibleCommitCount ? (
910 // Kept out of the radio group: it changes how much of the list is on screen
911 // rather than what the diff is scoped to.
912 <DropdownMenuItem
913 closeOnClick={false}
914 onClick={() => setVisibleCommitCount((count) => count + COMMIT_PAGE_SIZE)}
915 >
916 <span className="text-muted-foreground">
917 Show more ({orderedCommits.length - visibleCommitCount} left)
918 </span>
919 </DropdownMenuItem>
920 ) : null}
921 </DropdownMenuContent>
922 </DropdownMenu>
923 ) : null}
924 {/* One count, and the caveats as icons that carry their own words. Spelled out they
925 competed for a strip this narrow and every one of them truncated to nothing. */}
926 <PullRequestMetaLine>
927 <span className="shrink-0 tabular-nums">
928 {files.length} {files.length === 1 ? "file" : "files"}
929 {nextCursor === null ? "" : "+"}
930 </span>
931 {withheldContent ? (
932 <Tooltip>
933 <TooltipTrigger render={<span className="flex shrink-0 items-center" />}>
934 <TriangleAlertIcon
935 aria-label="Some of this diff was not shown"
936 className="size-3.5 text-amber-600 dark:text-amber-500"
937 />
938 </TooltipTrigger>
939 <TooltipPopup side="bottom">
940 The host withheld part of this diff — a binary file, or a change too large to
941 inline.
942 </TooltipPopup>
943 </Tooltip>
944 ) : null}
945 {commit !== null && review.inlineComment ? (
946 <Tooltip>
947 <TooltipTrigger render={<span className="flex shrink-0 items-center" />}>
948 <MessageSquareOffIcon
949 aria-label="Line comments are written from the whole change"
950 className="size-3.5"
951 />
952 </TooltipTrigger>
953 <TooltipPopup side="bottom">
954 A comment is anchored to the whole change, so switch to All commits to write one.
955 </TooltipPopup>
956 </Tooltip>
957 ) : null}
958 </PullRequestMetaLine>
959 </div>
960 <div className="flex shrink-0 items-center gap-1">
961 <PullRequestDiffStat
962 additions={lineStat.additions}
963 deletions={lineStat.deletions}
964 className="mr-1"
965 />
966 {fileKeys.length > 0 ? (
967 <Tooltip>
968 <TooltipTrigger
969 render={
970 <Button
971 type="button"
972 size="icon-sm"
973 variant="ghost"
974 aria-label={allFilesCollapsed ? "Expand all files" : "Collapse all files"}
975 onClick={toggleAllFiles}
976 />
977 }
978 >
979 {allFilesCollapsed ? (
980 <ChevronsUpDownIcon className="size-3.5" />
981 ) : (
982 <ChevronsDownUpIcon className="size-3.5" />
983 )}
984 </TooltipTrigger>
985 <TooltipPopup side="top">
986 {allFilesCollapsed ? "Expand all files" : "Collapse all files"}
987 </TooltipPopup>
988 </Tooltip>
989 ) : null}
990 <ToggleGroup
991 className="shrink-0 gap-1"
992 size="sm"
993 value={[diffRenderMode]}
994 onValueChange={(value) => {
995 const next = value[0];
996 if (next === "stacked" || next === "split") {
997 setDiffRenderMode(next);
998 }
999 }}
1001 <Toggle aria-label="Stacked diff view" value="stacked" variant="ghost">
1002 <Rows3Icon className="size-3.5" />
1003 </Toggle>
1004 <Toggle aria-label="Split diff view" value="split" variant="ghost">
1005 <Columns2Icon className="size-3.5" />
1006 </Toggle>
1007 </ToggleGroup>
1008 <Tooltip>
1009 <TooltipTrigger
1010 render={
1011 <Toggle
1012 aria-label={wordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
1013 variant="ghost"
1014 size="sm"
1015 pressed={wordWrap}
1016 onPressedChange={(pressed) => {
1017 setWordWrap(Boolean(pressed));
1018 }}
1019 />
1022 <TextWrapIcon className="size-3.5" />
1023 </TooltipTrigger>
1024 <TooltipPopup side="top">
1025 {wordWrap ? "Disable line wrapping" : "Enable line wrapping"}
1026 </TooltipPopup>
1027 </Tooltip>
1028 </div>
1029 </div>
1030 );
1031 // The toolbar rides above every branch below, not just the one with a patch in it: a commit
1032 // whose diff is empty or unreadable still needs the scope dropdown that got the reader there.
1033 const withReviewBar = (body: ReactNode) => (
1034 <div className="flex h-full min-h-0 flex-col">
1035 {toolbar}
1036 {/* The overlay is anchored to this wrapper, not the scroller: absolute positioning
1037 inside an overflowing element tracks the content's bottom edge, which would carry
1038 the trigger away with the first scroll. */}
1039 <div className="relative min-h-0 flex-1">
1040 <div className="h-full overflow-auto">{body}</div>
1041 {reviewOverlay}
1042 </div>
1043 </div>
1044 );
1045​
1046 // Under the toolbar rather than in place of it, so choosing a commit does not take the
1047 // dropdown that was just used off the screen while its diff loads.
1048 if (diffQuery.isPending && loadedSlices.length === 0) {
1049 return withReviewBar(<DiffPanelLoadingState label="Loading pull request diff..." />);
1051​
1052 // A slice that fails once there are files on screen is reported at the end of them instead:
1053 // the diff already read is worth more than the error that stopped it growing.
1054 if (diffQuery.error && loadedSlices.length === 0) {
1055 return withReviewBar(
1056 <p className="px-4 py-5 text-sm text-muted-foreground">{diffQuery.error}</p>,
1057 );
1059​
1060 // A patch the viewer cannot structure (binary, or a format it does not parse) still has to
1061 // be readable, so it falls back to the raw text rather than an empty tab. Only once the diff
1062 // is whole: returning here while a cursor is outstanding would take the sentinel off screen
1063 // and end the walk, leaving the rest of the change unasked for.
1064 const rawSlices =
1065 nextCursor === null
1066 ? parsedSlices.flatMap((parsed) => (parsed?.kind === "raw" ? [parsed] : []))
1067 : [];
1068 if (files.length === 0 && rawSlices.length > 0) {
1069 return withReviewBar(
1070 <div className="space-y-4 px-4 py-5">
1071 {rawSlices.map((slice) => (
1072 <div key={`${slice.reason}:${slice.text.slice(0, 64)}`} className="space-y-2">
1073 <p className="text-xs text-muted-foreground">{slice.reason}</p>
1074 <pre className="whitespace-pre-wrap break-words font-mono text-xs">{slice.text}</pre>
1075 </div>
1076 ))}
1077 </div>,
1078 );
1080​
1081 if (items.length === 0 && nextCursor === null) {
1082 return withReviewBar(
1083 <p className="px-4 py-5 text-sm text-muted-foreground">
1084 {commit === null
1085 ? "This pull request has no file changes."
1086 : "This commit has no file changes."}
1087 </p>,
1088 );
1090​
1091 const orphanThreads = detail.reviewThreads.filter((thread) => !placedThreadIds.has(thread.id));
1092 // A file carrying five stranded conversations should read as that file once rather than as
1093 // five copies of its path.
1094 const orphanFiles = new Map<string, PullRequestReviewThread[]>();
1095 for (const thread of orphanThreads) {
1096 const existing = orphanFiles.get(thread.path);
1097 if (existing) existing.push(thread);
1098 else orphanFiles.set(thread.path, [thread]);
1100​
1101 const unstructured =
1102 rawSlices.length === 0 ? null : (
1103 // A slice the viewer cannot structure is still part of the change. Shown under the files
1104 // that did parse rather than dropped, because the alternative is a diff that silently
1105 // omits whatever the viewer could not read.
1106 <div className="space-y-4 border-t border-border/60 px-4 py-5">
1107 {rawSlices.map((slice) => (
1108 <div key={`${slice.reason}:${slice.text.slice(0, 64)}`} className="space-y-2">
1109 <p className="text-xs text-muted-foreground">{slice.reason}</p>
1110 <pre className="whitespace-pre-wrap break-words font-mono text-xs">{slice.text}</pre>
1111 </div>
1112 ))}
1113 </div>
1114 );
1115​
1116 return (
1117 <DiffWorkerPoolProvider>
1118 <div className="flex h-full min-h-0 flex-col">
1119 {toolbar}
1120 {/* Above the code, closed, and counted: these belong to the change rather than to any
1121 line of it, and in the stream they read as cards dropped into the patch. */}
1122 {orphanFiles.size > 0 ? (
1123 <Collapsible
1124 className="shrink-0 border-b border-border/60"
1125 open={orphansOpen}
1126 onOpenChange={setOrphansOpen}
1128 {/* Still a heading, so the section keeps its place in a screen reader's outline;
1129 the count is spelled out there rather than left as a bare number. */}
1130 <h2>
1131 <CollapsibleTrigger className="flex w-full items-center gap-1.5 px-4 py-2 text-left text-xs text-muted-foreground">
1132 {/* While slices are still arriving a conversation may simply belong to a file
1133 that has not landed yet, which is not the same as being off the diff. */}
1134 <span>
1135 {nextCursor === null
1136 ? "Conversations not on the current diff"
1137 : "Conversations not on the diff loaded so far"}
1138 </span>
1139 <ChevronRightIcon
1140 aria-hidden
1141 className={cn("size-3.5 transition-transform", orphansOpen && "rotate-90")}
1142 />
1143 <span aria-hidden className="tabular-nums">
1144 {orphanThreads.length}
1145 </span>
1146 <span className="sr-only">
1147 {orphanThreads.length === 1
1148 ? "1 conversation"
1149 : `${orphanThreads.length} conversations`}
1150 </span>
1151 </CollapsibleTrigger>
1152 </h2>
1153 <CollapsiblePanel>
1154 {/* Capped: opened on a change with dozens of them, this would otherwise leave no
1155 room for the diff it sits above. */}
1156 <div className="max-h-64 space-y-3 overflow-auto px-4 pb-3">
1157 {[...orphanFiles].map(([path, threads]) => (
1158 <div key={path}>
1159 <p className="truncate px-3 text-xs text-muted-foreground" title={path}>
1160 {path}
1161 </p>
1162 <div className="mt-1 space-y-2">
1163 {threads.map((thread) => (
1164 <div key={thread.id}>
1165 {thread.line === null ? null : (
1166 <p className="px-3 text-xs text-muted-foreground">Line {thread.line}</p>
1167 )}
1168 {renderThreadCard(thread)}
1169 </div>
1170 ))}
1171 </div>
1172 </div>
1173 ))}
1174 </div>
1175 </CollapsiblePanel>
1176 </Collapsible>
1177 ) : null}
1178 {/* Relative wrapper so the review overlay floats over the diff rather than pushing it
1179 up; the viewer inside still owns its own scrolling. */}
1180 <div
1181 className="relative min-h-0 flex-1"
1182 // The chevron answers this too, but the whole header row is the target a reader
1183 // actually aims for. The header lives in the viewer's shadow tree, so the capture
1184 // listener walks `composedPath` — the only way to see through the shadow boundary.
1185 onClickCapture={(event) => {
1186 const composedPath = event.nativeEvent.composedPath?.() ?? [];
1187 for (const node of composedPath) {
1188 if (!(node instanceof HTMLElement)) continue;
1189 // A control inside the header — the collapse chevron — handles itself, and
1190 // this capture listener fires before its own click does. Leave it alone or
1191 // the two toggles cancel out.
1192 if (node instanceof HTMLButtonElement || node instanceof HTMLAnchorElement) {
1193 return;
1195 if (node.hasAttribute("data-diffs-header")) {
1196 const filePath = node.querySelector("[data-title]")?.textContent?.trim();
1197 if (filePath === undefined || filePath === "") return;
1198 const item = items.find(
1199 (candidate) => resolveFileDiffPath(candidate.fileDiff) === filePath,
1200 );
1201 if (item !== undefined) toggleFile(item.id);
1202 return;
1205 }}
1207 {/* The viewer virtualizes against the element it is told is scrolling and places its
1208 rows absolutely, so it has to own that element — the thread diff panel hands it the
1209 same one. Scrolling from a parent instead leaves it painting over its neighbours. */}
1210 <StyledDiffCodeView<ReviewAnnotationGroup>
1211 // Keep scrollbar space stable so file metadata and line numbers do not shift as a
1212 // diff crosses the overflow boundary. The viewer is itself focusable for keyboard
1213 // interaction, but its native host outline clips and competes with the focus
1214 // indicators on its actual controls.
1215 className="h-full overflow-auto [scrollbar-gutter:stable]"
1216 items={items}
1217 selectedLines={selectedLines}
1218 onSelectedLinesChange={setSelectedLines}
1219 options={diffViewOptions}
1220 // The viewer owns the scroll container, so the sentinel that asks for the next slice
1221 // has to live inside it — at the end of the files, where reaching it means the reader
1222 // is running out of diff.
1223 renderCodeViewFooter={renderCodeViewFooter}
1224 renderHeaderPrefix={renderHeaderPrefix}
1225 renderAnnotation={renderAnnotation}
1226 />
1227 {reviewOverlay}
1228 </div>
1229 {unstructured}
1230 </div>
1231 </DiffWorkerPoolProvider>
1232 );
1234​
1235export default PullRequestCodeTab;