Event delegation
One handler near the top reads data attributes from the event target. It replaces more than 20 handlers per line. Drag selection uses the same path to highlight lines.
The Files changed tab runs in React and is now the default for all users. On extreme pull requests the JavaScript heap passed 1 GB and DOM nodes passed 400,000. Interaction latency (INP) became unacceptable as diffs grew.
The v1 design used many small shared components close to the old Rails view.
The v1 diff line used about 10 DOM elements in unified view and 15 in split view. It also used at least 8 or 13 React components per line, each with several event handlers. The v2 design uses separate unified and split components, so each carries only its own logic.
A single top-level handler reads data attributes to find the target line. Comment and menu state live in children that render only when needed. Very large diffs use virtualization so only visible rows exist in the DOM.
One handler near the top reads data attributes from the event target. It replaces more than 20 handlers per line. Drag selection uses the same path to highlight lines.
Selectors use JavaScript Maps keyed by file path and line. This gives constant-time access to comments and selection state. It removes scans over nested arrays.
useEffect is allowed only at the top level of a diff file. A lint rule blocks it in line components. This lets line components be memoized safely.
Applies only to pull requests above about 10,000 diff lines. TanStack Virtual swaps rows as the user scrolls. Smaller pull requests keep native find-in-page.
| No. | Chose | Instead of | Why |
|---|---|---|---|
| D1 | Separate split and unified components | Shared thin wrappers for both views | The wrappers carried unused branches, and the team accepted some duplicated code. |
| D2 | Virtualize only the largest pull requests | Virtualize everything | Worst-case fixes can hurt everyday reviews, such as native search. |
| INP | Interaction to Next Paint, a measure of how fast a page responds to input. |
|---|---|
| Virtualization | Rendering only the rows currently visible in a long list. |