10,000 coupons in the neighbourhood head’s book: how many rows are really in the DOM? Scroll a real list, then test windowing on keyboard focus, screen…
Why it matters
A long list (a chat, a table, a feed) rendered in full makes thousands of DOM nodes: slow to mount, heavy to lay out, wasteful of memory. Windowing parts the data’s length from the DOM’s size, at a cost: keyboard focus, screen readers, Ctrl+F and rows of different heights must be looked after by hand.
The key idea
The data’s length and the DOM’s size need not match
Common mistakes
Rendering every row “to keep it simple” Thousands of nodes are slow to mount, heavy to lay out and wasteful of memory. Windowing keeps the DOM small and the same size whatever the data; use react-window or @tanstack/virtual.
Rows of different heights Simple windowing assumes every row is ROW tall. Taller rows overlap, and the scrollbar is wrong. Measure each row’s real height once mounted (measureElement in @tanstack/virtual) and work places out from it.
Forgetting a stable key With key={index}, React reuses the element in the same place for another item when the list shifts: what the element holds (a tick, typed text, focus) moves to the wrong item. Use a stable id.
Try it in this playground
Scroll the list of 10,000 coupons Rows in the DOM stay a dozen or so; the window moves, old rows go, new ones are mounted.
Press Render every row See how long 10,000 rows take to mount, and how many nodes are in the DOM.
Focus coupon 00003, then scroll Its element is removed and focus drops to <body>.
Turn on aria-setsize for screen readers Without it, a screen reader announces the rows in the DOM, not the coupons.