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

DiffPanel.tsx

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