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
Installation
@lezer/common@1.5.5@lezer/highlight@1.2.5lucide-reactUsage
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
| Prop | Type | Default |
|---|---|---|
additionsrequired | number | – |
deletionsrequired | number | – |
labelsrequired | DiffLabels | – |
bar | boolean | true |
className | string | – |
FileChange
| Prop | Type | Default |
|---|---|---|
diffrequired | FileDiff | – |
labelsrequired | DiffLabels | – |
bar | boolean | true |
DiffView
| Prop | Type | Default |
|---|---|---|
labelsOverridable accessible names and the few visible words; pass a stable object (a constant). | DiffLabels | diffLabels |
className | string | – |
aria-label | string | – |
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 DiffViewPropsAccessibility
- 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.