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

DiffPanel.tsx

630 lines23.9 KB

1import { parsePatchFiles } from "@pierre/diffs";
2import { FileDiff, type FileDiffMetadata, Virtualizer } from "@pierre/diffs/react";
3import { useQuery } from "@tanstack/react-query";
4import { useNavigate, useParams, useSearch } from "@tanstack/react-router";
5import { ThreadId, type TurnId } from "@t3tools/contracts";
6import { ChevronLeftIcon, ChevronRightIcon, Columns2Icon, Rows3Icon } from "lucide-react";
7import {
8 type WheelEvent as ReactWheelEvent,
9 useCallback,
10 useEffect,
11 useMemo,
12 useRef,
13 useState,
14} from "react";
15import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
16import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery";
17import { cn } from "~/lib/utils";
18import { readNativeApi } from "../nativeApi";
19import { preferredTerminalEditor, resolvePathLinkTarget } from "../terminal-links";
20import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch";
21import { isElectron } from "../env";
22import { useTheme } from "../hooks/useTheme";
23import { buildPatchCacheKey } from "../lib/diffRendering";
24import { resolveDiffThemeName } from "../lib/diffRendering";
25import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
26import { useStore } from "../store";
27import { ToggleGroup, Toggle } from "./ui/toggle-group";
28​
29type DiffRenderMode = "stacked" | "split";
30type DiffThemeType = "light" | "dark";
31​
32const DIFF_PANEL_UNSAFE_CSS = `
33[data-diffs-header],
34[data-diff],
35[data-file],
36[data-error-wrapper],
37[data-virtualizer-buffer] {
38 --diffs-bg: color-mix(in srgb, var(--card) 90%, var(--background)) !important;
39 --diffs-light-bg: color-mix(in srgb, var(--card) 90%, var(--background)) !important;
40 --diffs-dark-bg: color-mix(in srgb, var(--card) 90%, var(--background)) !important;
41 --diffs-token-light-bg: transparent;
42 --diffs-token-dark-bg: transparent;
43​
44 --diffs-bg-context-override: color-mix(in srgb, var(--background) 97%, var(--foreground));
45 --diffs-bg-hover-override: color-mix(in srgb, var(--background) 94%, var(--foreground));
46 --diffs-bg-separator-override: color-mix(in srgb, var(--background) 95%, var(--foreground));
47 --diffs-bg-buffer-override: color-mix(in srgb, var(--background) 90%, var(--foreground));
48​
49 --diffs-bg-addition-override: color-mix(in srgb, var(--background) 92%, var(--success));
50 --diffs-bg-addition-number-override: color-mix(in srgb, var(--background) 88%, var(--success));
51 --diffs-bg-addition-hover-override: color-mix(in srgb, var(--background) 85%, var(--success));
52 --diffs-bg-addition-emphasis-override: color-mix(in srgb, var(--background) 80%, var(--success));
53​
54 --diffs-bg-deletion-override: color-mix(in srgb, var(--background) 92%, var(--destructive));
55 --diffs-bg-deletion-number-override: color-mix(in srgb, var(--background) 88%, var(--destructive));
56 --diffs-bg-deletion-hover-override: color-mix(in srgb, var(--background) 85%, var(--destructive));
57 --diffs-bg-deletion-emphasis-override: color-mix(
58 in srgb,
59 var(--background) 80%,
60 var(--destructive)
61 );
62​
63 background-color: var(--diffs-bg) !important;
65​
66[data-file-info] {
67 background-color: color-mix(in srgb, var(--card) 94%, var(--foreground)) !important;
68 border-block-color: var(--border) !important;
69 color: var(--foreground) !important;
71​
72[data-diffs-header] {
73 position: sticky !important;
74 top: 0;
75 z-index: 4;
76 background-color: color-mix(in srgb, var(--card) 94%, var(--foreground)) !important;
77 border-bottom: 1px solid var(--border) !important;
79​
80[data-title] {
81 cursor: pointer;
82 transition:
83 color 120ms ease,
84 text-decoration-color 120ms ease;
85 text-decoration: underline;
86 text-decoration-color: transparent;
87 text-underline-offset: 2px;
89​
90[data-title]:hover {
91 color: color-mix(in srgb, var(--foreground) 84%, var(--primary)) !important;
92 text-decoration-color: currentColor;
94`;
95​
96type RenderablePatch =
97 | {
98 kind: "files";
99 files: FileDiffMetadata[];
100 }
101 | {
102 kind: "raw";
103 text: string;
104 reason: string;
105 };
106​
107function getRenderablePatch(
108 patch: string | undefined,
109 cacheScope = "diff-panel",
110): RenderablePatch | null {
111 if (!patch) return null;
112 const normalizedPatch = patch.trim();
113 if (normalizedPatch.length === 0) return null;
114​
115 try {
116 const parsedPatches = parsePatchFiles(
117 normalizedPatch,
118 buildPatchCacheKey(normalizedPatch, cacheScope),
119 );
120 const files = parsedPatches.flatMap((parsedPatch) => parsedPatch.files);
121 if (files.length > 0) {
122 return { kind: "files", files };
123 }
124​
125 return {
126 kind: "raw",
127 text: normalizedPatch,
128 reason: "Unsupported diff format. Showing raw patch.",
129 };
130 } catch {
131 return {
132 kind: "raw",
133 text: normalizedPatch,
134 reason: "Failed to parse patch. Showing raw patch.",
135 };
136 }
138​
139function resolveFileDiffPath(fileDiff: FileDiffMetadata): string {
140 const raw = fileDiff.name ?? fileDiff.prevName ?? "";
141 if (raw.startsWith("a/") || raw.startsWith("b/")) {
142 return raw.slice(2);
143 }
144 return raw;
146​
147function buildFileDiffRenderKey(fileDiff: FileDiffMetadata): string {
148 return fileDiff.cacheKey ?? `${fileDiff.prevName ?? "none"}:${fileDiff.name}`;
150​
151function formatTurnChipTimestamp(isoDate: string): string {
152 return new Intl.DateTimeFormat(undefined, {
153 hour: "numeric",
154 minute: "2-digit",
155 }).format(new Date(isoDate));
157​
158interface DiffPanelProps {
159 mode?: "inline" | "sheet" | "sidebar";
161​
162export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
163​
164export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
165 const navigate = useNavigate();
166 const { resolvedTheme } = useTheme();
167 const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
168 const patchViewportRef = useRef<HTMLDivElement>(null);
169 const turnStripRef = useRef<HTMLDivElement>(null);
170 const [canScrollTurnStripLeft, setCanScrollTurnStripLeft] = useState(false);
171 const [canScrollTurnStripRight, setCanScrollTurnStripRight] = useState(false);
172 const routeThreadId = useParams({
173 strict: false,
174 select: (params) => (params.threadId ? ThreadId.makeUnsafe(params.threadId) : null),
175 });
176 const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) });
177 const activeThreadId = routeThreadId;
178 const activeThread = useStore((store) =>
179 activeThreadId ? store.threads.find((thread) => thread.id === activeThreadId) : undefined,
180 );
181 const activeProjectId = activeThread?.projectId ?? null;
182 const activeProject = useStore((store) =>
183 activeProjectId ? store.projects.find((project) => project.id === activeProjectId) : undefined,
184 );
185 const activeCwd = activeThread?.worktreePath ?? activeProject?.cwd;
186 const gitBranchesQuery = useQuery(gitBranchesQueryOptions(activeCwd ?? null));
187 const isGitRepo = gitBranchesQuery.data?.isRepo ?? true;
188 const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
189 useTurnDiffSummaries(activeThread);
190 const orderedTurnDiffSummaries = useMemo(
191 () =>
192 [...turnDiffSummaries].toSorted((left, right) => {
193 const leftTurnCount =
194 left.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[left.turnId] ?? 0;
195 const rightTurnCount =
196 right.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[right.turnId] ?? 0;
197 if (leftTurnCount !== rightTurnCount) {
198 return rightTurnCount - leftTurnCount;
199 }
200 return right.completedAt.localeCompare(left.completedAt);
201 }),
202 [inferredCheckpointTurnCountByTurnId, turnDiffSummaries],
203 );
204​
205 const selectedTurnId = diffSearch.diffTurnId ?? null;
206 const selectedFilePath = selectedTurnId !== null ? (diffSearch.diffFilePath ?? null) : null;
207 const selectedTurn =
208 selectedTurnId === null
209 ? undefined
210 : (orderedTurnDiffSummaries.find((summary) => summary.turnId === selectedTurnId) ??
211 orderedTurnDiffSummaries[0]);
212 const selectedCheckpointTurnCount =
213 selectedTurn &&
214 (selectedTurn.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[selectedTurn.turnId]);
215 const selectedCheckpointRange = useMemo(
216 () =>
217 typeof selectedCheckpointTurnCount === "number"
218 ? {
219 fromTurnCount: Math.max(0, selectedCheckpointTurnCount - 1),
220 toTurnCount: selectedCheckpointTurnCount,
221 }
222 : null,
223 [selectedCheckpointTurnCount],
224 );
225 const conversationCheckpointTurnCount = useMemo(() => {
226 const turnCounts = orderedTurnDiffSummaries
227 .map(
228 (summary) =>
229 summary.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[summary.turnId],
230 )
231 .filter((value): value is number => typeof value === "number");
232 if (turnCounts.length === 0) {
233 return undefined;
234 }
235 const latest = Math.max(...turnCounts);
236 return latest > 0 ? latest : undefined;
237 }, [inferredCheckpointTurnCountByTurnId, orderedTurnDiffSummaries]);
238 const conversationCheckpointRange = useMemo(
239 () =>
240 !selectedTurn && typeof conversationCheckpointTurnCount === "number"
241 ? {
242 fromTurnCount: 0,
243 toTurnCount: conversationCheckpointTurnCount,
244 }
245 : null,
246 [conversationCheckpointTurnCount, selectedTurn],
247 );
248 const activeCheckpointRange = selectedTurn
249 ? selectedCheckpointRange
250 : conversationCheckpointRange;
251 const conversationCacheScope = useMemo(() => {
252 if (selectedTurn || orderedTurnDiffSummaries.length === 0) {
253 return null;
254 }
255 return `conversation:${orderedTurnDiffSummaries.map((summary) => summary.turnId).join(",")}`;
256 }, [orderedTurnDiffSummaries, selectedTurn]);
257 const activeCheckpointDiffQuery = useQuery(
258 checkpointDiffQueryOptions({
259 threadId: activeThreadId,
260 fromTurnCount: activeCheckpointRange?.fromTurnCount ?? null,
261 toTurnCount: activeCheckpointRange?.toTurnCount ?? null,
262 cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : conversationCacheScope,
263 enabled: isGitRepo,
264 }),
265 );
266 const selectedTurnCheckpointDiff = selectedTurn
267 ? activeCheckpointDiffQuery.data?.diff
268 : undefined;
269 const conversationCheckpointDiff = selectedTurn
270 ? undefined
271 : activeCheckpointDiffQuery.data?.diff;
272 const isLoadingCheckpointDiff = activeCheckpointDiffQuery.isLoading;
273 const checkpointDiffError =
274 activeCheckpointDiffQuery.error instanceof Error
275 ? activeCheckpointDiffQuery.error.message
276 : activeCheckpointDiffQuery.error
277 ? "Failed to load checkpoint diff."
278 : null;
279​
280 const selectedPatch = selectedTurn ? selectedTurnCheckpointDiff : conversationCheckpointDiff;
281 const hasResolvedPatch = typeof selectedPatch === "string";
282 const hasNoNetChanges = hasResolvedPatch && selectedPatch.trim().length === 0;
283 const renderablePatch = useMemo(
284 () => getRenderablePatch(selectedPatch, `diff-panel:${resolvedTheme}`),
285 [resolvedTheme, selectedPatch],
286 );
287 const renderableFiles = useMemo(() => {
288 if (!renderablePatch || renderablePatch.kind !== "files") {
289 return [];
290 }
291 return renderablePatch.files.toSorted((left, right) =>
292 resolveFileDiffPath(left).localeCompare(resolveFileDiffPath(right), undefined, {
293 numeric: true,
294 sensitivity: "base",
295 }),
296 );
297 }, [renderablePatch]);
298​
299 useEffect(() => {
300 if (!selectedFilePath || !patchViewportRef.current) {
301 return;
302 }
303 const target = Array.from(
304 patchViewportRef.current.querySelectorAll<HTMLElement>("[data-diff-file-path]"),
305 ).find((element) => element.dataset.diffFilePath === selectedFilePath);
306 target?.scrollIntoView({ block: "nearest" });
307 }, [selectedFilePath, renderableFiles]);
308​
309 const openDiffFileInEditor = useCallback(
310 (filePath: string) => {
311 const api = readNativeApi();
312 if (!api) return;
313 const targetPath = activeCwd ? resolvePathLinkTarget(filePath, activeCwd) : filePath;
314 void api.shell.openInEditor(targetPath, preferredTerminalEditor()).catch((error) => {
315 console.warn("Failed to open diff file in editor.", error);
316 });
317 },
318 [activeCwd],
319 );
320​
321 const selectTurn = (turnId: TurnId) => {
322 if (!activeThread) return;
323 void navigate({
324 to: "/$threadId",
325 params: { threadId: activeThread.id },
326 search: (previous) => {
327 const rest = stripDiffSearchParams(previous);
328 return { ...rest, diff: "1", diffTurnId: turnId };
329 },
330 });
331 };
332 const selectWholeConversation = () => {
333 if (!activeThread) return;
334 void navigate({
335 to: "/$threadId",
336 params: { threadId: activeThread.id },
337 search: (previous) => {
338 const rest = stripDiffSearchParams(previous);
339 return { ...rest, diff: "1" };
340 },
341 });
342 };
343 const updateTurnStripScrollState = useCallback(() => {
344 const element = turnStripRef.current;
345 if (!element) {
346 setCanScrollTurnStripLeft(false);
347 setCanScrollTurnStripRight(false);
348 return;
349 }
350​
351 const maxScrollLeft = Math.max(0, element.scrollWidth - element.clientWidth);
352 setCanScrollTurnStripLeft(element.scrollLeft > 4);
353 setCanScrollTurnStripRight(element.scrollLeft < maxScrollLeft - 4);
354 }, []);
355 const scrollTurnStripBy = useCallback((offset: number) => {
356 const element = turnStripRef.current;
357 if (!element) return;
358 element.scrollBy({ left: offset, behavior: "smooth" });
359 }, []);
360 const onTurnStripWheel = useCallback((event: ReactWheelEvent<HTMLDivElement>) => {
361 const element = turnStripRef.current;
362 if (!element) return;
363 if (element.scrollWidth <= element.clientWidth + 1) return;
364 if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
365​
366 event.preventDefault();
367 element.scrollBy({ left: event.deltaY, behavior: "auto" });
368 }, []);
369​
370 useEffect(() => {
371 const element = turnStripRef.current;
372 if (!element) return;
373​
374 const frameId = window.requestAnimationFrame(() => updateTurnStripScrollState());
375 const onScroll = () => updateTurnStripScrollState();
376​
377 element.addEventListener("scroll", onScroll, { passive: true });
378​
379 const resizeObserver = new ResizeObserver(() => updateTurnStripScrollState());
380 resizeObserver.observe(element);
381​
382 return () => {
383 window.cancelAnimationFrame(frameId);
384 element.removeEventListener("scroll", onScroll);
385 resizeObserver.disconnect();
386 };
387 }, [updateTurnStripScrollState]);
388​
389 useEffect(() => {
390 const frameId = window.requestAnimationFrame(() => updateTurnStripScrollState());
391 return () => {
392 window.cancelAnimationFrame(frameId);
393 };
394 }, [orderedTurnDiffSummaries, selectedTurnId, updateTurnStripScrollState]);
395​
396 useEffect(() => {
397 const element = turnStripRef.current;
398 if (!element) return;
399​
400 const selectedChip = element.querySelector<HTMLElement>("[data-turn-chip-selected='true']");
401 selectedChip?.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "smooth" });
402 }, [selectedTurn?.turnId, selectedTurnId]);
403​
404 const shouldUseDragRegion = isElectron && mode !== "sheet";
405 const headerRow = (
406 <>
407 <div className="relative min-w-0 flex-1 [-webkit-app-region:no-drag]">
408 {canScrollTurnStripLeft && (
409 <div className="pointer-events-none absolute inset-y-0 left-8 z-10 w-7 bg-linear-to-r from-card to-transparent" />
410 )}
411 {canScrollTurnStripRight && (
412 <div className="pointer-events-none absolute inset-y-0 right-8 z-10 w-7 bg-linear-to-l from-card to-transparent" />
413 )}
414 <button
415 type="button"
416 className={cn(
417 "absolute left-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors",
418 canScrollTurnStripLeft
419 ? "border-border/70 hover:border-border hover:text-foreground"
420 : "cursor-not-allowed border-border/40 text-muted-foreground/40",
421 )}
422 onClick={() => scrollTurnStripBy(-180)}
423 disabled={!canScrollTurnStripLeft}
424 aria-label="Scroll turn list left"
425 >
426 <ChevronLeftIcon className="size-3.5" />
427 </button>
428 <button
429 type="button"
430 className={cn(
431 "absolute right-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors",
432 canScrollTurnStripRight
433 ? "border-border/70 hover:border-border hover:text-foreground"
434 : "cursor-not-allowed border-border/40 text-muted-foreground/40",
435 )}
436 onClick={() => scrollTurnStripBy(180)}
437 disabled={!canScrollTurnStripRight}
438 aria-label="Scroll turn list right"
439 >
440 <ChevronRightIcon className="size-3.5" />
441 </button>
442 <div
443 ref={turnStripRef}
444 className="turn-chip-strip flex gap-1 overflow-x-auto px-8 py-0.5"
445 onWheel={onTurnStripWheel}
446 >
447 <button
448 type="button"
449 className="shrink-0 rounded-md"
450 onClick={selectWholeConversation}
451 data-turn-chip-selected={selectedTurnId === null}
452 >
453 <div
454 className={cn(
455 "rounded-md border px-2 py-1 text-left transition-colors",
456 selectedTurnId === null
457 ? "border-border bg-accent text-accent-foreground"
458 : "border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80",
459 )}
460 >
461 <div className="text-[10px] leading-tight font-medium">All turns</div>
462 </div>
463 </button>
464 {orderedTurnDiffSummaries.map((summary) => (
465 <button
466 key={summary.turnId}
467 type="button"
468 className="shrink-0 rounded-md"
469 onClick={() => selectTurn(summary.turnId)}
470 title={summary.turnId}
471 data-turn-chip-selected={summary.turnId === selectedTurn?.turnId}
472 >
473 <div
474 className={cn(
475 "rounded-md border px-2 py-1 text-left transition-colors",
476 summary.turnId === selectedTurn?.turnId
477 ? "border-border bg-accent text-accent-foreground"
478 : "border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80",
479 )}
480 >
481 <div className="flex items-center gap-1">
482 <span className="text-[10px] leading-tight font-medium">
483 Turn{" "}
484 {summary.checkpointTurnCount ??
485 inferredCheckpointTurnCountByTurnId[summary.turnId] ??
486 "?"}
487 </span>
488 <span className="text-[9px] leading-tight opacity-70">
489 {formatTurnChipTimestamp(summary.completedAt)}
490 </span>
491 </div>
492 </div>
493 </button>
494 ))}
495 </div>
496 </div>
497 <ToggleGroup
498 className="shrink-0 [-webkit-app-region:no-drag]"
499 variant="outline"
500 size="xs"
501 value={[diffRenderMode]}
502 onValueChange={(value) => {
503 const next = value[0];
504 if (next === "stacked" || next === "split") {
505 setDiffRenderMode(next);
506 }
507 }}
508 >
509 <Toggle aria-label="Stacked diff view" value="stacked">
510 <Rows3Icon className="size-3" />
511 </Toggle>
512 <Toggle aria-label="Split diff view" value="split">
513 <Columns2Icon className="size-3" />
514 </Toggle>
515 </ToggleGroup>
516 </>
517 );
518 const headerRowClassName = cn(
519 "flex items-center justify-between gap-2 px-4",
520 shouldUseDragRegion ? "drag-region h-[52px] border-b border-border" : "h-12",
521 );
522​
523 return (
524 <div
525 className={cn(
526 "flex h-full min-w-0 flex-col bg-background",
527 mode === "inline"
528 ? "w-[42vw] min-w-[360px] max-w-[560px] shrink-0 border-l border-border"
529 : "w-full",
530 )}
531 >
532 {shouldUseDragRegion ? (
533 <div className={headerRowClassName}>{headerRow}</div>
534 ) : (
535 <div className="border-b border-border">
536 <div className={headerRowClassName}>{headerRow}</div>
537 </div>
538 )}
539​
540 {!activeThread ? (
541 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
542 Select a thread to inspect turn diffs.
543 </div>
544 ) : !isGitRepo ? (
545 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
546 Turn diffs are unavailable because this project is not a git repository.
547 </div>
548 ) : orderedTurnDiffSummaries.length === 0 ? (
549 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
550 No completed turns yet.
551 </div>
552 ) : (
553 <>
554 <div
555 ref={patchViewportRef}
556 className="diff-panel-viewport min-h-0 min-w-0 flex-1 overflow-hidden"
557 >
558 {checkpointDiffError && !renderablePatch && (
559 <div className="px-3">
560 <p className="mb-2 text-[11px] text-red-500/80">{checkpointDiffError}</p>
561 </div>
562 )}
563 {!renderablePatch ? (
564 <div className="flex h-full items-center justify-center px-3 py-2 text-xs text-muted-foreground/70">
565 <p>
566 {isLoadingCheckpointDiff
567 ? "Loading checkpoint diff..."
568 : hasNoNetChanges
569 ? "No net changes in this selection."
570 : "No patch available for this selection."}
571 </p>
572 </div>
573 ) : renderablePatch.kind === "files" ? (
574 <Virtualizer
575 className="diff-render-surface h-full min-h-0 overflow-auto px-2 pb-2"
576 config={{
577 overscrollSize: 600,
578 intersectionObserverMargin: 1200,
579 }}
580 >
581 {renderableFiles.map((fileDiff) => {
582 const filePath = resolveFileDiffPath(fileDiff);
583 const fileKey = buildFileDiffRenderKey(fileDiff);
584 const themedFileKey = `${fileKey}:${resolvedTheme}`;
585 return (
586 <div
587 key={themedFileKey}
588 data-diff-file-path={filePath}
589 className="diff-render-file mb-2 rounded-md first:mt-2 last:mb-0"
590 onClickCapture={(event) => {
591 const nativeEvent = event.nativeEvent as MouseEvent;
592 const composedPath = nativeEvent.composedPath?.() ?? [];
593 const clickedHeader = composedPath.some((node) => {
594 if (!(node instanceof Element)) return false;
595 return node.hasAttribute("data-title");
596 });
597 if (!clickedHeader) return;
598 openDiffFileInEditor(filePath);
599 }}
600 >
601 <FileDiff
602 fileDiff={fileDiff}
603 options={{
604 diffStyle: diffRenderMode === "split" ? "split" : "unified",
605 lineDiffType: "none",
606 theme: resolveDiffThemeName(resolvedTheme),
607 themeType: resolvedTheme as DiffThemeType,
608 unsafeCSS: DIFF_PANEL_UNSAFE_CSS,
609 }}
610 />
611 </div>
612 );
613 })}
614 </Virtualizer>
615 ) : (
616 <div className="h-full overflow-auto p-2">
617 <div className="space-y-2">
618 <p className="text-[11px] text-muted-foreground/75">{renderablePatch.reason}</p>
619 <pre className="max-h-[72vh] overflow-auto rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90">
620 {renderablePatch.text}
621 </pre>
622 </div>
623 </div>
624 )}
625 </div>
626 </>
627 )}
628 </div>
629 );