State & ArchitectureBaseline · Widely

Virtualized Lists & Windowing

Mental Model

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.

Interactive Simulator

List Rendering: Full DOM vs Windowed Viewport

Adjust total dataset size and overscan buffer to compare live DOM node count and layout cost.

Parameter Profile
totalRows10000
overscanCount5
windowingEnabledOn
totalRows
10000
overscanCount
5
windowingEnabled
On
Parameters evaluated in real time.

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).

  1. Compute startIndex = Math.max(0, Math.floor(scrollTop / rowHeight) - overscan) and endIndex from container height.
  2. Render only items.slice(startIndex, endIndex) with transform: translateY(${i * rowHeight}px).
  3. For dynamic-height rows, attach a ResizeObserver to measure rendered items once and update a prefix-sum offset table.
JS
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

Production Pitfall
  • Breaking Cmd+F and accessibility: Unmounting offscreen rows removes them from native browser find-in-page and shifts screen-reader row counts unless aria-rowcount and aria-rowindex are provided.
  • Scrollbar jitter with estimated heights: Guessing estimatedHeight = 50px for rows that actually measure 180px causes the scrollbar thumb to jump wildly while scrolling.
When Not to Use
  • When not to use JS Virtualization: For lists under ~500 simple rows, native DOM + CSS content-visibility: auto; contain-intrinsic-size: 0 64px; preserves Cmd+F search, text selection, and accessibility with zero JS complexity.

Connections & Logical Next Steps

Mechanical Comparisons