diff --git a/CHANGELOG.md b/CHANGELOG.md index cb5482a..70cfbc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file. The format is based on Keep a Changelog, and this project follows Semantic Versioning. +## [0.1.4] - 2026-04-07 + +### Added + +- Published hosted demo page: https://www.zhangjiahang.com/react-virtualized-diff. + +### Changed + +- Bumped workspace package versions to `0.1.4` for the release. +- Reworked both English and Chinese README documents with clearer, search-friendly structure. +- Promoted API, benchmark, and demo sections for faster discovery by humans and AI crawlers. + ## [0.1.3] - 2026-04-07 ### Added diff --git a/README.md b/README.md index cb866b0..79559a4 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,44 @@ # react-virtualized-diff -A high-performance, virtualized React diff viewer designed for **very large text files** and smooth developer experience. +High-performance React diff viewer for **large text/code files** with virtualized rendering. -> Package name on npm: **`react-virtualized-diff`** +- 📦 npm: [`react-virtualized-diff`](https://www.npmjs.com/package/react-virtualized-diff) +- 🌐 Live Demo: https://www.zhangjiahang.com/react-virtualized-diff +- 📊 Benchmark report: [benchmark-results/results.md](./benchmark-results/results.md) +- 🇨🇳 中文文档: [README.zh-CN.md](./README.zh-CN.md) -[中文文档(Chinese README)](./README.zh-CN.md) +## Why react-virtualized-diff ---- +Most diff components are smooth for small files, but degrade heavily with 10k+ lines. -## Why this project +`react-virtualized-diff` is built for: -Most diff viewers are good for small files but become slow when input grows to tens of thousands of lines. - -`react-virtualized-diff` focuses on: - -- **Performance first** rendering with virtualization -- **Readable side-by-side UI** for code/text review -- **Configurable context lines** around changes -- **TypeScript support** for reliable integration -- **Simple React API** for quick adoption - ---- - -## Features - -- ✅ Side-by-side diff layout -- ✅ Virtualized row rendering (good for large files) -- ✅ Collapsed unchanged blocks with configurable context -- ✅ Lightweight integration in React apps -- ✅ TypeScript declarations out of the box - ---- +- **Virtualized rendering** for big-file performance +- **Side-by-side layout** for easy review +- **Collapsed unchanged blocks** with configurable context +- **TypeScript support** for predictable integration ## Installation ```bash -# pnpm pnpm add react-virtualized-diff - -# npm -npm install react-virtualized-diff - -# yarn -yarn add react-virtualized-diff +# or npm i react-virtualized-diff +# or yarn add react-virtualized-diff ``` ---- - -## Quick start +## Quick Start ```tsx import { DiffViewer } from 'react-virtualized-diff'; -const oldText = `line 1\nline 2\nline 3`; -const newText = `line 1\nline 2 changed\nline 3\nline 4`; +const original = `line 1\nline 2\nline 3`; +const modified = `line 1\nline 2 changed\nline 3\nline 4`; -export function Example() { +export function App() { return ( @@ -67,117 +46,77 @@ export function Example() { } ``` ---- +## API -## API (current) +### `DiffViewer` -### `DiffViewer` props +| Prop | Type | Default | Description | +| --- | --- | --- | --- | +| `original` | `string` | - | Original text content | +| `modified` | `string` | - | Modified text content | +| `contextLines` | `number` | `2` | Number of unchanged lines kept around diff hunks | +| `height` | `number \| string` | `500` | Viewport height of the virtual list | +| `locale` | `DiffViewerLocale` | - | UI text localization | +| `language` | `string` | - | Reserved field for future language-related extensions | -- `original: string` – original text content -- `modified: string` – modified text content -- `contextLines?: number` – unchanged lines to keep around changes (default behavior from component) -- `height?: number | string` – viewport height for virtualization container +### `DiffViewerLocale` -> Tip: for best performance with huge files, keep rendering area constrained with a fixed `height`. +| Field | Type | Description | +| --- | --- | --- | +| `collapse` | `string` | Label for collapse button | +| `showMoreLines` | `(count: number) => string` | Label factory for “show hidden lines” | ---- +## Benchmark -## Benchmark suite +Included benchmark compares: -A runnable benchmark harness is included to compare: - -- `react-virtualized-diff` (this project) +- `react-virtualized-diff` - `react-diff-viewer` - `react-diff-viewer-continued` - `react-diff-view` -Metrics collected for each dataset size (`1k / 10k / 50k / 100k` lines): +Dataset sizes: `1k / 10k / 50k / 100k` lines. + +Metrics: -- FPS (average during auto-scroll) -- Initial render time (ms) -- Memory usage (`usedJSHeapSize` in Chromium) -- Per benchmark case timeout: `60000 ms` (timeout cases are recorded in results instead of failing the run) +- FPS (during auto-scroll) +- initial render time +- memory usage (`usedJSHeapSize`) -Quick result highlights (from the latest run): +Quick highlights from latest report: -- At **10k lines**, `react-virtualized-diff` keeps ~**60 FPS**, with **187.2 ms** initial render and **9.5 MB** memory. -- At **50k/100k lines**, `react-diff-viewer` and `react-diff-viewer-continued` hit timeout, while this project finishes both cases. -- 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**. +- At `10k` lines: ~`60 FPS`, `187.2 ms` initial render, `9.5 MB` memory. +- At `50k/100k` lines: `react-diff-viewer` and `react-diff-viewer-continued` timeout. +- At `100k` lines: `141.1 MB` (`react-virtualized-diff`) vs `1297.0 MB` (`react-diff-view`). -Run: +Run benchmark: ```bash pnpm install pnpm benchmark ``` -> If Playwright Chromium is missing, the script will auto-run `pnpm exec playwright install chromium` once. - -> `react-diff-viewer-continued` is optional in the benchmark app. If missing locally, benchmark falls back to `react-diff-viewer` for that case. - -Output files: - -- `benchmark-results/results.json` -- `benchmark-results/results.md` - -➡️ See detailed benchmark table: [benchmark-results/results.md](./benchmark-results/results.md) - -## Monorepo structure - -```text -apps/demo/ # Vite demo app -packages/react/ # npm package: react-virtualized-diff -``` - ---- +## Demo -## Local development +- Hosted demo page: https://www.zhangjiahang.com/react-virtualized-diff +- Local demo: ```bash pnpm install -pnpm dev # run demo app -pnpm build # build workspace packages +pnpm dev ``` ---- - -## npm package README support - -To ensure npm users always see correct documentation: - -- Package-level README is maintained at `packages/react/README.md` -- `packages/react/package.json` includes README in publish files -- Root README links to the package docs and Chinese docs - ---- - -## Release log +## Monorepo Structure -See [CHANGELOG.md](./CHANGELOG.md) for tracked releases and supported capabilities. - ---- - -## Future plan - -### Near-term roadmap - -- [ ] Optional syntax highlighting (performance-aware) -- [ ] More comprehensive live demo scenarios (big files, mixed edits) -- [ ] Public hosted demo site for quick evaluation -- [ ] Better customization hooks (line renderers, gutters) - -### Additional TODOs to make this project more popular +```text +apps/demo/ # Vite demo app +apps/benchmark/ # benchmark app +packages/react/ # npm package source +``` -- [x] Detailed benchmark report vs common diff viewers -- [ ] Keyboard navigation + accessibility improvements -- [ ] Dark/light theme presets and design tokens -- [ ] SSR usage guide (Next.js / Remix examples) -- [ ] More real-world examples (JSON, logs, markdown, code) -- [ ] CI release automation + semantic versioning workflow -- [ ] Contribution guide and issue templates -- [ ] International docs beyond English/Chinese +## Changelog ---- +See [CHANGELOG.md](./CHANGELOG.md). ## License diff --git a/README.zh-CN.md b/README.zh-CN.md index 0999e12..a68157d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,64 +1,44 @@ # react-virtualized-diff -一个面向**超大文本文件**场景的高性能 React 差异对比组件(虚拟滚动渲染)。 +面向**大体量文本/代码文件**的高性能 React Diff 组件(虚拟滚动渲染)。 -> npm 包名:**`react-virtualized-diff`** +- 📦 npm:[`react-virtualized-diff`](https://www.npmjs.com/package/react-virtualized-diff) +- 🌐 在线 Demo:https://www.zhangjiahang.com/react-virtualized-diff +- 📊 Benchmark 报告:[benchmark-results/results.md](./benchmark-results/results.md) +- 🇬🇧 English README:[README.md](./README.md) -[English README](./README.md) +## 为什么做这个库 ---- +很多 diff 组件在小文件场景表现不错,但在 `10k+` 行后会出现明显卡顿。 -## 项目定位 +`react-virtualized-diff` 重点是: -很多 diff 组件在小文件场景表现不错,但面对数万行甚至十万行文本时,渲染和交互会明显变慢。 - -`react-virtualized-diff` 的目标是: - -- **性能优先**:通过虚拟列表减少 DOM 压力 -- **可读性优先**:清晰的左右对比视图 -- **可配置性**:支持上下文折叠行数配置 -- **工程可用性**:TypeScript 友好、接入简单 - ---- - -## 功能特性 - -- ✅ 左右并排差异视图 -- ✅ 虚拟化渲染(适合大文件) -- ✅ 未变化区块折叠 + 上下文行 -- ✅ React 项目快速接入 -- ✅ 开箱即用 TypeScript 类型定义 - ---- +- **虚拟化渲染**,优先保证大文件性能 +- **左右并排视图**,提升代码审阅效率 +- **可折叠未变更区块**,支持上下文行配置 +- **TypeScript 友好**,接入稳定 ## 安装 ```bash -# pnpm pnpm add react-virtualized-diff - -# npm -npm install react-virtualized-diff - -# yarn -yarn add react-virtualized-diff +# 或 npm i react-virtualized-diff +# 或 yarn add react-virtualized-diff ``` ---- - ## 快速开始 ```tsx import { DiffViewer } from 'react-virtualized-diff'; -const oldText = `line 1\nline 2\nline 3`; -const newText = `line 1\nline 2 changed\nline 3\nline 4`; +const original = `line 1\nline 2\nline 3`; +const modified = `line 1\nline 2 changed\nline 3\nline 4`; -export function Example() { +export function App() { return ( @@ -66,33 +46,48 @@ export function Example() { } ``` ---- +## API -## 当前 API +### `DiffViewer` -### `DiffViewer` 属性 +| 属性 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `original` | `string` | - | 原始文本 | +| `modified` | `string` | - | 修改后文本 | +| `contextLines` | `number` | `2` | 每个变更块周围保留的未变更行数 | +| `height` | `number \| string` | `500` | 虚拟列表可视区域高度 | +| `locale` | `DiffViewerLocale` | - | 组件文案本地化 | +| `language` | `string` | - | 预留字段(未来语言相关扩展) | -- `original: string`:原始文本 -- `modified: string`:修改后文本 -- `contextLines?: number`:变化块周围保留的上下文行数 -- `height?: number | string`:组件容器高度(建议固定高度以获得更好性能) +### `DiffViewerLocale` ---- +| 字段 | 类型 | 说明 | +| --- | --- | --- | +| `collapse` | `string` | “收起”按钮文案 | +| `showMoreLines` | `(count: number) => string` | “展开隐藏行”文案生成函数 | ## Benchmark(性能基准) -我们提供了可运行的 benchmark,对比以下组件: +内置 benchmark 对比: -- `react-virtualized-diff`(本项目) +- `react-virtualized-diff` - `react-diff-viewer` - `react-diff-viewer-continued` - `react-diff-view` +数据规模:`1k / 10k / 50k / 100k` 行。 + +观测指标: + +- FPS(自动滚动过程) +- 首次渲染时间 +- 内存占用(`usedJSHeapSize`) + 最新结果亮点: -- **10k 行**:本项目保持约 **60 FPS**,首屏渲染 **187.2 ms**,内存 **9.5 MB**。 -- **50k / 100k 行**:`react-diff-viewer` 与 `react-diff-viewer-continued` 在 `60000 ms` 超时限制内未完成。 -- **100k 行**:本项目内存 **141.1 MB**,而 `react-diff-view` 为 **1297.0 MB**(约 **9.2 倍**差距);FPS 分别为 **60.4 vs 5.6**。 +- `10k` 行:约 `60 FPS`,首渲染 `187.2 ms`,内存 `9.5 MB`。 +- `50k/100k` 行:`react-diff-viewer` 与 `react-diff-viewer-continued` 超时。 +- `100k` 行:本库 `141.1 MB`,`react-diff-view` 为 `1297.0 MB`。 运行方式: @@ -101,67 +96,28 @@ pnpm install pnpm benchmark ``` -详细结果请查看:[`benchmark-results/results.md`](./benchmark-results/results.md) - ---- - -## 仓库结构 - -```text -apps/demo/ # Vite 演示项目 -packages/react/ # npm 包:react-virtualized-diff -``` - ---- +## Demo -## 本地开发 +- 在线体验:https://www.zhangjiahang.com/react-virtualized-diff +- 本地运行: ```bash pnpm install pnpm dev -pnpm build ``` ---- - -## npm 包 README 支持说明 - -为确保 npm 页面文档可用: - -- 在 `packages/react/README.md` 维护包级说明 -- 在 `packages/react/package.json` 发布文件中包含 README -- 根目录 README 与中文文档互相链接 +## 仓库结构 ---- +```text +apps/demo/ # Vite 演示应用 +apps/benchmark/ # benchmark 应用 +packages/react/ # npm 包源码 +``` -## 版本发布记录 +## 版本记录 详见 [CHANGELOG.md](./CHANGELOG.md)。 ---- - -## 后续规划 - -### 近期路线 - -- [ ] 可选语法高亮(性能优先设计) -- [ ] 更完整的在线 Demo 场景(超大文件、复杂编辑) -- [ ] 托管在线示例站点,方便快速体验 -- [ ] 更强的自定义能力(行渲染、gutter 等) - -### 可提升项目影响力的 TODO - -- [x] 与主流 diff 组件的基准测试报告 -- [ ] 键盘导航与无障碍增强 -- [ ] 深色/浅色主题预设 -- [ ] SSR 集成文档(Next.js / Remix) -- [ ] 更多真实场景示例(JSON、日志、Markdown、代码) -- [ ] CI 自动发布与语义化版本流程 -- [ ] 完善贡献指南与 issue 模板 -- [ ] 扩展多语言文档 - ---- - -## 许可证 +## License MIT diff --git a/apps/benchmark/package.json b/apps/benchmark/package.json index 24db627..8ad144b 100644 --- a/apps/benchmark/package.json +++ b/apps/benchmark/package.json @@ -1,7 +1,7 @@ { "name": "benchmark-app", "private": true, - "version": "0.0.0", + "version": "0.1.4", "type": "module", "scripts": { "dev": "vite", diff --git a/apps/demo/package.json b/apps/demo/package.json index 6843de5..60e7ad7 100644 --- a/apps/demo/package.json +++ b/apps/demo/package.json @@ -1,7 +1,7 @@ { "name": "demo", "private": true, - "version": "0.0.0", + "version": "0.1.4", "type": "module", "scripts": { "dev": "vite", @@ -21,4 +21,4 @@ "typescript": "^5.6.0", "vite": "^5.4.0" } -} \ No newline at end of file +} diff --git a/packages/react/README.md b/packages/react/README.md index 72c98ec..6b80e5b 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -1,181 +1,51 @@ # react-virtualized-diff -A high-performance, virtualized React diff viewer designed for **very large text files** and smooth developer experience. +High-performance React diff viewer with virtualization for large text/code files. -> Package name on npm: **`react-virtualized-diff`** +- Demo: https://www.zhangjiahang.com/react-virtualized-diff +- Changelog: https://github.com/Zhang-JiahangH/react-virtualized-diff/blob/main/CHANGELOG.md +- Benchmark: https://github.com/Zhang-JiahangH/react-virtualized-diff/blob/main/benchmark-results/results.md ---- - -## Why this project - -Most diff viewers are good for small files but become slow when input grows to tens of thousands of lines. - -`react-virtualized-diff` focuses on: - -- **Performance first** rendering with virtualization -- **Readable side-by-side UI** for code/text review -- **Configurable context lines** around changes -- **TypeScript support** for reliable integration -- **Simple React API** for quick adoption - ---- - -## Features - -- ✅ Side-by-side diff layout -- ✅ Virtualized row rendering (good for large files) -- ✅ Collapsed unchanged blocks with configurable context -- ✅ Lightweight integration in React apps -- ✅ TypeScript declarations out of the box - ---- - -## Installation +## Install ```bash -# pnpm pnpm add react-virtualized-diff - -# npm -npm install react-virtualized-diff - -# yarn -yarn add react-virtualized-diff +# or npm i react-virtualized-diff +# or yarn add react-virtualized-diff ``` ---- - -## Quick start +## Usage ```tsx import { DiffViewer } from 'react-virtualized-diff'; -const oldText = `line 1\nline 2\nline 3`; -const newText = `line 1\nline 2 changed\nline 3\nline 4`; - -export function Example() { +export function App() { return ( ); } ``` ---- - -## API (current) +## API ### `DiffViewer` props -- `original: string` – original text content -- `modified: string` – modified text content -- `contextLines?: number` – unchanged lines to keep around changes (default behavior from component) -- `height?: number | string` – viewport height for virtualization container - -> Tip: for best performance with huge files, keep rendering area constrained with a fixed `height`. - ---- - -## Benchmark suite - -A runnable benchmark harness is included to compare: - -- `react-virtualized-diff` (this project) -- `react-diff-viewer` -- `react-diff-viewer-continued` -- `react-diff-view` - -Metrics collected for each dataset size (`1k / 10k / 50k / 100k` lines): - -- FPS (average during auto-scroll) -- Initial render time (ms) -- Memory usage (`usedJSHeapSize` in Chromium) -- Per benchmark case timeout: `60000 ms` (timeout cases are recorded in results instead of failing the run) - -Quick result highlights (from the latest run): - -- At **10k lines**, `react-virtualized-diff` keeps ~**60 FPS**, with **187.2 ms** initial render and **9.5 MB** memory. -- At **50k/100k lines**, `react-diff-viewer` and `react-diff-viewer-continued` hit timeout, while this project finishes both cases. -- 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**. - -Run: - -```bash -pnpm install -pnpm benchmark -``` - -> If Playwright Chromium is missing, the script will auto-run `pnpm exec playwright install chromium` once. - -> `react-diff-viewer-continued` is optional in the benchmark app. If missing locally, benchmark falls back to `react-diff-viewer` for that case. - -Output files: - -- `benchmark-results/results.json` -- `benchmark-results/results.md` - -➡️ See detailed benchmark table: [benchmark-results/results.md](https://github.com/Zhang-JiahangH/react-virtualized-diff/blob/main/benchmark-results/results.md) - -## Monorepo structure - -```text -apps/demo/ # Vite demo app -packages/react/ # npm package: react-virtualized-diff -``` - ---- - -## Local development - -```bash -pnpm install -pnpm dev # run demo app -pnpm build # build workspace packages -``` - ---- - -## npm package README support - -To ensure npm users always see correct documentation: - -- Package-level README is maintained at `packages/react/README.md` -- `packages/react/package.json` includes README in publish files -- Root README links to the package docs and Chinese docs - ---- - -## Release log - -See [CHANGELOG.md](https://github.com/Zhang-JiahangH/react-virtualized-diff/blob/main/CHANGELOG.md) for tracked releases and supported capabilities. - ---- - -## Future plan - -### Near-term roadmap - -- [ ] Optional syntax highlighting (performance-aware) -- [ ] More comprehensive live demo scenarios (big files, mixed edits) -- [ ] Public hosted demo site for quick evaluation -- [ ] Better customization hooks (line renderers, gutters) - -### Additional TODOs to make this project more popular +- `original: string` +- `modified: string` +- `contextLines?: number` (default `2`) +- `height?: number | string` (default `500`) +- `locale?: DiffViewerLocale` +- `language?: string` (reserved for future use) -- [x] Detailed benchmark report vs common diff viewers -- [ ] Keyboard navigation + accessibility improvements -- [ ] Dark/light theme presets and design tokens -- [ ] SSR usage guide (Next.js / Remix examples) -- [ ] More real-world examples (JSON, logs, markdown, code) -- [ ] CI release automation + semantic versioning workflow -- [ ] Contribution guide and issue templates -- [ ] International docs beyond English/Chinese +### `DiffViewerLocale` ---- +- `collapse?: string` +- `showMoreLines?: (count: number) => string` ## License diff --git a/packages/react/package.json b/packages/react/package.json index 09843e7..359e36f 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "react-virtualized-diff", - "version": "0.1.3", + "version": "0.1.4", "description": "High-performance React diff viewer for large files", "main": "./dist/index.cjs", "module": "./dist/index.mjs",