Virtualized Lists & Windowing
Mounting 20,000 list rows creates 200,000+ DOM nodes, blowing past memory and Browser Rendering Pipeline layout budgets. Windowing mounts only the ~20 rows currently inside the scroll viewport (plus a small overscan buffer), keeping DOM work constant regardless of dataset size.
List Rendering: Full DOM vs Windowed Viewport
Adjust total dataset size and overscan buffer to compare live DOM node count and layout cost.
Under the Hood
A virtualized list behaves like a train window: the landscape has 50,000 trees, but only 15 trees exist outside the glass at any moment. Inside a single tall spacer container (height: totalRows * rowHeight), the list computes visible indices from scrollTop and positions rows via GPU Compositor Layers (translateY).
- Compute
startIndex = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan)andendIndexfrom container height. - Render only
items.slice(startIndex, endIndex)withtransform: translateY(${i * rowHeight}px). - For dynamic-height rows, attach a ResizeObserver to measure rendered items once and update a prefix-sum offset table.
function getVisibleRange(scrollTop, viewportHeight, rowHeight, total, overscan = 4) {
const first = Math.floor(scrollTop / rowHeight);
const count = Math.ceil(viewportHeight / rowHeight);
return {
start: Math.max(0, first - overscan),
end: Math.min(total, first + count + overscan),
};
}Problem Genealogy
- 2012 (Infinite Scroll DOM Append): Appended 50 items per page indefinitely until tabs hit 1 GB RAM and crashed on mobile.
- 2015–2018 (
react-virtualized/react-window): Standardized fixed- and variable-height windowing with overscan buffers. - 2020+ (CSS
content-visibility: auto): Let the browser skip layout and paint for offscreen DOM nodes natively without JS windowing for medium-sized lists.
Production Pitfalls
- Breaking
Cmd+Fand accessibility: Unmounting offscreen rows removes them from native browser find-in-page and shifts screen-reader row counts unlessaria-rowcountandaria-rowindexare provided. - Scrollbar jitter with estimated heights: Guessing
estimatedHeight = 50pxfor rows that actually measure180pxcauses the scrollbar thumb to jump wildly while scrolling.
- When not to use JS Virtualization: For lists under ~500 simple rows, native DOM + CSS
content-visibility: auto; contain-intrinsic-size: 0 64px;preservesCmd+Fsearch, text selection, and accessibility with zero JS complexity.
Connections & Logical Next Steps
Rendering 10,000+ DOM nodes chokes style recalculation and layout passes; windowing caps active nodes.
Variable-height virtualized rows rely on ResizeObserver to measure and cache actual row heights.
Positioning windowed rows with transform: translateY() avoids triggering layout during scroll.
Full-list DOM rendering forces layout over thousands of off-screen boxes, whereas virtualization caps active layout nodes to the viewport.