Skip to the content

Diff

A code change, read line by line. Each file has a header with its path, its change kind and +N −N. Each line has its old and new number, a + or − sign and a green or red tint. Pass a unified diff as text (git diff, git format-patch, diff -u) or files you already parsed.
Data Display

When to use

Use when
  • A person reviews or approves a code or config change: a pull request, an approval gate, a deploy.
  • Showing what a run, a migration or a policy edit changed in a file.
Avoid when
  • Code that is not a change — use Text with fontFamily="code".
  • Comparing two records field by field — use a Table or a DescriptionList.
  • You need side-by-side review, word-level highlights or syntax colours — not supported.

Usage

src/limits.ts2 additions, 1 deletion
@@ -1,4 +1,5 @@ export const limits = {
retries: 3,
removed, patch: 20_000,
added, patch: 40_000,
added, signed: true,
timeout: 30,
docs/gates.md → docs/approval-gates.mdrenamed0 additions, 0 deletions
No line changes.
import { Diff } from '@apollion-dsi/core/data-display/diff';

<Diff patch={changes.patch} />;
  • Every file starts open; defaultCollapsed starts them closed. The header toggles the file (click, Enter or Space) and onFileToggle(file, open) reports it. A closed file renders no lines.
  • Binary files and files with no line changes (a rename, a mode change) show a short note instead of lines.

Long lines and long patches

  • Lines keep their shape and scroll sideways inside the file. wrap breaks long lines instead.
  • A file with more rows than virtualizeAbove (default 400) renders only the rows in view, inside a block maxHeight tall (default 32rem). Below the threshold every line is in the page, so in-page search finds it.
  • truncated adds a closing note when the source cut the patch; truncatedLabel replaces its text. A patch cut mid-hunk shows the lines up to the cut.
src/limits.ts2 additions, 1 deletion
@@ -1,4 +1,5 @@ export const limits = {
retries: 3,
removed, patch: 20_000,
added, patch: 40_000,
added, signed: true,
timeout: 30,
docs/gates.md → docs/approval-gates.mdrenamed0 additions, 0 deletions
No line changes.
The patch is cut here — the whole one is at runs/42/patch.diff
<Diff patch={changes.patch} truncated={changes.truncated} truncatedLabel={`The whole patch is at ${changes.path}`} />

Parsed files

parseUnifiedDiff(patch) returns the DiffFile[] the component draws. Use it to count files and lines with the same rules, or to parse on the server and pass files. It reads git headers, quoted paths, new and deleted files, renames, copies, mode changes, binary files and \ No newline at end of file, and it never throws.

import { Diff, parseUnifiedDiff } from '@apollion-dsi/core/data-display/diff';

const files = parseUnifiedDiff(changes.patch);
<Diff files={files} />;

Look

Colours live in the theme, never in className. The theme.component.diff tier sets added, removed and hunk (a palette and a tint amount), surface, header, code and gutter:

createTheme({
  component: {
    diff: {
      added: { color: 'success', tint: 0.3 },
      removed: { color: 'danger', tint: 0.3 },
      code: { fontSize: 'micro' },
    },
  },
});

Tints mix per mode, so one tier works in light and dark. When a tint would drop the line text under 4.5:1, it is pulled back toward the ground until it passes. Signs, counts and line numbers reach 4.5:1 too.

Accessibility

  • Never colour only: changed lines show + / −, and screen readers hear "added" or "removed" before the text. Line numbers and signs are hidden from them.
  • Each file's code is a focusable region named by its path, so a keyboard user can scroll it sideways.
  • The header reads its counts in words ("2 additions, 1 deletion").
  • Every string has an English default; labels replaces any of them.

Properties

Beyond the props above, the component accepts the native <div> attributes (id, aria-*, data-*).

See also