|
1 | 1 | # react-virtualized-diff |
2 | 2 |
|
3 | | -A high-performance, virtualized React diff viewer designed for **very large text files** and smooth developer experience. |
| 3 | +High-performance React diff viewer for **large text/code files** with virtualized rendering. |
4 | 4 |
|
5 | | -> Package name on npm: **`react-virtualized-diff`** |
| 5 | +- 📦 npm: [`react-virtualized-diff`](https://www.npmjs.com/package/react-virtualized-diff) |
| 6 | +- 🌐 Live Demo: https://www.zhangjiahang.com/react-virtualized-diff |
| 7 | +- 📊 Benchmark report: [benchmark-results/results.md](./benchmark-results/results.md) |
| 8 | +- 🇨🇳 中文文档: [README.zh-CN.md](./README.zh-CN.md) |
6 | 9 |
|
7 | | -[中文文档(Chinese README)](./README.zh-CN.md) |
| 10 | +## Why react-virtualized-diff |
8 | 11 |
|
9 | | ---- |
| 12 | +Most diff components are smooth for small files, but degrade heavily with 10k+ lines. |
10 | 13 |
|
11 | | -## Why this project |
| 14 | +`react-virtualized-diff` is built for: |
12 | 15 |
|
13 | | -Most diff viewers are good for small files but become slow when input grows to tens of thousands of lines. |
14 | | - |
15 | | -`react-virtualized-diff` focuses on: |
16 | | - |
17 | | -- **Performance first** rendering with virtualization |
18 | | -- **Readable side-by-side UI** for code/text review |
19 | | -- **Configurable context lines** around changes |
20 | | -- **TypeScript support** for reliable integration |
21 | | -- **Simple React API** for quick adoption |
22 | | - |
23 | | ---- |
24 | | - |
25 | | -## Features |
26 | | - |
27 | | -- ✅ Side-by-side diff layout |
28 | | -- ✅ Virtualized row rendering (good for large files) |
29 | | -- ✅ Collapsed unchanged blocks with configurable context |
30 | | -- ✅ Lightweight integration in React apps |
31 | | -- ✅ TypeScript declarations out of the box |
32 | | - |
33 | | ---- |
| 16 | +- **Virtualized rendering** for big-file performance |
| 17 | +- **Side-by-side layout** for easy review |
| 18 | +- **Collapsed unchanged blocks** with configurable context |
| 19 | +- **TypeScript support** for predictable integration |
34 | 20 |
|
35 | 21 | ## Installation |
36 | 22 |
|
37 | 23 | ```bash |
38 | | -# pnpm |
39 | 24 | pnpm add react-virtualized-diff |
40 | | - |
41 | | -# npm |
42 | | -npm install react-virtualized-diff |
43 | | - |
44 | | -# yarn |
45 | | -yarn add react-virtualized-diff |
| 25 | +# or npm i react-virtualized-diff |
| 26 | +# or yarn add react-virtualized-diff |
46 | 27 | ``` |
47 | 28 |
|
48 | | ---- |
49 | | - |
50 | | -## Quick start |
| 29 | +## Quick Start |
51 | 30 |
|
52 | 31 | ```tsx |
53 | 32 | import { DiffViewer } from 'react-virtualized-diff'; |
54 | 33 |
|
55 | | -const oldText = `line 1\nline 2\nline 3`; |
56 | | -const newText = `line 1\nline 2 changed\nline 3\nline 4`; |
| 34 | +const original = `line 1\nline 2\nline 3`; |
| 35 | +const modified = `line 1\nline 2 changed\nline 3\nline 4`; |
57 | 36 |
|
58 | | -export function Example() { |
| 37 | +export function App() { |
59 | 38 | return ( |
60 | 39 | <DiffViewer |
61 | | - original={oldText} |
62 | | - modified={newText} |
| 40 | + original={original} |
| 41 | + modified={modified} |
63 | 42 | contextLines={2} |
64 | 43 | height={480} |
65 | 44 | /> |
66 | 45 | ); |
67 | 46 | } |
68 | 47 | ``` |
69 | 48 |
|
70 | | ---- |
| 49 | +## API |
71 | 50 |
|
72 | | -## API (current) |
| 51 | +### `DiffViewer` |
73 | 52 |
|
74 | | -### `DiffViewer` props |
| 53 | +| Prop | Type | Default | Description | |
| 54 | +| --- | --- | --- | --- | |
| 55 | +| `original` | `string` | - | Original text content | |
| 56 | +| `modified` | `string` | - | Modified text content | |
| 57 | +| `contextLines` | `number` | `2` | Number of unchanged lines kept around diff hunks | |
| 58 | +| `height` | `number \| string` | `500` | Viewport height of the virtual list | |
| 59 | +| `locale` | `DiffViewerLocale` | - | UI text localization | |
| 60 | +| `language` | `string` | - | Reserved field for future language-related extensions | |
75 | 61 |
|
76 | | -- `original: string` – original text content |
77 | | -- `modified: string` – modified text content |
78 | | -- `contextLines?: number` – unchanged lines to keep around changes (default behavior from component) |
79 | | -- `height?: number | string` – viewport height for virtualization container |
| 62 | +### `DiffViewerLocale` |
80 | 63 |
|
81 | | -> Tip: for best performance with huge files, keep rendering area constrained with a fixed `height`. |
| 64 | +| Field | Type | Description | |
| 65 | +| --- | --- | --- | |
| 66 | +| `collapse` | `string` | Label for collapse button | |
| 67 | +| `showMoreLines` | `(count: number) => string` | Label factory for “show hidden lines” | |
82 | 68 |
|
83 | | ---- |
| 69 | +## Benchmark |
84 | 70 |
|
85 | | -## Benchmark suite |
| 71 | +Included benchmark compares: |
86 | 72 |
|
87 | | -A runnable benchmark harness is included to compare: |
88 | | - |
89 | | -- `react-virtualized-diff` (this project) |
| 73 | +- `react-virtualized-diff` |
90 | 74 | - `react-diff-viewer` |
91 | 75 | - `react-diff-viewer-continued` |
92 | 76 | - `react-diff-view` |
93 | 77 |
|
94 | | -Metrics collected for each dataset size (`1k / 10k / 50k / 100k` lines): |
| 78 | +Dataset sizes: `1k / 10k / 50k / 100k` lines. |
| 79 | + |
| 80 | +Metrics: |
95 | 81 |
|
96 | | -- FPS (average during auto-scroll) |
97 | | -- Initial render time (ms) |
98 | | -- Memory usage (`usedJSHeapSize` in Chromium) |
99 | | -- Per benchmark case timeout: `60000 ms` (timeout cases are recorded in results instead of failing the run) |
| 82 | +- FPS (during auto-scroll) |
| 83 | +- initial render time |
| 84 | +- memory usage (`usedJSHeapSize`) |
100 | 85 |
|
101 | | -Quick result highlights (from the latest run): |
| 86 | +Quick highlights from latest report: |
102 | 87 |
|
103 | | -- At **10k lines**, `react-virtualized-diff` keeps ~**60 FPS**, with **187.2 ms** initial render and **9.5 MB** memory. |
104 | | -- At **50k/100k lines**, `react-diff-viewer` and `react-diff-viewer-continued` hit timeout, while this project finishes both cases. |
105 | | -- At **100k lines**, this project uses **141.1 MB** memory vs `react-diff-view` at **1297.0 MB** (~9.2x lower), and keeps **60.4 FPS** vs **5.6 FPS**. |
| 88 | +- At `10k` lines: ~`60 FPS`, `187.2 ms` initial render, `9.5 MB` memory. |
| 89 | +- At `50k/100k` lines: `react-diff-viewer` and `react-diff-viewer-continued` timeout. |
| 90 | +- At `100k` lines: `141.1 MB` (`react-virtualized-diff`) vs `1297.0 MB` (`react-diff-view`). |
106 | 91 |
|
107 | | -Run: |
| 92 | +Run benchmark: |
108 | 93 |
|
109 | 94 | ```bash |
110 | 95 | pnpm install |
111 | 96 | pnpm benchmark |
112 | 97 | ``` |
113 | 98 |
|
114 | | -> If Playwright Chromium is missing, the script will auto-run `pnpm exec playwright install chromium` once. |
115 | | -
|
116 | | -> `react-diff-viewer-continued` is optional in the benchmark app. If missing locally, benchmark falls back to `react-diff-viewer` for that case. |
117 | | -
|
118 | | -Output files: |
119 | | - |
120 | | -- `benchmark-results/results.json` |
121 | | -- `benchmark-results/results.md` |
122 | | - |
123 | | -➡️ See detailed benchmark table: [benchmark-results/results.md](./benchmark-results/results.md) |
124 | | - |
125 | | -## Monorepo structure |
126 | | - |
127 | | -```text |
128 | | -apps/demo/ # Vite demo app |
129 | | -packages/react/ # npm package: react-virtualized-diff |
130 | | -``` |
131 | | - |
132 | | ---- |
| 99 | +## Demo |
133 | 100 |
|
134 | | -## Local development |
| 101 | +- Hosted demo page: https://www.zhangjiahang.com/react-virtualized-diff |
| 102 | +- Local demo: |
135 | 103 |
|
136 | 104 | ```bash |
137 | 105 | pnpm install |
138 | | -pnpm dev # run demo app |
139 | | -pnpm build # build workspace packages |
| 106 | +pnpm dev |
140 | 107 | ``` |
141 | 108 |
|
142 | | ---- |
143 | | - |
144 | | -## npm package README support |
145 | | - |
146 | | -To ensure npm users always see correct documentation: |
147 | | - |
148 | | -- Package-level README is maintained at `packages/react/README.md` |
149 | | -- `packages/react/package.json` includes README in publish files |
150 | | -- Root README links to the package docs and Chinese docs |
151 | | - |
152 | | ---- |
153 | | - |
154 | | -## Release log |
| 109 | +## Monorepo Structure |
155 | 110 |
|
156 | | -See [CHANGELOG.md](./CHANGELOG.md) for tracked releases and supported capabilities. |
157 | | - |
158 | | ---- |
159 | | - |
160 | | -## Future plan |
161 | | - |
162 | | -### Near-term roadmap |
163 | | - |
164 | | -- [ ] Optional syntax highlighting (performance-aware) |
165 | | -- [ ] More comprehensive live demo scenarios (big files, mixed edits) |
166 | | -- [ ] Public hosted demo site for quick evaluation |
167 | | -- [ ] Better customization hooks (line renderers, gutters) |
168 | | - |
169 | | -### Additional TODOs to make this project more popular |
| 111 | +```text |
| 112 | +apps/demo/ # Vite demo app |
| 113 | +apps/benchmark/ # benchmark app |
| 114 | +packages/react/ # npm package source |
| 115 | +``` |
170 | 116 |
|
171 | | -- [x] Detailed benchmark report vs common diff viewers |
172 | | -- [ ] Keyboard navigation + accessibility improvements |
173 | | -- [ ] Dark/light theme presets and design tokens |
174 | | -- [ ] SSR usage guide (Next.js / Remix examples) |
175 | | -- [ ] More real-world examples (JSON, logs, markdown, code) |
176 | | -- [ ] CI release automation + semantic versioning workflow |
177 | | -- [ ] Contribution guide and issue templates |
178 | | -- [ ] International docs beyond English/Chinese |
| 117 | +## Changelog |
179 | 118 |
|
180 | | ---- |
| 119 | +See [CHANGELOG.md](./CHANGELOG.md). |
181 | 120 |
|
182 | 121 | ## License |
183 | 122 |
|
|
0 commit comments