Repository navigation
fix(grid): stop hijacking the wheel, and stop rebuilding observers - #542
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #407, #417.
The wheel — #407
Past 5000 rows the grid installed a non-passive wheel listener that called
preventDefaultand movedscrollTopitself: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
preventDefaulton 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'sResizeObservereffect listedformattedin its dependencies, so every value change tore the observer down and constructed another. A grid pollingSELECT 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.
columnNameanddataTypewere dependencies as well, and neither bears on whether text overflows its box.Tests
preventDefault, so the assertion targets specifically the kind that can — I hit that while writing it and narrowed the check rather than loosening it.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.
EditableCellkeeps itseditingstate 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