Skip to content
Eskais UI

Diff

Diff View

The renderer behind TextDiff and GitDiff: every file's lines in one virtualized scroller (UI SDK createVirtualizer), unified or split, folded unchanged regions, changed-word highlights, Lezer syntax colours parsed in slices and applied only to the lines on screen, one tab stop over the lines (createGridFocus), j/k and n/p between hunks and files, Shift ranges for comments (onLineSelect), find in page across folded and off-screen lines, and agent actions.

Example

Modifiedpackage.yml2 additions, 1 deletion
@@ -1,3 +1,4 @@
Line 1
Line 1
Removed, line 2
Added, line 2
Line 3
Line 3
Added, line 4

Installation

npx shadcn@latest add @eskais/diff-view
npm packages@lezer/common@1.5.5@lezer/highlight@1.2.5lucide-react

Usage

Import
import { diffLabels, diffLabelsEs } from "@/components/ui/diff-labels"import { createDiffSyntax } from "@/components/ui/diff-syntax"import { createDocumentBuilder, findableOf, gapLines, toViewFiles } from "@/components/ui/diff-view-model"import { defaultMetrics, readMetrics, rowHeight, sameMetrics } from "@/components/ui/diff-view-metrics"import { createLineSelection, lineAt, lineRow } from "@/components/ui/diff-view-selection"import { connectDiffScroll } from "@/components/ui/diff-view-scroller"import { createDiffDocument } from "@/components/ui/diff-view-document"import { createDiffViewController, diffView } from "@/components/ui/diff-view-primitive"import { DiffViewRow, hunkHeader, loneSide } from "@/components/ui/diff-view-rows"import { DiffStat, FileChange } from "@/components/ui/diff-stat"import { DiffFileHeader, DiffNoticeRow, renameLabel } from "@/components/ui/diff-file-header"import { DiffView } from "@/components/ui/diff-view"

DiffView renders file diffs you built yourself (toViewFiles over FileDiffs from parsePatch or diffText). TextDiff and GitDiff are DiffView with input handling and chrome; reach for it to add your own toolbar or side panel, driving it with createDiffViewController.

API reference

DiffStat

PropTypeDefault
additionsrequirednumber–
deletionsrequirednumber–
labelsrequiredDiffLabels–
barbooleantrue
classNamestring–

FileChange

PropTypeDefault
diffrequiredFileDiff–
labelsrequiredDiffLabels–
barbooleantrue

DiffView

PropTypeDefault
labelsOverridable accessible names and the few visible words; pass a stable object (a constant).DiffLabelsdiffLabels
classNamestring–
aria-labelstring–
aria-busyWhile a newer diff is computed: the current one stays on screen.boolean–
emptyShown when no file has a change.ReactNode–
height`auto` (default) grows to the diff and scrolls with the nearest scrolling ancestor, or the page, which the virtualizer follows; a `--diff-max-height` set on it or an ancestor caps it and it scrolls inside past that. `fill` takes the height its parent gives it, for a diff that fills a pane."auto" | "fill""auto"

Also takes DiffViewOptions.

Other exports

diffLabelsdiffLabelsEscreateDiffSyntaxcreateDocumentBuilderfindableOfgapLinestoViewFilesdefaultMetricsreadMetricsrowHeightsameMetricscreateLineSelectionlineAtlineRowconnectDiffScrollcreateDiffDocumentcreateDiffViewControllerdiffViewDiffViewRowhunkHeaderloneSideDiffFileHeaderDiffNoticeRowrenameLabeltype DiffLabelstype DiffSidetype DiffSyntaxtype SyntaxSpantype BuildStatetype DiffDocumenttype DiffGaptype DiffLayouttype DiffNoticetype DiffRowtype DiffViewFiletype DiffMetricstype DiffLineReftype DiffLineSelectiontype SelectHandlertype SelectReasontype DiffScrolltype DiffDocumentControllertype DiffSnapshottype DiffViewStatetype DiffViewControllertype DiffViewOptionstype DiffViewApitype DiffHeighttype DiffViewProps

Accessibility

  • All files share one virtualized scroller and one tab stop; the focused line stays rendered when scrolled away.
  • It grows to the whole diff and scrolls with its scrolling ancestor, still virtualized; a --diff-max-height the page sets caps it. height="fill" fills a sized parent instead.

Agent actions

Same actions as GitDiff; a controller calls them from your own buttons.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.