Thanks for your interest in contributing! This guide covers the basics.
- Node.js 18+
- pnpm (recommended) or npm/yarn
git clone https://github.com/quanming1/react-code-diff.git
cd react-code-diff
pnpm install
pnpm dev # start the demo at localhost:5173src/
├── code-diff/ # the component library (the actual library)
│ ├── CodeDiff.tsx # main component + sub-components (Toolbar, SearchBar, rows)
│ ├── CodeDiff.css # component styles (CSS variables driven)
│ ├── types.ts # all types & config interfaces
│ ├── diff-engine.ts # line/word diff computation, collapse, search
│ ├── highlight-engine.ts # refractor syntax highlighting + flatten to lines
│ ├── segment-merger.ts # merge syntax/diff/search ranges into render segments
│ ├── config-merger.ts # deep-merge config + colors → CSS vars
│ ├── default-config.tsx # default theme, font, layout, icons, texts
│ └── index.ts # public exports
├── App.tsx # demo app
└── main.tsx # Vite entry
The three-engine architecture (diff → highlight → segment-merge) keeps each concern isolated and testable. When changing behavior, try to modify the relevant engine rather than the rendering layer.
- Fork & branch — create a branch from
main:git checkout -b feat/your-feature
- Code — follow the existing style (TypeScript, functional components, no class components). Keep changes focused.
- Lint — ensure it passes:
pnpm lint
- Build — make sure the build succeeds:
pnpm build
- Test — run the demo (
pnpm dev) and verify your change visually in bothsplitandunifiedmodes,darkandlightthemes. - Commit — use clear, conventional commit messages:
feat: add word-wrap toggle fix: incorrect line number on unified view refactor: simplify segment merger docs: update README props table - Pull Request — open a PR against
main. Describe what changed and why. Include screenshots if the UI changed.
- TypeScript strict — no
anyunless absolutely necessary; prefer proper types fromtypes.ts. - CSS variables — all colors/fonts/layout go through
--cd-*CSS variables. Never hardcode colors in components. - Performance — keep heavy computations in
useMemo; avoid re-rendering rows unnecessarily (see how split-drag uses direct DOM manipulation as a reference). - No new dependencies — prefer using what's already installed. If a new dep is truly needed, justify it in the PR.
Open an issue with:
- A minimal reproduction (old/new code strings + props used)
- Expected vs actual behavior
- Browser and React version
By contributing, you agree your contributions will be licensed under the MIT License.