Diffs Component Guide

· 397 words

This guide documents every component in the diffs integration built on @pierre/diffs. All components are React islands hydrated via client:visible — JS loads only when you scroll to them.


DiffViewer

Compare two versions of a file. The main workhorse component.

PropTypeDefaultDescription
oldCodestringrequiredThe original file contents
newCodestringrequiredThe modified file contents
filenamestringrequiredDisplay filename (also sets syntax language)
languagestring"typescript"Override the Shiki language
diffStyle"split" | "unified""unified"Side-by-side or stacked layout
diffIndicators"bars" | "classic" | "none""bars"Change indicator style
lineDiffType"word" | "word-alt" | "char" | "none""word"Inline diff granularity
disableBackgroundbooleanfalseRemove addition/deletion background colors
wrapLinesbooleanfalseWrap long lines instead of scrolling
disableLineNumbersbooleanfalseHide line numbers
hunkSeparator"line-info" | "line-info-basic" | "metadata" | "simple""line-info"Style for collapsed unchanged regions
collapsedbooleanfalseStart with body hidden (click header to expand)
copyablebooleanfalseShow a copy-to-clipboard button in the header
renderHeaderMetadata(fileDiff) => ReactNodeCustom header metadata (right side)
renderCustomHeader(fileDiff) => ReactNodeReplace the entire header

Split layout (with copy button)

Unified layout

Change indicator styles

Bars (default)

Classic (+/–)

None (with background disabled)

Inline diff granularity

Word-level (default)

Character-level

Line wrapping

Disabled line numbers

Hunk separators

Control how collapsed unchanged regions between hunks are displayed.

ValueDescription
"line-info"Full-width separator with collapsed line count and expand controls
"line-info-basic"Compact variant of line-info
"metadata"Patch-style @@ -x,y +a,b @@ header
"simple"Minimal separator bar

Line Info (default)

Metadata (patch-style)

Simple

Collapsed diff

Set collapsed to start with only the header visible. Use the chevron button (▼) in the header to expand/collapse.


CodeViewer

Display a single file with syntax highlighting. No diff — just code.

PropTypeDefaultDescription
codestringrequiredThe file contents
filenamestringrequiredDisplay filename (also sets syntax language)
languagestring"typescript"Override the Shiki language
wrapLinesbooleanfalseWrap long lines instead of scrolling
showLineNumbersbooleantrueShow line numbers
copyablebooleanfalseShow a copy-to-clipboard button in the header

With copy button

CSS file

No line numbers, wrapping enabled


MergeConflict

Render a file with conflict markers. Each conflict block gets Accept Current, Accept Incoming, and Accept Both buttons.

PropTypeDefaultDescription
fileContentsstringrequiredFile contents with <<<<<<<, =======, >>>>>>> markers
filenamestringrequiredDisplay filename
languagestring"typescript"Override the Shiki language

The component is uncontrolled — the library manages resolution state internally. To reset (restore original conflicts), remount the component by changing its React key.

Multiple conflicts


AcceptRejectDiff

A diff where each hunk has accept/reject controls. Manages its own state — accepting collapses hunks to context lines, rejecting restores the original.

PropTypeDefaultDescription
oldCodestringrequiredThe original file contents
newCodestringrequiredThe modified file contents
filenamestringrequiredDisplay filename
languagestring"typescript"Override the Shiki language
diffStyle"split" | "unified""unified"Layout style

The toolbar provides Accept / Reject per hunk, plus Undo (reverts last action) and Reset (restores all hunks).

Split layout


DiffPlayground

Two editable text areas plus a live-updating diff below. Edit either pane and the diff recalculates in real time.

PropTypeDefaultDescription
defaultOldCodestringrequiredInitial “before” contents
defaultNewCodestringrequiredInitial “after” contents
oldFilenamestring"before"Label for the left editor
newFilenamestring"after"Label for the right editor
languagestring"css"Shiki language for syntax highlighting
diffStyle"split" | "unified""unified"Layout for the diff view

TypeScript example