Skip to content

Remove extra horizontal scrollbar space, improve row height estimation - #41

Open
hovhannesmarikyan wants to merge 1 commit into
pre-releasefrom
extra-scrollbar-removal
Open

Remove extra horizontal scrollbar space, improve row height estimation#41
hovhannesmarikyan wants to merge 1 commit into
pre-releasefrom
extra-scrollbar-removal

Conversation

@hovhannesmarikyan

Copy link
Copy Markdown

Problem

The grid's ideal-height calculation always reserved vertical space for a horizontal scrollbar, even when the content didn't actually overflow horizontally — leaving dead space below the grid in the
common case where everything fits.

For variable row heights (rowHeight as a function), the estimate also averaged only the first 10 rows and extrapolated that average across the entire dataset. On large, heterogeneous datasets this
could be significantly off, producing an incorrect ideal height and, ironically, a spurious scrollbar of its own.

Change

  • Extracted the ideal-size calculation out of data-editor.tsx into a pure, exported computeIdealSize function in data-editor-fns.ts so it's unit-testable in isolation.
  • Horizontal-scrollbar height is now only reserved when contentWidth > clientAreaWidth (i.e. the content actually overflows horizontally), removing the dead space in the non-overflowing case.
  • For function-based rowHeight, once the client area has been measured, the new logic sums exact row heights until the viewport is filled (with a minimum 10-row floor so the average isn't based on a
    single outlier row), then extrapolates the remainder from that average — instead of always averaging just the first 10 rows regardless of dataset size. This stays O(1)-ish for huge datasets while
    being far more accurate than the old fixed 10-row average.
  • Before the client area has been measured (first render), it still falls back to the bounded 10-row sample average, as before.
  • Memoized clientAreaWidth/clientAreaHeight as primitives out of clientSize so the idealWidth/idealHeight useMemo doesn't re-run on every scroll tick just because clientSize got a new array reference.

if (remainingRows > 0) {
h += (summedHeight / rowsSummed) * remainingRows;
}
} else {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea if we need "else" block as is.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32818848642

Coverage increased (+0.04%) to 89.271%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: 92 of 92 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 20575
Covered Lines: 18677
Line Coverage: 90.78%
Relevant Branches: 3798
Covered Branches: 3081
Branch Coverage: 81.12%
Branches in Coverage %: Yes
Coverage Strength: 3242.19 hits per line

💛 - Coveralls

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.

2 participants