[BUG] customScrollParent inside a CSS zoom-ed ancestor: growing gap, missing items, endReached stops firing
Describe the bug
When a Virtuoso list with customScrollParent is rendered inside an element with CSS zoom other than 1, the virtualizer mixes two coordinate systems. Item sizes and scrollTop are in layout (unscaled) pixels, while the viewport rect, list offset and per-item size correction come from getBoundingClientRect(), which returns zoom-scaled pixels.
At zoom < 1 the drift grows with total content height:
- Blank space appears inside the scroller above and below the rendered items, and grows with every page appended.
- Items briefly render into the blank space and jump on fast scroll.
- Once the drift exceeds the viewport plus
increaseViewportBy,endReachednever fires again, so infinite loading silently stalls even though more data is available.
At zoom > 1 the math is wrong in the other direction, it is just less visible.
Unlike transform: scale(), CSS zoom participates in layout and is now standardized in all engines (Chrome, Firefox 126+, Safari 17.4+). We use it for a "dashboard zoom" feature, which is how we hit this.
Root cause, two places feed getBoundingClientRect() values into arithmetic with layout pixels:
packages/react-virtuoso/src/hooks/useWindowViewportRect.ts(useWindowViewportRectRef),customScrollParentbranch:visibleHeight,offsetTop,listHeightandvisibleWidthare derived from rects (scaled) and then combined withcustomScrollParent.scrollTopand item sizes (unscaled).packages/react-virtuoso/src/utils/correctItemSize.ts:Math.round(el.getBoundingClientRect()[dimension])records item sizes in scaled pixels while the scroller'sscrollTop/scrollHeightstay unscaled.
Everything downstream (sizeRangeSystem, listStateSystem, endReached detection) assumes a single unit. TableVirtuoso and GroupedVirtuoso share this code and are affected too.
Reproduction
https://codesandbox.io/p/sandbox/jn8xqj?file=%2Fsrc%2FApp.tsx%3A35%2C1
To Reproduce
Steps to reproduce the behavior:
- Open the sandbox. The list is wrapped in
<div style={{ zoom: 0.75 }}>and usescustomScrollParentpointing at the red-bordered scroller. - Scroll to the bottom of the scroller.
- Observe: only a few items are rendered (e.g. 39 to 42), with blank space above and below them inside the scroller, and the "Loaded items" counter stays at 50 because
endReachednever fires. - Change the wrapper to
zoom: 1. Everything renders correctly and the counter grows to 100, 150, ... as you scroll.
Expected behavior
The list should behave identically at any CSS zoom: no blank space inside the scroller, all items in view rendered, and endReached firing when the user reaches the end.
Screenshots
Only items 39 to 42 are rendered; items 33 to 38 and 43 to 49 should fill the blank space. The counter is stuck at 50.
Desktop (please complete the following information):
- OS: macOS
- Browser: Chrome 128+ (also reproduced in Firefox and Safari)
- react-virtuoso: 4.12.8 and 4.18.11
Additional context
Proposed fix: divide every getBoundingClientRect()-derived value by Element.currentCSSZoom (Chrome 128+, Firefox 126+, Safari 17.4+). With ?? 1 as fallback, older browsers behave as today and zoom: 1 is a no-op.
// utils/correctItemSize.ts
export function correctItemSize(el: HTMLElement, dimension: 'height' | 'width') {
return Math.round(el.getBoundingClientRect()[dimension] / (el.currentCSSZoom ?? 1))
}// hooks/useWindowViewportRect.ts, customScrollParent branch
const rect = element.getBoundingClientRect()
let visibleWidth = rect.width
let listHeight = rect.height
let offsetTop: number, visibleHeight: number
if (customScrollParent) {
const zoom = customScrollParent.currentCSSZoom ?? 1
const customScrollParentRect = customScrollParent.getBoundingClientRect()
const deltaTop = (rect.top - customScrollParentRect.top) / zoom
visibleHeight = customScrollParentRect.height / zoom - Math.max(0, deltaTop)
offsetTop = deltaTop + customScrollParent.scrollTop
visibleWidth = rect.width / zoom
listHeight = rect.height / zoom
} else {
// window scroller branch unchanged
}We have been running exactly this change as a pnpm patch on top of 4.18.11 in production for several weeks. It fixed the blank space and the stalled endReached in our zoomed layout, with no observable effect at zoom: 1. Happy to open a PR with this change plus a test.
Workaround until fixed: patch the package as above, or keep the scroll container outside the zoomed subtree and apply zoom inside each item instead.
Source: petyosi/react-virtuoso