Rendering Long Lists in React: How We Choose Between content-visibility, TanStack Virtual and Pagination
Table of Contents
About the Author

Ahmed Mahmoud
Author & Developer
Software engineer passionate about web development and user experience design.
Founder of Devya · eng-ahmed.com ↗A long React list is slow for one of two reasons: React spends too long rendering components, which is a JavaScript cost, or the browser spends too long on style, layout and paint, which is a rendering cost. At Devya we treat these as different problems. CSS content-visibility: auto fixes only the rendering cost; list virtualization with TanStack Virtual fixes both but breaks find-in-page, server rendering and keyboard focus until it is patched; pagination sidesteps the problem entirely when the list is backed by a server.
Almost every product our team ships eventually grows a list that was fine with 50 rows and painful with 5,000: an activity feed, an admin table, a log viewer. The reflex is to install a virtualization library, but sometimes one CSS property or a ?page=2 link does the job with none of the side effects. These are our field notes on telling the cases apart, and on what we patch after we virtualize.
Key takeaways
Measure before choosing: the Chrome DevTools Performance panel shows whether a slow list spends its time in Scripting (React rendering) or in Rendering and Painting (style, layout, paint), and the right fix depends on which one dominates.
content-visibility: auto is a one-line fix for layout cost: the browser skips layout and paint for off-screen elements while every row stays in the DOM, so find-in-page and screen readers keep working. The property has been Baseline since Safari 18 shipped it in September 2024.
Virtualization is the fix for JavaScript cost: the useVirtualizer hook from TanStack Virtual mounts only the rows near the viewport, so React renders a few dozen row components instead of thousands.
Virtualization has a bill: unmounted rows break browser find-in-page, are invisible to crawlers, render nothing on the server by default, and can drop keyboard focus.
Pagination beats both for indexable, server-backed lists: real URLs such as ?page=2 are crawlable, shareable and cheap to render.
What actually makes a long React list slow?
A long React list is slow because of JavaScript work, browser rendering work, or both, and each one needs a different fix. JavaScript work is React calling every row component, diffing the output and committing DOM changes; it grows with the number of mounted rows and the cost of each row component. Browser rendering work is style recalculation, layout and paint; it grows with DOM size and CSS complexity, even when React is idle.
We record the slow interaction (first load, typing into a filter, expanding a row) in the Chrome DevTools Performance panel and read the summary. If most of the time sits under Scripting, inside React's render and commit functions, the problem is too many components rendering. If most of the time sits under Rendering (Recalculate Style, Layout) and Painting, React has finished and the browser is struggling with the DOM. The React DevTools Profiler confirms the first case by showing the render time of each component in each commit. We also watch Interaction to Next Paint (INP), the Core Web Vital that measures input responsiveness, because a big list that re-renders on every keystroke is a classic INP failure.
When is CSS content-visibility: auto enough?
content-visibility: auto is enough when the bottleneck is browser layout and paint and React already renders the list in acceptable time. The CSS property content-visibility controls whether the browser renders an element's contents at all; with the value auto, the browser skips layout and paint for elements outside the viewport and renders them as they approach it. Every row stays in the DOM, so Ctrl+F finds text in off-screen rows, screen readers can read the full list, and the server-rendered HTML is complete.
The whole change is one CSS rule on the row class: content-visibility: auto, plus contain-intrinsic-size: auto 96px. The second property matters as much as the first. A skipped element has no rendered content to size it, so without a placeholder every off-screen row collapses toward zero height and the scrollbar jumps as rows render. The value auto 96px reserves 96 pixels until a row has rendered once, then reuses its last real size.
The limit of content-visibility is that it saves the browser's work, not React's. React still renders, reconciles and holds in memory every row component, and the DOM still contains every node. A list whose rows are cheap components with expensive layout (long text, nested grids, many images) gets a large win. A list of heavy components with menus, charts and several hooks per row barely improves.
How do you virtualize a list with TanStack Virtual?
List virtualization, also called windowing, is a technique that mounts only the rows in or near the viewport and positions them inside a container sized to the full list's height. TanStack Virtual (the @tanstack/react-virtual package, version 3) is the headless library our team uses for it: it computes which rows to render and where, and leaves the markup to us. It handles rows of unknown height by measuring them after they mount.
Our setup calls useVirtualizer with five options: count (the number of rows), getScrollElement (a ref to the scrolling container), estimateSize (a first height guess such as 96 pixels), overscan (extra rows rendered beyond the viewport) and getItemKey (a stable row ID). The inner list is sized with getTotalSize(), and each item from getVirtualItems() renders as an absolutely positioned row moved into place with translateY(item.start).
Three details carry most of the correctness. getTotalSize() sizes the inner list so the scrollbar represents every row, not just the mounted ones. The measureElement ref plus a data-index attribute lets the virtualizer read each row's real height through a ResizeObserver, so a row that grows when its image loads re-flows correctly. getItemKey keys rows by a stable ID instead of their index, which keeps cached measurements attached to the right row when the list is filtered or reordered. We raise overscan above its default of 1 because a single spare row shows blank gaps during fast scrolling.
For a list that scrolls with the page instead of inside a box, useWindowVirtualizer takes the same options without getScrollElement. In the Next.js App Router the virtualized list must be a Client Component, so we fetch rows in a Server Component and pass them down as props; only the windowing logic ships to the browser.
What does virtualization break, and how do you fix it?
Virtualization breaks every browser feature that assumes the whole list is in the DOM. These are the ones our team has hit, and the fix we use for each.
Find-in-page: Ctrl+F cannot find text in rows that are not mounted. For log viewers and long documents, where users expect find-in-page, we use content-visibility instead, or ship an in-app search that jumps to the match with virtualizer.scrollToIndex(index).
Server rendering and SEO: the virtualizer needs the scroll container's size, which does not exist on the server, so a server-rendered virtual list contains no rows by default. The initialRect option, for example { width: 1024, height: 800 }, makes the server render the first screen of rows. Crawlers still never scroll, so we never virtualize a list whose content must be indexed.
Keyboard focus: when a focused row scrolls out of range, React unmounts it and focus falls back to document.body. We track the focused index and keep that row mounted with a custom rangeExtractor that adds it to the indexes returned by defaultRangeExtractor(range).
Screen readers: assistive technology only sees mounted rows, so we set aria-setsize and aria-posinset on every row to announce the true position, such as item 312 of 5,000.
Scroll restoration: the browser cannot restore a scroll position inside a list that has not measured its rows yet. We save virtualizer.scrollOffset when the list unmounts and pass it back through the initialOffset option.
React Compiler: useVirtualizer returns a mutable instance whose methods return new values without the object changing identity, which React Compiler cannot memoize safely. eslint-plugin-react-hooks flags it under its incompatible-library rule.
Which approach should you pick for your list?
We pick the cheapest approach that fixes the cost we measured, in this order: render everything, add content-visibility, paginate, virtualize. Virtualization comes last because it carries the most side effects, not because it is the weakest tool.
Render everything: fixes neither cost, keeps find-in-page and crawlability, and takes no effort.
content-visibility: auto: cuts layout and paint cost only, keeps find-in-page and server rendering, and is one CSS rule.
Pagination with real URLs (?page=2): cuts both costs and stays crawlable for low effort, though find-in-page only covers the current page.
Infinite scroll (useInfiniteQuery plus IntersectionObserver): helps at first, but the DOM keeps growing and only the first page is server-rendered; medium effort.
Virtualization (TanStack Virtual): cuts both costs but loses find-in-page and crawlability unless initialRect is set; the highest effort.
Our working rules: a few hundred simple rows rarely need anything. Long, text-heavy rows such as comments, articles or documentation get content-visibility. Product catalogs, blog archives and anything search engines should index get server-side pagination with real URLs, preferably cursor-based. Dashboards, data grids, chat histories and log streams with thousands of interactive rows get virtualization, and infinite feeds get infinite loading plus virtualization together, so the DOM stays small however far the user scrolls. These are starting points, not thresholds; the Performance panel makes the final call.
FAQ
Q: Does content-visibility: auto work in every browser?
A: Yes, in current versions. Chrome and Edge support content-visibility since version 85, Firefox since 125, and Safari since 18, which made it Baseline in September 2024. Older browsers ignore the property and render everything, so it is safe as progressive enhancement.
Q: How many rows can React render before I need virtualization?
A: There is no fixed number, because the limit depends on how expensive each row component and its CSS are. Record the slow interaction in the Chrome Performance panel: if Scripting dominates, reduce mounted rows with pagination or virtualization; if Rendering dominates, try content-visibility: auto first.
Q: Does list virtualization hurt SEO?
A: Yes, for content that should be indexed. Crawlers do not scroll, and a virtualized list renders only its first window of rows, or none on the server without initialRect, so indexable lists should use paginated URLs instead.
Q: Should I use TanStack Virtual, react-window or react-virtuoso?
A: All three are mature React virtualization libraries. We default to TanStack Virtual because it is headless, so it fits any markup or component library, and it measures dynamic row heights with measureElement.
Further Reading
Frontend Engineering
Dark Mode Without the Flash in Next.js 16: How We Ship a Blocking Theme Script, color-scheme, and a Hydration-Safe Toggle
Dark mode that flashes white on reload is a timing bug: the server cannot read localStorage. We explain the blocking theme script we use in Next.js 16, why we keep the theme out of cookies to preserve static rendering, and how we build a toggle that hydrates without mismatches.
Frontend Engineering
Dynamic Open Graph Images in Next.js 16: How We Build opengraph-image.tsx, Check the Satori Version next/og Ships, and Keep Link Previews Correct
Our generated share cards hit three surprises: a WOFF2 font the renderer could not parse, a Satori README describing a newer engine than the one Next.js bundles, and a page that kept showing its layout's image. These are our field notes on opengraph-image.tsx in Next.js 16, metadata precedence, and checking og:image before a link goes out.