Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gridSystem): fix
itemsPerRow
precision (#892)
* fix(gridSystem): fix `itemsPerRow` precision - Fix `itemsPerRow()` calculation to handle edge cases related to element dimension precision - Add tests with experimentally-determined edge cases that cause precision problems with the previous calculation - fixes [BUG] `VirtuosoGrid` + CSS Grid `List` component: items not rendered #889 `react-virtuoso` calculates element dimensions using `getBoundingClientRect()`. This value may be imprecise when the browser view is zoomed in/out, though technically it is [more precise than eg `clientWidth`](https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth). To see this for yourself, use `getBoundingClientWidth()` and `clientWidth` to measure the width of a relatively sized element at various zoom levels. `clientWidth` reports the same value each time, while `getBoundingClientRect()` may report slightly different values. This very small difference may be magnified during the calculation done in `itemsPerRow()` and, in certain cases, causes the resulting value to be 1 less than what it should be. The number of items to render in the window are thus incorrect. My crude understanding of the cause: when the browser calculates viewport and element dimensions at non-100% zoom level, some native rounding is involved. `getBoundingClientRect()`, which reports precise fractional values, is affected by this rounding, while `clientWidth` rounds or floors values. This may not be entirely correct - discussion on this is rather sparse and anyways, it's beyond me. * fix(gridSystem): make `itemsPerRow` more conservative Err on the side of rendering too many items instead of too few.
- Loading branch information