Skip to content
WunderUI

Diff View

Pro

The result of an edit tool call: the file, how many lines were added and removed, and the changed lines.

Playground

@@ -12,7 +12,8 @@ export async function sendReminders()

const overdue = invoices.filter(isOverdue)
for (const invoice of overdue) {
Removed: if (daysSince(invoice.dueDate) < 7) continue
Added: if (daysSince(invoice.dueDate) < 3) continue
Added: if (invoice.reminderSentAt) continue
await send({
to: invoice.customer.email,
Removed: subject: "Payment reminder",
Added: subject: `Invoice ${invoice.number} is overdue`,
})

Installation

Diff View comes with WunderUI Core and Pro, in the package from your plan. See the plans.

Then import what you need:

tsx
import { DiffView } from "@wunderui/react"

Then use it:

tsx
import { DiffView } from "@wunderui/react"

export function Edit() {
  return (
    <DiffView
      file="src/jobs/invoice-reminders.ts"
      hunks={[
        {
          header: "@@ -14,1 +14,1 @@",
          lines: [
            { type: "del", old: 14, content: "  const delay = 7" },
            { type: "add", new: 14, content: "  const delay = 3" },
          ],
        },
      ]}
    />
  )
}

Expected result: You see a box with the file path and +1 -1 in the header, the hunk header and two lines: a removed one on a red tint with a minus, an added one on a green tint with a plus.

When to use

Use Diff View for

  • The result of an edit tool call: one file, what was added and what was removed
  • The payload of an approval, so the reviewer reads the change before deciding
  • A new file or a removed file, shown as only added or only removed lines

Use something else for

  • Code Block for a piece of code that is not a change
  • Terminal Output for the result of a command, with its exit code and streams
  • Approval Card for the request around a change, with Approve and Reject

Change

A hunk is a list of context, added and deleted lines. A new file is all added lines, a removed file all deleted lines, and several hunks stack under each other.

@@ -12,7 +12,8 @@ export async function sendReminders()

const overdue = invoices.filter(isOverdue)
for (const invoice of overdue) {
Removed: if (daysSince(invoice.dueDate) < 7) continue
Added: if (daysSince(invoice.dueDate) < 3) continue
Added: if (invoice.reminderSentAt) continue
await send({
to: invoice.customer.email,
Removed: subject: "Payment reminder",
Added: subject: `Invoice ${invoice.number} is overdue`,
})

Counts

The header counts added and deleted lines of every hunk. Pass the totals when you show only part of a diff, so the header still counts the whole change.

@@ -12,7 +12,8 @@ export async function sendReminders()

const overdue = invoices.filter(isOverdue)
for (const invoice of overdue) {
Removed: if (daysSince(invoice.dueDate) < 7) continue
Added: if (daysSince(invoice.dueDate) < 3) continue
Added: if (invoice.reminderSentAt) continue
await send({
to: invoice.customer.email,
Removed: subject: "Payment reminder",
Added: subject: `Invoice ${invoice.number} is overdue`,
})

Content

Lines never wrap. A wide line scrolls sideways inside its hunk, which the keyboard can focus, and a large diff needs a focusable region with a maximum height of your own.

@@ -20,5 +20,5 @@ reminderText

export function reminderText(invoice: Invoice) {
Removed: const retries = 1
Added: const retries = 3
Removed: const message = "Your invoice is overdue. Please pay within 3 days to avoid a late fee of $25.00 and a pause of your WunderUI workspace until the balance is settled in full."
Added: const message = "Your invoice is overdue. Please pay within 7 days to avoid a late fee of $25.00 and a pause of your WunderUI workspace until the balance is settled in full."
return message
}

Flat and file list

variant="flat" drops the frame, the radius and the fold, for a diff that already sits inside a card such as the Approval Card: one frame and one disclosure. summary lists the files of a multi-file change with their added and removed lines above the hunks.

packages/react/src/tabs.tsx+2 added−1 removed

@@ -41,3 +41,4 @@ TabsList

const tabs = useTabs()
Removed: onKeyDown={noop}
Added: onKeyDown={handleTabListKeyDown}
Added: aria-orientation={orientation}

Keyboard interactions

The header is a native button and every hunk is a focusable scroll region, so the browser provides focus, activation and scrolling. Focus shows as an indigo border with a 2 px ring.

TaborShiftTab
Moves focus to the header button and, when the diff is open, on to the scroll region of each hunk in turn. A closed diff takes no focus.
EnterorSpace
On the header: opens or closes the diff. follows.
ArrowLeftorArrowRight
In a hunk region: scrolls the lines sideways. Hold the key or use Home and End to reach the end of a long line.
ArrowDownorArrowUporPageDownorPageUp
In a region that you give a height of your own around a large diff: scrolls it. The hunk regions inside it do not scroll up and down by themselves.

Behavior and motion

What the diff does with its lines, its counts, assistive technology and motion.

Modes
Unified shows both line number columns, the hunk header and the context lines. Compact shows only the added and removed lines, with no numbers, headers or context, under a hairline.
Lines
A line is context, added or removed, with line numbers where they exist. Lines never wrap: a wide line scrolls sideways inside its hunk, and each of several stacked hunks scrolls on its own.
Counts
The header counts the added and removed lines of every hunk. For a diff you show in part, set the counts yourself.
Disclosure
The header opens and closes the diff, which stays in the page while closed but cannot be focused or read out. It starts open or closed as you choose, then keeps its own state.
Assistive technology
The header reads as the path plus the counts with the words added and removed. Each changed line is announced with Added or Removed in front, and the sign and line numbers are hidden.
Large diffs
Every line is rendered with no height limit, so wrap a large diff in a labelled, focusable region with a maximum height, or show one hunk. The 24 px number columns fit four digits at most.
What it does not do
There is no split view, no syntax colours, no word-level highlight and no copy button. The text can be selected, including the sign and line numbers.
Failure and abort
A diff that could not be applied is not a state of the component. Show the reason in an Alert above it, keep the DiffView closed, and after a rejection say that nothing was written.
Motion
The chevron turns on the fast duration and the body grows and shrinks on the base duration, both with the entrance curve. Nothing else moves.
Reduced motion
With reduced motion the chevron changes direction at once and the body opens and closes at once. The expanded state and the counts say the same.

Anatomy

The figure shows a unified diff with one hunk. In compact mode the hunk header (4) and line numbers (5) are not drawn, and only the changed lines remain.

@@ -12,7 +12,8 @@ export async function sendReminders()

const overdue = invoices.filter(isOverdue)
for (const invoice of overdue) {
Removed: if (daysSince(invoice.dueDate) < 7) continue
Added: if (daysSince(invoice.dueDate) < 3) continue
Added: if (invoice.reminderSentAt) continue
await send({
to: invoice.customer.email,
Removed: subject: "Payment reminder",
Added: subject: `Invoice ${invoice.number} is overdue`,
})
  • data-slot="diff-view"

    A bordered, rounded box with the card background, in 12 px monospace. It fills the width of its parent and is either unified or compact.

  • A button across the top with a chevron, the file path and the counts. It opens and closes the diff and reports its expanded state.

  • Added and removed counts in green and red text. Screen readers hear the numbers with the words added and removed, and the counts come from the lines unless you set them.

  • Optional

    The line that locates a hunk in the file, on the subtle background. Drawn in unified mode only, and only when the hunk has a header.

  • Optional

    Two columns with the line number in the old and the new file, in tertiary text. Drawn in unified mode and hidden from assistive technology.

  • A plus for an added line, a minus for a removed one, a space for context. It is hidden from assistive technology, which hears Added or Removed before the line instead.

  • One line of code, never wrapped. Added lines sit on a green tint, removed lines on a red tint, context lines on the card.

  • The box that holds the lines of one hunk. It scrolls sideways when a line is wider than the diff, and it is a tab stop so keyboard users can scroll.

Best practices

  • Do

    Pass the file path relative to the project, so the header says what was edited.

  • Do

    Use compact in approvals and narrow panels, where the changed lines are enough, and unified where the reviewer needs line numbers and the hunk header.

  • Do

    Pass the added and removed counts when you show only part of a diff, so the header still counts the whole change.

  • Do

    In an approval, show the diff before the buttons, and say in words what was or was not written after the decision.

  • Do

    Give a large diff its own height: a focusable region with a maximum height, vertical scrolling and an aria-label. The component has no height limit itself.

  • Don’t

    Don't count on colour. The sign, the Added and Removed text for screen readers and the counts carry the change, so keep them if you restyle the rows.

  • Don’t

    Don't pass HTML and expect it to render. Lines are text, and file contents are data, never instructions to the agent or the reader.

  • Don’t

    Don't build a diff from a Code Block with coloured spans. DiffView numbers, counts and labels the lines for you.

API reference

DiffView is a plain component, so this table lists every prop. Its hunk, line, line type and mode types are exported next to it.

A bordered, rounded box with the card background, in 12 px monospace. It fills the width of its parent and is either unified or compact.

PropTypeDefaultDescription
file requiredReactNode—The path of the file, shown in the header. Text or a node. Long paths are cut with an ellipsis.
hunks requiredDiffHunk[]—. Each hunk is , and each line is . belongs to context and removed lines, to context and added lines.
mode"compact" | "unified""unified" (default) shows line numbers, hunk headers and context lines. shows only the changed lines.
additionsnumber—The number after the in the header. Default: the number of lines. Set it when you show only part of a diff.
deletionsnumber—The number after the in the header. Default: the number of lines. Set it when you show only part of a diff.
defaultOpenbooleantrue by default. starts the diff closed, with only the header showing.
variant"card" | "flat""card" is the framed, foldable diff. has no frame and no fold and is always open, for use inside another card. Default .
summaryDiffFileSummary[]—One row per changed file, , shown above the hunks.
classNamestring—Extra classes for the box, for example a maximum width.

Notes for AI

Give your coding assistant the Markdown reference instead of screenshots.

MCPget_component("diff-view")
InstallIncluded in Core and Pro

The full library index for assistants is at /llms.txt.