List Virtualization (Windowing) in React Explained
Render only the rows in view plus overscan, keep the scrollbar honest with a prefix sum of heights, anchor scroll and key rows by id.
Windowing: common questions
When should I virtualize a list?
When a list has enough rows that rendering all of them makes scrolling or interaction slow, usually hundreds to thousands of complex rows. Short lists are simpler without it.
Related chapters
- Core Web Vitals in Production: LCP, INP and CLS
- The Cost of JavaScript: Bundle Size, Parsing and Hydration
- Critical Rendering Path Explained: DOM, CSSOM, Paint
- Critical CSS: Inline Above-the-Fold Styles
- CSS Performance: Selectors, @import and Layout Cost
- HTTP Caching Explained: Cache-Control, ETag, CDN
- Lazy Loading Images and Code: Best Practices
- Intersection Observer API Explained, with Examples
- How Mobile Browsers Work: Camera, Permissions, Quirks
- Frontend Performance Case Studies: Netflix, Airbnb, Flipkart
Keep learning
Overview
Maya posted a photo Reply from Jon Link: rendering notes Poll: ship Friday? A short note Chapter 66 · windowing Only the rows on screen get a DOM node The scrollbar still spans the whole list. The nodes for the rest are absent.
1. The bill is the nodes, not the data
Mount every row 10,000 rows · 10,000 trees Style, layout, and memory run for rows the eye never reaches. The first paint waits on them. A window 10,000 rows · about 14 trees The list keeps its length. The DOM holds the viewport, plus a few rows of overscan so a fast scroll has something to show.
6. What you decide in production
Total height The spacer spans all rows. The mounted band is small. The viewport sits inside it. every row height summed short sum last rows unreachable One empty box is as tall as every row summed. The scrollbar thumb is that height divided by the viewport. A short sum means the reader cannot reach the last row. With zero overscan only the viewport is mounted. With 200 pixels, a band above and below is mounted too. fast fling Extra rows above and below. Zero overscan leaves a blank band when the scroll moves faster than the next commit. A few hundred pixels is the usual band. More pixels means more nodes. Measure, then correct An image above the viewport loads, the row grows 72 pixels, scrollTop gets the same 72 pixels in a layout effect, then the browser paints. img above loads row +72px scrollTop += 72 Variable rows store a prefix sum. Finding the first visible index is a binary search on that sum. An image that finishes above the viewport changes the sum. Add that delta to scrollTop in useLayoutEffect, before paint. Who holds the scroll position in-flow list: the browser anchors for you absolute rows: anchoring cannot see it, the delta is yours The browser will hold an in-flow list still when content above grows. Absolutely positioned rows change the math without a shift that anchor can see. The delta is yours. Keys and drafts Slot keys keep text on the screen slot. Id keys move it with the row. A store keeps it after unmount. moves with row survives unmount Key the row by its id. A slot key keeps the previous input, video, and hover. State inside the row dies when the row leaves the window, so a comment draft lives in a store keyed by id. The accessibility tree The grid says 10,000 rows. Only rows 4012 to 4014 exist, each with its row index. rowindex 4012 focus → next row Unmounted rows are absent from find-in-page and from screen readers. A grid exposes aria-rowcount and aria-rowindex on the rows that exist, and moves focus when the focused row unmounts. Relative cost for 10,000 rows. All nodes: highest. content-visibility: layout and paint skipped but memory stays. A window: lowest. all nodes layout + paint + memory content-visibility: auto with contain-intrinsic-size keeps the nodes and skips layout and paint offscreen. Hundreds of plain rows can stop there. Tens of thousands of component trees still want a window, because memory and commit cost remain. Library features measures rows
7. The end of the list is a different tool
Mounted rows in the middle. Empty space above and below. A sentinel sits at the real end of the list. Intersection Observer watches that sentinel and asks for the next page. no node mounted window Scroll the feed. The scroll moved. New rows are not mounted yet. The window caught up.
2. Scroll a real window
160 rows in this box. A production feed is closer to ten thousand, and each row is a tree of images and buttons. The shape is the same. What exists in the DOM Every row Row heights Mixed, measured Mixed, assumed 56px Load a photo above Fling downward Hold my place on screen mounted, off screen no node placed at the wrong offset Every row was placed as if it were 56px tall. The tall ones cover their neighbors, and the scrollbar is shorter than the real sum. · photo loaded
3. A running sum finds the row
Start positions 0, 48, 96, 216, 264, 344. Each one is the sum of the heights above it. Even rows are index × height, which is that sum with a closed form. Mixed rows search the sum. The search is logarithmic. Walking all 10,000 heights on every scroll is the slow version of the same idea.
4. The key decides who keeps the letters
Type in a row, then scroll. Slot keys glue the letters to the screen. Id keys take the letters with the row. React key Key by slot Key by row id Rows with inputs type, then scroll When the row unmounts, state that lived inside it is gone. A draft the reader still cares about is stored by id, outside the window.
Feed
Posts are variable height. Measure them. Overscan covers the fling. The sentinel at the real end loads the next page.
Sheet
= 2 && row = 3 && col Rows and columns both window. The mounted set is a rectangle. Sticky headers sit outside that rectangle and paint on top.
Chat
Follow the end while the reader is already there. A scroll upward means they are reading history. New rows must not pull them down.
File tree
Fifty thousand files, twenty rows on screen. The same sum, with indentation as a property of the row, not a reason to mount the rest. at the end Reading history Following the end Two new messages
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.