Skip to content

fix(grid): stop hijacking the wheel, and stop rebuilding observers - #542

Merged
EVWorth merged 1 commit into
mainfrom
fix/grid-scroll-tab-observer
Sep 5, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/grid-scroll-tab-observer

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Closes #407, #417.

The wheel — #407

Past 5000 rows the grid installed a non-passive wheel listener that called preventDefault and moved scrollTop itself:

const SCROLL_BOOST = Math.min(totalRows / 100, 100);
el.scrollTop += e.deltaY * SCROLL_BOOST;

The multiplier came from the row count, which is not a property of the input device. On a 10K-row result one notch of a mouse wheel travelled 10,000px — about 312 rows — so the grid was unusable for finding anything. A trackpad sends small pixel deltas many times a second and got the same treatment from the other direction, feeling stuck. deltaMode, which is what actually says whether a delta is in pixels, lines or pages, was never read.

Deleted. Native scrolling and the virtualizer already handle this between them, and preventDefault on a non-passive listener was costing a main-thread round trip per event to reimplement it worse. Overscan left at 5 — native scrolling is slower than the boosted version was, so if anything it needs less headroom, and changing it speculatively isn't warranted.

The observer — #417

TruncatedCell's ResizeObserver effect listed formatted in its dependencies, so every value change tore the observer down and constructed another. A grid polling SELECT NOW(), or a column being typed into, does that for every visible cell on every render.

One correction to the issue's framing: nothing leaked. The cleanup did call disconnect(), so observers were not accumulating. The cost is churn — hundreds of constructions a second all doing the work of one — which is real and does show up as CPU burnt on an idle grid, but "leak" overstates what was happening.

Split in two: the observer is created once per mounted cell and watches for the box resizing; a second effect re-measures when the text changes, which is a single layout read and what the original effect was really for. columnName and dataType were dependencies as well, and neither bears on whether text overflows its box.

Tests

  • One browser test asserting no non-passive wheel listener is installed on a 5001-row result. React's own root registers a passive wheel listener, which by definition cannot preventDefault, so the assertion targets specifically the kind that can — I hit that while writing it and narrowed the check rather than loosening it.
  • Three on observer churn: one observer across 25 value changes, one across column-metadata changes, and still disconnected on unmount.

The wheel test and the first two churn tests fail against the previous implementation, verified by stashing each source file. The unmount test passes either way — it guards behaviour the split could plausibly have broken, and didn't.

1700 unit + 298 browser green, tsc/dprint/eslint clean.

Not included

#408 (Tab doesn't move focus) is the third of the remaining grid bugs and I deliberately left it out. EditableCell keeps its editing state internally, so making Tab move the edit to the next cell means lifting that state to the grid and turning the cell into a controlled component — an API change with its own test surface. It doesn't belong in a PR that otherwise deletes code. Next one.

🤖 Generated with Claude Code

Closes #407, #417.

## The wheel (#407)

Past 5000 rows the grid installed a non-passive wheel listener that called
preventDefault and moved scrollTop itself:

    const SCROLL_BOOST = Math.min(totalRows / 100, 100);
    el.scrollTop += e.deltaY * SCROLL_BOOST;

The multiplier came from the row count, which is not a property of the input
device. On a 10K-row result one notch of a mouse wheel travelled 10,000px,
about 312 rows, so the grid was unusable for finding anything. A trackpad
sends small pixel deltas many times a second and got the same treatment from
the other direction, feeling stuck. deltaMode, which is what actually says
whether a delta is in pixels, lines or pages, was never read.

Deleted. Native scrolling and the virtualizer already handle this between
them, and preventDefault on a non-passive listener was costing a main-thread
round trip per event to reimplement it worse.

## The observer (#417)

TruncatedCell's ResizeObserver effect listed `formatted` in its dependencies,
so every value change tore the observer down and constructed another. A grid
polling SELECT NOW(), or a column being typed into, does that for every
visible cell on every render.

Nothing leaked — the cleanup did disconnect them — so the issue's framing
overstates it. The cost is churn: hundreds of constructions a second all
doing the work of one, showing up as CPU burnt on an idle grid.

Split in two. The observer is created once per mounted cell and watches for
the box changing size. A second effect re-measures when the text changes,
which is a single layout read and what the original effect was really for.
`columnName` and `dataType` were dependencies too, and neither bears on
whether text overflows its box.

## Tests

- one browser test asserting no non-passive wheel listener is installed on a
  5001-row result; React's own root registers a passive one, which by
  definition cannot preventDefault, so the assertion targets the kind that
  can
- three on observer churn: one observer across 25 value changes, one across
  column-metadata changes, and still disconnected on unmount

The wheel test and the first two churn tests fail against the previous
implementation. The unmount test passes either way — it guards behaviour the
split could plausibly have broken, and did not.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit fdd8919 into main Sep 5, 2026
10 checks passed
@EVWorth
EVWorth deleted the fix/grid-scroll-tab-observer branch September 5, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] [bug] Scroll wheel hijacking — broken for fast wheels, breaks a11y

1 participant