List virtualization
Why thousands of DOM nodes make a page slow and how windowing keeps lists fast — from the fixed-height math and infinite scroll to measured heights, scroll anchoring, accessibility costs and the alternatives.
Reading level
Shows sections up to the selected level.
Before you start
This topic starts at Middle level.
Why thousands of DOM nodes are slow
Ekrandakı bir sətir arxasındakı datadan qat-qat baha başa gəlir. JavaScript-də 10 000 obyekti filtrləmək bir neçə millisaniyə çəkir, onları 10 000 cədvəl sətrinə çevirmək isə yox. Hər element bir neçə mərhələdə "ödəniş" edir və bu xərc istifadəçinin gördüyü sətirlərin yox, bütün sətirlərin sayı ilə artır:
- Yaradılma. React hər sətir komponentini çağırır, onun elementlərini və fiber-lərini, sonra da DOM node-larını yaradır.
- Style. Brauzer hər element üçün selector-ları uyğunlaşdırır və style-ları hesablayır.
- . Hər qutu ölçü və mövqe alır. Default
table-layout: autoilə sütunların eni hər xananın məzmunundan asılıdır, ona görə də cədvəl sütunlarını ölçmək üçün bütün sətirlərin layout-unu hesablayır. - Yaddaş. Sətirlər mövcud olduqca DOM node-ları, hesablanmış style-lar, layout obyektləri və React-in fiber-ləri yaddaşda qalır.
- Hər yeniləmə. Siyahının valideyni yenidən render olunanda — məsələn, axtarış qutusuna yazılan hər hərfdə — React bütün sətir komponentlərini yenidən çağırır və brauzer növbəti kadrı çəkməzdən əvvəl hər sətrin nəticəsini müqayisə edir.
Paint istisnadır: brauzer əsasən viewport-a yaxın olanı çəkir, ona görə də ekrandan kənar sətirlərin xərci azdır, amma yuxarıdakı bütün digər xərclər qalır.
function TransactionsTable({ transactions }) {
return (
<table className="transactions">
<tbody>
{transactions.map((t) => (
<tr key={t.id}>
<td>{t.date}</td>
<td>{t.merchant}</td>
<td>{t.category}</td>
<td>{t.card}</td>
<td>{t.amount}</td>
<td>{t.status}</td>
</tr>
))}
</tbody>
</table>
);
}Təsəvvür et: hər sətrində altı xana olan 10 000 tranzaksiyalıq cədvəl — 70 000 və daha çox element. Onlar səhifə açılanda bir uzun task-da yaradılır, filtr qutusuna yazılan hər hərfdə isə yenidən render olunur, halbuki scroll sahəsində bəlkə də cəmi on-on iki sətir görünür. Bir neçə yüz test qeydi ilə bunu heç kim hiss etmir; production datası ilə isə hər interaksiya saniyələr çəkir — INP məhz bunu ölçür.
Problemi necə tanımaq olar
- Performance panelində -də uzun task: vaxtın çoxunu scripting (React sətirləri render edir), "Recalculate style" və "Layout" tutur.
- Konsolda
document.querySelectorAll("*").length. Lighthouse body-də təxminən 800-dən çox node olanda xəbərdarlıq edir, 1 400-dən çox olanda isə xəta göstərir (Lighthouse 13-dən bu yoxlama "Optimize DOM size" insight-ının içindədir).
A row on the screen costs far more than the data behind it. Filtering 10,000 objects in JavaScript takes a few milliseconds; turning them into 10,000 table rows does not. Every element pays in several stages, and the costs grow with the number of rows, not with what the user can see:
- Creating it. React calls every row component, creates its elements and fibers, and then the DOM nodes.
- Style. The browser matches selectors and computes styles for each element.
- . Every box gets a size and position. With the default
table-layout: auto, column widths depend on the content of every cell, so a table lays out all its rows to size its columns. - Memory. DOM nodes, computed styles, layout objects and React's fibers all stay alive while the rows exist.
- Every update. When the list's parent re-renders — say, on each letter typed into a search box — React calls every row component again and compares every row's output before the browser can paint the next frame.
Paint is the exception: browsers mostly paint what is near the viewport, so off-screen rows cost little , but they still pay every other cost above.
function TransactionsTable({ transactions }) {
return (
<table className="transactions">
<tbody>
{transactions.map((t) => (
<tr key={t.id}>
<td>{t.date}</td>
<td>{t.merchant}</td>
<td>{t.category}</td>
<td>{t.card}</td>
<td>{t.amount}</td>
<td>{t.status}</td>
</tr>
))}
</tbody>
</table>
);
}Picture a table of 10,000 transactions with six cells per row: 70,000 elements or more, created in one long task when the page opens and rendered again on every keystroke in its filter box — while the scroll area shows perhaps a dozen rows. With a few hundred test records nobody notices; with production data each interaction takes seconds, which is exactly what INP measures.
How to spot it
- In the Performance panel, a long task on the dominated by scripting (React rendering the rows) plus "Recalculate style" and "Layout".
document.querySelectorAll("*").lengthin the console. Lighthouse warns when the body has more than about 800 nodes and reports an error above about 1,400 (since Lighthouse 13 this lives in the "Optimize DOM size" insight).
Windowing: render only what is visible
Windowing (başqa adı virtualizasiya) bütün datanı yaddaşda saxlayır, amma yalnız viewport-un içindəki sətirləri, üstəlik yuxarıda və aşağıda bir neçə əlavə sətri render edir — buna overscan deyilir. Siyahıda 300 element olsa da, 300 000 olsa da, DOM-un ölçüsü dəyişmir.
Quruluş üç hissədən ibarətdir: sabit hündürlüklü və overflow-y: auto olan viewport; scrollbar düzgün ölçüdə və aralıqda olsun deyə bütün siyahı qədər hündür spacer; və öz yerinə sürüşdürülmüş, render olunan sətirlərdən ibarət pəncərə:
<div class="viewport" style="height: 400px; overflow-y: auto">
<div class="spacer" style="position: relative; height: 40000px">
<div class="window" style="transform: translateY(880px)">
<div class="row" style="height: 40px">Row 22</div>
<div class="row" style="height: 40px">Row 23</div>
<div class="row" style="height: 40px">Row 24</div>
</div>
</div>
</div>(Kitabxanalar adətən hər sətri ayrıca absolute mövqeləndirir; <table>-da isə render olunan sətirlərdən yuxarıda və aşağıda bir boş spacer sətri qoyaraq cədvəl semantikasını saxlaya bilərsən.)
Sabit hündürlüklü sətirlərin riyaziyyatı
Bütün sətirlər eyni hündürlükdədirsə, mövqe vurma ilə, görünən aralıq isə bölmə ilə tapılır:
function getRange({ scrollTop, viewportHeight, rowHeight, count, overscan }) {
const first = Math.floor(scrollTop / rowHeight);
const last = Math.ceil((scrollTop + viewportHeight) / rowHeight);
const start = Math.max(0, first - overscan);
const end = Math.min(count, last + overscan);
return { start, end, offset: start * rowHeight, total: count * rowHeight };
}
getRange({ scrollTop: 1010, viewportHeight: 400, rowHeight: 40, count: 1000, overscan: 3 });
// { start: 22, end: 39, offset: 880, total: 40000 }firstyuxarı kənarın kəsdiyi sətirdir,lastaşağı kənarın kəsdiyi sətirdən bir sonrakıdır. Deməli,endaralığa daxil deyil və birbaşaitems.slice(start, end)-ə uyğun gəlir.scrollTop1010 olanda 25–35-ci sətirlər görünür; overscan 3 ilə pəncərədə 22–38-ci sətirlər olur: 1000 yox, 17 sətir.- Hər iki ucu məhdudlaşdır. Overscan 0-dan aşağı düşməməli və
count-u keçməməlidir. Axtarış siyahını qısaldanda isə köhnəscrollTopyeni sondan xeyli aşağıda qala bilər: əvvəlcəscrollTop-utotal - viewportHeightilə məhdudlaşdır, yoxsa pəncərə boş qalacaq, nəhəng spacer isə səhifəni boş göstərəcək.
Overscan-ı necə seçmək
Scroll adətən compositor-da, main thread-dən irəlidə gedir, ona görə də sürətli scroll hələ render olunmamış sətirlərə çata bilər və bir-iki kadr boş yer görünər. Böyük overscan bunu gizlədir, kiçik overscan isə hər render-i ucuz saxlayır. Bir neçə sətirdən bir ekran hündürlüyünə qədər dəyər geniş yayılıb.
Windowing (also called virtualization) keeps the full data in memory but renders only the rows inside the viewport, plus a few extra rows above and below — the overscan. The DOM stays the same size whether the list has 300 items or 300,000.
The structure has three parts: a viewport with a fixed height and overflow-y: auto, a spacer as tall as the whole list so the scrollbar has the right size and range, and the window of rendered rows moved to where they belong:
<div class="viewport" style="height: 400px; overflow-y: auto">
<div class="spacer" style="position: relative; height: 40000px">
<div class="window" style="transform: translateY(880px)">
<div class="row" style="height: 40px">Row 22</div>
<div class="row" style="height: 40px">Row 23</div>
<div class="row" style="height: 40px">Row 24</div>
</div>
</div>
</div>(Libraries usually position each row absolutely instead; in a <table> you can keep the table semantics with an empty spacer row above and below the rendered rows.)
The math for fixed-height rows
When every row has the same height, positions are a multiplication and the visible range is a division:
function getRange({ scrollTop, viewportHeight, rowHeight, count, overscan }) {
const first = Math.floor(scrollTop / rowHeight);
const last = Math.ceil((scrollTop + viewportHeight) / rowHeight);
const start = Math.max(0, first - overscan);
const end = Math.min(count, last + overscan);
return { start, end, offset: start * rowHeight, total: count * rowHeight };
}
getRange({ scrollTop: 1010, viewportHeight: 400, rowHeight: 40, count: 1000, overscan: 3 });
// { start: 22, end: 39, offset: 880, total: 40000 }firstis the row cut by the top edge,lastis one past the row cut by the bottom edge, soendis exclusive and maps straight toitems.slice(start, end).- At
scrollTop1010, rows 25–35 are visible; with overscan 3 the window holds rows 22–38: 17 rows instead of 1,000. - Clamp both ends. Overscan must not go below 0 or past
count. And when a search shortens the list, the oldscrollTopcan lie far below the new end: clampscrollToptototal - viewportHeightfirst, or the window is empty while a huge spacer keeps the page blank.
Choosing the overscan
Scrolling usually runs on the compositor, ahead of the main thread, so a fast fling can reach rows that are not rendered yet and show blank space for a frame or two. A larger overscan hides that; a smaller one keeps each render cheaper. A few rows to a screenful is common.
Windowing in React and with libraries
React-də əl ilə yazılan versiya scrollTop-u və viewport-un hündürlüyünü state-də saxlayan, aralığı render zamanı hesablayan və items.slice(start, end)-i render edən komponentdir. Scroll yalnız bu komponenti və onun 20–30 sətrini yenidən render edir. Burada üç detal vacibdir:
- Sətirlərə key-i elementin id-si ilə ver, kəsikdəki mövqe ilə yox. Id ilə React pəncərədə qalan sətirləri saxlayır və yalnız yeni girənləri mount edir; kəsik indeksi ilə isə hər sətrin state-i və DOM-u başqa elementə keçərdi.
- State-i yalnız aralıq dəyişəndə yenilə.
scrollsaniyədə dəfələrlə baş verir; aralığı saxlamaq (və yascrollTop-u tam sətrə yuvarlaqlaşdırmaq) hər piksel üçün render-in qarşısını alır. - Viewport-u ölç —
useLayoutEffect-də (ölçüsü dəyişə bilirsə, həm dəResizeObserverilə). Belə olanda ilk paint artıq düzgün sətirləri göstərir.
Təkcə useDeferredValue və ya memo DOM-u kiçiltmir: yazmaq bir az rahatlaşa bilər, amma hər sətir yenə mövcuddur və ilk render yenə hamısını yaradır.
TanStack Virtual
Real layihədə dəstəklənən kitabxanadan istifadə et. TanStack Virtual headless-dır: aralıqları və offset-ləri hesablayır, öz markup-ını render etmir.
import { useRef } from "react";
import { useVirtualizer } from "@tanstack/react-virtual";
function TransactionList({ transactions }) {
const scrollRef = useRef(null);
const virtualizer = useVirtualizer({
count: transactions.length,
getScrollElement: () => scrollRef.current,
estimateSize: () => 40,
overscan: 8,
getItemKey: (index) => transactions[index].id,
});
return (
<div ref={scrollRef} className="viewport">
<div style={{ position: "relative", height: virtualizer.getTotalSize() }}>
{virtualizer.getVirtualItems().map((row) => (
<TransactionRow
key={row.key}
transaction={transactions[row.index]}
style={{
position: "absolute",
top: 0,
width: "100%",
height: row.size,
transform: `translateY(${row.start}px)`,
}}
/>
))}
</div>
</div>
);
}Hər virtual elementin index, key, start, size və end sahələri var. Default overscan 1-dir, default key isə indeksdir, ona görə də getItemKey ötür. useWindowVirtualizer eyni işi səhifə ilə birgə scroll olunan siyahı üçün görür, scrollToIndex() isə istənilən elementə keçir.
react-window (2.x) isə hazır komponentlər verir: rowComponent, rowCount, rowHeight və rowProps qəbul edən List, iki ölçü üçün Grid və hündürlüyü əvvəlcədən bilinməyən sətirlər üçün useDynamicRowHeight. Ehtiyaca görə seç: markup üzərində tam nəzarət lazımdırsa (cədvəl, masonry, sticky sətirlər) TanStack, hazır komponent yetərlidirsə react-window.
In React the hand-written version is a component that keeps scrollTop and the viewport height in state, computes the range during render, and renders items.slice(start, end). Scrolling re-renders only that component and its 20–30 rows. Three details matter:
- Key rows by item id, not by the position in the slice. With ids, React keeps the rows that stay in the window and mounts only the ones that enter; with slice indexes every row's state and DOM would be reused for a different item.
- Update state only when the range changes.
scrollfires many times per second; storing the range (or roundingscrollTopto whole rows) avoids re-rendering on every pixel. - Measure the viewport in
useLayoutEffect(and with aResizeObserverwhen it can resize), so the first paint already shows the right rows.
useDeferredValue or memo alone do not shrink the DOM: typing may feel smoother, but every row still exists, and the first render still creates all of them.
TanStack Virtual
In production code, use a maintained library. TanStack Virtual is headless: it computes ranges and offsets and renders no markup of its own.
import { useRef } from "react";
import { useVirtualizer } from "@tanstack/react-virtual";
function TransactionList({ transactions }) {
const scrollRef = useRef(null);
const virtualizer = useVirtualizer({
count: transactions.length,
getScrollElement: () => scrollRef.current,
estimateSize: () => 40,
overscan: 8,
getItemKey: (index) => transactions[index].id,
});
return (
<div ref={scrollRef} className="viewport">
<div style={{ position: "relative", height: virtualizer.getTotalSize() }}>
{virtualizer.getVirtualItems().map((row) => (
<TransactionRow
key={row.key}
transaction={transactions[row.index]}
style={{
position: "absolute",
top: 0,
width: "100%",
height: row.size,
transform: `translateY(${row.start}px)`,
}}
/>
))}
</div>
</div>
);
}Each virtual item has index, key, start, size and end. The default overscan is 1 and the default key is the index, so pass getItemKey. useWindowVirtualizer does the same for a list that scrolls with the page, and scrollToIndex() jumps to an item.
react-window (2.x) gives you components instead: List with rowComponent, rowCount, rowHeight and rowProps, a Grid for two dimensions, and useDynamicRowHeight for rows that cannot be sized ahead of time. Pick by need: TanStack when you want full control over markup (tables, masonry, sticky rows), react-window when a ready component fits.
Infinite scroll with IntersectionObserver
Sonsuz scroll istifadəçi sona yaxınlaşanda növbəti səhifəni yükləyir. scroll-a qulaq asıb hər hadisədə scrollTop-u scrollHeight ilə müqayisə etmə: bu, main thread-də saniyədə dəfələrlə layout oxumaq deməkdir. Son elementdən sonra boş sentinel elementi qoy və onun viewport-a yaxınlaşdığını sənə IntersectionObserver desin. O, Baseline widely available-dır (2019-cu ilin martından).
import { useEffect, useRef } from "react";
function useLoadMore(loadMore, enabled) {
const sentinelRef = useRef(null);
useEffect(() => {
if (!enabled) return;
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) loadMore();
},
{ rootMargin: "0px 0px 800px 0px" },
);
observer.observe(sentinelRef.current);
return () => observer.disconnect();
}, [loadMore, enabled]);
return sentinelRef;
}
function Feed({ posts, hasNextPage, isFetching, fetchNextPage }) {
const sentinelRef = useLoadMore(fetchNextPage, hasNextPage && !isFetching);
return (
<div role="feed" aria-busy={isFetching} aria-label="News">
{posts.map((post, i) => (
<Post key={post.id} post={post} posInSet={i + 1} />
))}
<div ref={sentinelRef} />
</div>
);
}rootMargin: "0px 0px 800px 0px"root-u aşağıdan 800 px böyüdür, ona görə də növbəti səhifə sona hələ xeyli qalmış yüklənməyə başlayır. Siyahı öz konteynerinin içində scroll olunursa, həmin elementirootkimi ötür.- Səhifə yüklənərkən observer söndürülür, ona görə də eyni səhifə iki dəfə istənmir. Yenidən yaradılanda
observe()cari vəziyyətlə ilk callback-i çağırır: sentinel hələ də yaxındırsa, növbəti səhifə də yüklənir, qısa ilk səhifə isə ekranı özü doldurur. - Xəta vəziyyətini və ehtiyat variant kimi görünən "Daha çox yüklə" düyməsini saxla. Unutma ki, sonsuz siyahının altındakı footer-ə çatmaq çətindir.
- ARIA feed şablonu:
role="feed", hər postaria-posinsetvəaria-setsize(ümumi say bilinmirsə-1) olanarticle, yükləmə zamanıaria-busy="true". APG-yə görə Page Down və Page Up fokusu article-lar arasında hərəkət etdirir.
Sonsuz scroll windowing deyil
Hər səhifə DOM-a yeni postlar əlavə edir, ona görə də uzun sessiyanın sonunda yenə minlərlə node yığılır. İkisini birləşdir: yüklənmiş postları virtualizasiya et, növbəti səhifəni isə aralığa görə yüklə (son render olunan indeks count-a bir neçə element qalmış yaxınlaşanda), çünki virtualizasiya olunmuş siyahıda DOM-un sonu siyahının sonu deyil.
Infinite scroll loads the next page when the user gets close to the end. Don't listen to scroll and compare scrollTop with scrollHeight on every event: that reads layout many times per second on the main thread. Put an empty sentinel element after the last item and let an IntersectionObserver tell you when it comes near the viewport. It is Baseline widely available (since March 2019).
import { useEffect, useRef } from "react";
function useLoadMore(loadMore, enabled) {
const sentinelRef = useRef(null);
useEffect(() => {
if (!enabled) return;
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) loadMore();
},
{ rootMargin: "0px 0px 800px 0px" },
);
observer.observe(sentinelRef.current);
return () => observer.disconnect();
}, [loadMore, enabled]);
return sentinelRef;
}
function Feed({ posts, hasNextPage, isFetching, fetchNextPage }) {
const sentinelRef = useLoadMore(fetchNextPage, hasNextPage && !isFetching);
return (
<div role="feed" aria-busy={isFetching} aria-label="News">
{posts.map((post, i) => (
<Post key={post.id} post={post} posInSet={i + 1} />
))}
<div ref={sentinelRef} />
</div>
);
}rootMargin: "0px 0px 800px 0px"grows the root by 800 px at the bottom, so the next page starts loading well before the end. If the list scrolls inside its own container, pass that element asroot.- The observer is off while a page is loading, so the same page is never requested twice. When it is re-created,
observe()delivers a first callback with the current state: if the sentinel is still near, the next page loads too, and a short first page fills the screen by itself. - Keep an error state and a visible "Load more" button as a fallback, and remember that a footer below an infinite list is hard to reach.
- The ARIA feed pattern:
role="feed", each post anarticlewitharia-posinsetandaria-setsize(-1when the total is unknown), andaria-busy="true"while loading. Per the APG, Page Down and Page Up move focus between articles.
Infinite scroll is not windowing
Every page adds posts to the DOM, so a long session ends up with thousands of nodes again. Combine the two: virtualize the loaded posts, and trigger the next page from the range (when the last rendered index comes within a few items of count), because in a virtualized list the end of the DOM is not the end of the list.
Variable heights: estimate, measure, correct
Real sətirlərin hündürlüyü nadir hallarda eyni olur: postlarda şəkil var, mətn hər ekranda fərqli sınır, sətir açılıb genişlənir. Onda i-ci sətrin offset-i artıq i * rowHeight yox, özündən əvvəlki bütün ölçülərin cəmidir.
Prefiks cəmlər və binary search
offsets[i] = i-ci sətrin başlanğıcı saxla (offsets[0] = 0, offsets[i + 1] = offsets[i] + size[i]). Ümumi hündürlük offsets[count]-dur, ilk görünən sətir isə offsets[i] <= scrollTop şərtini ödəyən ən böyük i üçün binary search ilə tapılır — hər scroll-da siyahını gəzmək əvəzinə O(log n). Bir ölçü dəyişəndə ondan sonrakı bütün offset-lər dəyişir, ona görə də kitabxanalar offset-ləri ilk dəyişən indeksdən başlayaraq lazım olduqca yeniləyir.
Əvvəlcə təxmin, sonra ölçmə
Sətir render olunana qədər ölçüsü bilinmir, ona görə virtualizer:
- Ölçülməmiş hər sətir üçün təxmini ölçü götürür (TanStack-da
estimateSize; onun sənədləri dinamik ölçmədə ehtimal olunan ən böyük ölçünü yazmağı tövsiyə edir). - Pəncərəni render edir, sonra render olunan sətirləri ölçür. TanStack-ın
measureElementref-i və react-window-unuseDynamicRowHeight-iResizeObserver-dən istifadə edir; o, sonrakı dəyişiklikləri də tutur, məsələn, şəklin yüklənib qurtarmasını. - Ölçülmüş dəyəri indeksə yox, key-ə görə cache-də saxlayır ki, sıralama və ya filtr ölçüləri itirməsin, sonra offset-ləri yenidən hesablayır.
Ölçü dəyişəndə anchoring
Viewport-dan yuxarıdakı sətir təxmin ediləndən 20 px qısa çıxsa, ondan aşağıdakı hər şey 20 px yuxarı qalxır və istifadəçinin baxdığı məzmun sıçrayır. Həll yolu kadr çəkilməzdən əvvəl scrollTop-u eyni fərq qədər sürüşdürməkdir:
const measured = new Map();
const observer = new ResizeObserver((entries) => {
let shift = 0;
for (const entry of entries) {
const key = entry.target.dataset.key;
const size = entry.borderBoxSize[0].blockSize;
const old = measured.get(key) ?? ESTIMATE;
if (size === old) continue;
measured.set(key, size);
if (startOf(key) < viewport.scrollTop) shift += size - old;
}
if (shift !== 0) viewport.scrollTop += shift;
scheduleRender();
});Burada startOf sətrin offset-ini prefiks cəmlərdən oxuyur, render olunan hər sətir isə observer.observe(row) ilə izlənir. Resize müşahidələri paint-dən əvvəl çatdırılır, ona görə də düzəliş eyni kadra düşür. TanStack Virtual bunu sənin yerinə edir: default olaraq düzəlişi yalnız istifadəçi geriyə scroll etmədikdə tətbiq edir, shouldAdjustScrollPositionOnItemSizeChange isə bu qaydanı dəyişməyə imkan verir.
Tələlər
- Style yazan dövrün içində
getBoundingClientRect()ilə ölçmək səbəb olur. - İzlədiyi elementin ölçüsünü dəyişən callback "ResizeObserver loop completed with undelivered notifications" xətasını yaradır: qalan bildirişlər növbəti kadra qalır, layout titrəyir.
- Təxmini ölçülər real ölçülərlə əvəzləndikcə scrollbar-ın sürgüsü ölçüsünü dəyişir; yaxşı təxmin bunu minimuma endirir.
Real rows rarely have one height: posts have images, text wraps differently on each screen, a row expands. Then the offset of row i is no longer i * rowHeight but the sum of all sizes before it.
Prefix sums and binary search
Keep offsets[i] = the start of row i (offsets[0] = 0, offsets[i + 1] = offsets[i] + size[i]). The total height is offsets[count], and the first visible row is found by a binary search for the largest i with offsets[i] <= scrollTop — O(log n) per scroll instead of walking the list. When one size changes, every later offset changes, so libraries update offsets lazily from the first changed index.
Estimate, then measure
Sizes are unknown until a row is rendered, so a virtualizer:
- Estimates a size for every unmeasured row (TanStack's
estimateSize; its docs recommend estimating the largest likely size when measuring dynamically). - Renders the window, then measures the rendered rows. TanStack's
measureElementref and react-window'suseDynamicRowHeightuse aResizeObserver, which also catches later changes such as an image finishing loading. - Caches the measured size by key, not by index, so sorting or filtering keeps the measurements, and recomputes the offsets.
Anchoring when sizes change
If a row above the viewport turns out 20 px shorter than estimated, everything below it moves up 20 px and the content under the user's eyes jumps. The fix is to shift scrollTop by the same delta before the frame is painted:
const measured = new Map();
const observer = new ResizeObserver((entries) => {
let shift = 0;
for (const entry of entries) {
const key = entry.target.dataset.key;
const size = entry.borderBoxSize[0].blockSize;
const old = measured.get(key) ?? ESTIMATE;
if (size === old) continue;
measured.set(key, size);
if (startOf(key) < viewport.scrollTop) shift += size - old;
}
if (shift !== 0) viewport.scrollTop += shift;
scheduleRender();
});Here startOf reads a row's offset from the prefix sums and every rendered row is observed with observer.observe(row). Resize observations are delivered before paint, so the correction lands in the same frame. TanStack Virtual does this for you; by default it applies the correction only when the user is not scrolling backward, and shouldAdjustScrollPositionOnItemSizeChange lets you change that rule.
Pitfalls
- Measuring with
getBoundingClientRect()in a loop that also writes styles causes . - A callback that resizes what it observes triggers "ResizeObserver loop completed with undelivered notifications": the rest waits for the next frame and the layout flickers.
- The scrollbar thumb changes size as estimates are replaced; a good estimate keeps that small.
Keeping the scroll position: restoration and prepending
Uzun siyahıda istifadəçinin yerini iki vəziyyət pozur: siyahıya geri qayıtmaq və oxuduğu yerin yuxarısında yeni elementlərin peyda olması.
Naviqasiyadan sonra bərpa
Brauzer back və forward zamanı sənədin scroll mövqeyini özü bərpa edir (history.scrollRestoration default olaraq "auto"-dur). Virtual siyahı çox vaxt buna mane olur: o, öz konteynerinin içində scroll olunur, datası asinxron gəlir, təxmini hündürlüklər üzündən isə brauzer bərpa edən anda hələ kifayət qədər hündür olmur.
- Pikselləri yox, anchor-u saxla: ilk görünən elementin key-i və viewport-un yuxarı kənarının onun içində nə qədər aşağıda olduğu. Piksel offset-i yalnız eyni təxminlər və ölçmələr üçün doğrudur.
- Onu hər history qeydi üçün ayrıca saxla (
history.state-də və ya qeydə görə açarlanan map-də),scrollToIndex()ilə bərpa et, sonra offset-i əlavə et. - Datanı cache-də saxla ki, istifadəçi qayıdanda eyni elementlər yerində olsun; bərpanı öz kodun edirsə,
history.scrollRestoration = "manual"yaz.
Siyahının əvvəlinə əlavə
Köhnə mesajları yükləyən chat və ya yuxarıya "12 yeni post" əlavə edən lent viewport-dan yuxarıda hündürlük artırır, nəticədə oxunan məzmun aşağı sürüşür. Adi axında brauzerlər scroll anchoring edir: görünən sahədə bir anchor element seçir və ondan yuxarıdakı məzmun dəyişəndə scroll mövqeyini düzəldir. Bu, default olaraq açıqdır, overflow-anchor: none isə ondan imtina edir; MDN onu Baseline 2026 kimi göstərir (Chrome 56, Firefox 66, Safari 27).
Virtualizer sətirləri özü mövqeləndirir, deməli, düzəlişi də özü etməlidir: brauzer çəkməzdən əvvəl əlavə olunan elementlərin hündürlüyünü scrollTop-a əlavə et. React-də yeniləmədən əvvəl ölç, useLayoutEffect-də düzəlt:
const heightBefore = useRef(0);
async function loadOlder() {
const older = await fetchOlderMessages(messages[0].id);
heightBefore.current = viewportRef.current.scrollHeight;
setMessages((list) => [...older, ...list]);
}
useLayoutEffect(() => {
const viewport = viewportRef.current;
if (heightBefore.current === 0) return;
viewport.scrollTop += viewport.scrollHeight - heightBefore.current;
heightBefore.current = 0;
}, [messages]);- Virtualizasiya olunmamış scroller-də düzəlişi əl ilə edirsənsə, ona
overflow-anchor: nonever, yoxsa həm brauzer, həm də sənin kodun düzəliş edəcək və siyahı əks tərəfə sıçrayacaq. - Key-lər sabit id olmalıdır: virtualizer əvvələ əlavəni sona əlavədən məhz belə ayırır. TanStack Virtual-da chat, log və tərs lentlər üçün
anchorTo: "end"var,followOnAppendisə yeni elementlərin ardınca yalnız istifadəçi artıq sonda olanda gedir — tarixçəni oxuyan adamı aşağı dartmır.
Two situations break the user's place in a long list: coming back to it, and new items appearing above what they are reading.
Restoring after navigation
The browser restores the document's scroll position on back and forward (history.scrollRestoration is "auto" by default). A virtualized list often defeats that: it scrolls inside its own container, its data arrives asynchronously, and with estimated heights it is not tall enough yet when the browser restores.
- Save an anchor, not pixels: the key of the first visible item and how far the viewport top is inside it. A pixel offset is only valid for the same estimates and measurements.
- Store it per history entry (in
history.stateor a map keyed by the entry), restore withscrollToIndex()and then add the offset. - Keep the data cached so the same items exist when the user returns, and set
history.scrollRestoration = "manual"if your code takes over.
Prepending items
A chat loading older messages, or a feed inserting "12 new posts" at the top, adds height above the viewport, so the content being read moves down. In normal flow, browsers do scroll anchoring: they pick an anchor element in view and adjust the scroll position when content above it changes. It is on by default, and overflow-anchor: none opts out; MDN lists it as Baseline 2026 (Chrome 56, Firefox 66, Safari 27).
A virtualizer positions rows itself, so it corrects itself: add the height of the inserted items to scrollTop before the browser paints. In React, measure before the update and correct in useLayoutEffect:
const heightBefore = useRef(0);
async function loadOlder() {
const older = await fetchOlderMessages(messages[0].id);
heightBefore.current = viewportRef.current.scrollHeight;
setMessages((list) => [...older, ...list]);
}
useLayoutEffect(() => {
const viewport = viewportRef.current;
if (heightBefore.current === 0) return;
viewport.scrollTop += viewport.scrollHeight - heightBefore.current;
heightBefore.current = 0;
}, [messages]);- If you correct by hand in a non-virtualized scroller, set
overflow-anchor: noneon it, or the browser and your code both correct and the list jumps the other way. - Keys must be stable ids: that is how a virtualizer tells a prepend from an append. TanStack Virtual has
anchorTo: "end"for chats, logs and reverse feeds, andfollowOnAppendfollows new items only when the user was already at the end — someone reading history is not pulled down.
What windowing costs: find-in-page, screen readers, focus
Windowing sətirləri DOM-dan çıxarır və DOM üzərində işləyən hər şey də onları itirir. Windowing-in pulsuz sürət yox, trade-off olmasının səbəbi məhz bu xərclərdir.
Səhifədə axtarış
Ctrl+F / Cmd+F yalnız render olunan sətirləri tapır. İstifadəçiyə datanın özü üzrə axtarış ver (məsələn, bütün massivi filtrləyən axtarış qutusu) və onu asan tapılan yerdə saxla. content-visibility: auto əks trade-off-dur: render-i ötürülən məzmun axtarışda tapılır.
Ekran oxuyucular
Assistiv texnologiyalar DOM-dan qurulan accessibility tree-ni oxuyur, yəni 10 000 sətirlik cədvəlin təxminən otuz sətrini görür. Ona real ölçünü de:
<table aria-rowcount="5001">
<thead>
<tr aria-rowindex="1">
<th scope="col">Date</th>
<th scope="col">Merchant</th>
</tr>
</thead>
<tbody>
<tr aria-hidden="true" style="height: 880px"></tr>
<tr aria-rowindex="24">
<td>2026-11-02</td>
<td><a href="#/transactions/t-4023">Coffee Corner</a></td>
</tr>
<tr aria-rowindex="25">
<td>2026-11-02</td>
<td><a href="#/transactions/t-4024">City Books</a></td>
</tr>
</tbody>
</table>table/gridüzərindəkiaria-rowcountbütöv cədvəldəki sətirlərin sayıdır, başlıq sətri də daxil;-1sayın bilinmədiyini bildirir.- Render olunan hər sətirdəki
aria-rowindexonun bütöv cədvəldəki mövqeyidir və 1-dən başlayır. Burada 22 sətir ötürülüb (sətri 40 px olmaqla 880 px spacer), ona görə də render olunan ilk data sətri başlıqdan sonra 24-cü sətirdir. - Siyahılarda, option-larda və feed article-larında hər elementə
aria-setsizevəaria-posinsetyaz. - Spacer elementlərini
aria-hidden="true"ilə gizlət.
Klaviatura fokusu
İstifadəçi Tab ilə 40-cı sətirdəki linkə keçir, sonra təkərlə scroll edir. 40-cı sətir pəncərədən çıxıb unmount olur, fokuslanmış element yox olur və fokus <body>-yə düşür: növbəti Tab yenidən səhifənin başından başlayır. Həll yolları:
- Fokuslanmış sətri aralıqdan kənarda olsa da render etməyə davam et (TanStack-ın
rangeExtractor-u onun indeksini əlavə edə bilər). - Və ya grid şablonundan istifadə et: cədvəl üçün bir Tab dayanacağı, aktiv sətri ox düymələri dəyişir, kod isə həmin sətri fokuslamazdan əvvəl onu görünən sahəyə gətirir (
scrollToIndex).
Yalnız DOM-u görən digər şeylər
#order-123 kimi səhifədaxili linklər, çap, crawler-lər və testlər: jsdom-da layout yoxdur, viewport-un hündürlüyü 0-dır və virtual siyahı heç nə render etməyə bilər. Ölçünü mock et və ya aralıq məntiqini ayrıca test et.
Windowing removes rows from the DOM, and everything that works on the DOM loses them too. These costs are why windowing is a trade-off, not a free speed-up.
Find-in-page
Ctrl+F / Cmd+F finds only rendered rows. Give users a search over the data itself (a search box that filters the full array) and keep it easy to find. content-visibility: auto is the opposite trade: skipped content stays searchable.
Screen readers
Assistive technology reads the accessibility tree, built from the DOM, so it sees about thirty rows of a 10,000-row table. Tell it the real size:
<table aria-rowcount="5001">
<thead>
<tr aria-rowindex="1">
<th scope="col">Date</th>
<th scope="col">Merchant</th>
</tr>
</thead>
<tbody>
<tr aria-hidden="true" style="height: 880px"></tr>
<tr aria-rowindex="24">
<td>2026-11-02</td>
<td><a href="#/transactions/t-4023">Coffee Corner</a></td>
</tr>
<tr aria-rowindex="25">
<td>2026-11-02</td>
<td><a href="#/transactions/t-4024">City Books</a></td>
</tr>
</tbody>
</table>aria-rowcounton thetable/gridis the number of rows in the full table, header included;-1means unknown.aria-rowindexon each rendered row is its position in the full table, starting at 1. Here 22 rows are skipped (880 px of spacer at 40 px a row), so the first data row rendered is row 24 after the header.- For lists, options and feed articles use
aria-setsizeandaria-posinseton every item. - Hide spacer elements with
aria-hidden="true".
Keyboard focus
A user tabs to a link in row 40 and then scrolls with the wheel. Row 40 leaves the window and unmounts, the focused element is gone, and focus falls back to <body>: the next Tab starts again from the top of the page. Fixes:
- Keep the focused row rendered even outside the range (TanStack's
rangeExtractorcan add its index). - Or use the grid pattern: one tab stop for the table, arrow keys move the active row, and the code scrolls that row into view (
scrollToIndex) before focusing it.
Other things that only see the DOM
In-page links to #order-123, printing, crawlers and tests: in jsdom there is no layout, the viewport height is 0, and a virtualized list may render nothing. Mock the size or test the range logic separately.
Alternatives: pagination, content-visibility, less data
Windowing "node-lar həddən çoxdur" probleminin cavablarından yalnız biridir. Ona əl atmazdan əvvəl istifadəçinin nəyə ehtiyacı olduğunu soruş.
Daha az yüklə və daha az render et
- Filtr, sıralama və axtarışı serverdə et. Brauzerdə filtrləmək üçün bütün qeydləri yükləmək render başlamamış şəbəkəyə, yaddaşa və parse-a xərc çıxarır; limitli server sorğusu yalnız istifadəçinin baxa biləcəyini göndərir.
- Səhifələmə. Kiçik DOM, sabit URL-lər (
?page=3və ya cursor), səhifədə axtarış həmin səhifə daxilində işləyir, back düyməsi lazımi yerə qaytarır. Qiyməti: hər şeyi fasiləsiz gözdən keçirmək olmur. Bəzi məhsullara isə bir fasiləsiz siyahı lazımdır və onda səhifələmə seçim deyil. - Daha ucuz sətirlər. Sətir başına daha az sarğı elementi, sadə selector-lar, sütun enləri hər xanadan asılı olmasın deyə
table-layout: fixed.
content-visibility: auto
.post {
content-visibility: auto;
contain-intrinsic-size: auto 320px;
}Brauzer istifadəçi üçün aktual olmayan (ekrandan kənar) elementlərin məzmunu üçün style, layout və paint işini ötürür və onlar yaxınlaşanda render edir. Windowing-dən fərqli olaraq elementlər DOM-da və accessibility tree-də qalır: səhifədə axtarış, Tab sırası və fokus adi qaydada işləyir. contain-intrinsic-size: auto 320px ötürülən elementlərə yer tutan ölçü verir; auto ilə brauzer element bir dəfə render olunandan sonra onun real ölçüsünü yadda saxlayır və scrollbar sıçramağı dayandırır.
Dəstək: content-visibility Baseline 2024-dür, 2024-cü ilin sentyabrından newly available (Chrome 85, Firefox 125, Safari 18); contain-intrinsic-size isə widely available-dır.
Onun aradan qaldırmadığı şeylər: DOM node-ları yenə yaradılır və yaddaşda qalır, React də hər yeniləmədə hər elementi render edib müqayisə edir. O, uzun sənədlər və orta ölçülü lentlər üçün uyğundur; on minlərlə elementi hər hərfdə yenidən render olunan cədvələ isə kömək etmir.
Praktik qayda
- Bir neçə yüz sadə sətir: hamısını render et, sonra ölç.
- Yuxarıdan aşağı oxunan uzun səhifə:
content-visibility: auto. - Minlərlə sətir, tez-tez yeniləmə və ya sonsuz böyüyən siyahı: windowing, üstəlik əvvəlki bölmədəki əlçatanlıq işi.
- İstifadəçi mövqeyə görə gəzir və ya nəticələrə link paylaşır: səhifələmə.
- Hər halda: göstərməyəcəyin datanı yükləmə.
Windowing is one answer to "too many nodes". Before reaching for it, ask what the user needs.
Load and render less
- Filter, sort and search on the server. Downloading every record to filter it in the browser costs network, memory and parsing before rendering even starts; a server query with a limit sends what the user can look at.
- Pagination. Small DOM, stable URLs (
?page=3or a cursor), find-in-page works on the page, and the back button lands where it should. The cost: no continuous scan through everything. Some products need one continuous list, and then pagination is not an option. - Cheaper rows. Fewer wrapper elements per row, simple selectors,
table-layout: fixedso column widths do not depend on every cell.
content-visibility: auto
.post {
content-visibility: auto;
contain-intrinsic-size: auto 320px;
}The browser skips style, layout and paint for the contents of elements that are not relevant to the user (off-screen), and renders them when they come near. Unlike windowing, the elements stay in the DOM and the accessibility tree: find-in-page, tab order and focus work as normal. contain-intrinsic-size: auto 320px gives skipped elements a placeholder size; with auto the browser remembers the real size once an element has been rendered, so the scrollbar stops jumping.
Support: content-visibility is Baseline 2024, newly available since September 2024 (Chrome 85, Firefox 125, Safari 18); contain-intrinsic-size is widely available.
What it does not remove: the DOM nodes are still created and kept in memory, and React still renders and compares every item on each update. It suits long documents and moderate feeds; it does not help a table whose tens of thousands of elements are re-rendered on every keystroke.
A rule of thumb
- A few hundred simple rows: render them all, then measure.
- A long page read from top to bottom:
content-visibility: auto. - Thousands of rows, frequent updates, or a list that grows without end: windowing, with the accessibility work from the previous section.
- Users navigate by position or share links to results: pagination.
- In every case: do not download what you will not show.
Interview tips
30 saniyəlik cavab. "Hər DOM node-unun yaradılma, style, layout və yaddaş xərci var, React-də isə hər sətir yeniləmələrdə yenidən render olunur. Windowing yalnız viewport-dakı sətirləri və overscan-ı bütün siyahı qədər hündür spacer-in içində render edir, ona görə də DOM-un ölçüsü sabit qalır. Sabit hündürlükdə aralıq floor(scrollTop / h)-dan ceil((scrollTop + height) / h)-a qədərdir; dəyişən hündürlükdə isə təxmin edirsən, ölçürsən, key-ə görə cache-də saxlayırsan və scroll mövqeyini düzəldirsən."
Gözlənilən suallar
- Virtual siyahı yaz. Overscan və məhdudlaşdırma ilə aralıq riyaziyyatını, spacer-i yaz, sətirlərə id ilə key ver. Viewport-u ölçməyi və state-i yalnız aralıq dəyişəndə yeniləməyi qeyd et.
- Sətirlərin hündürlüyü fərqlidir. Prefiks cəmlər və binary search, təxmini ölçülər, key-ə görə cache-lənən
ResizeObserverölçmələri və viewport-dan yuxarıdakı sətirlər üçün scroll düzəlişi. - Sonsuz lent dizayn et.
rootMargin-li IntersectionObserver sentinel-i, cursor ilə səhifələmə, uzun sessiyalar üçün virtualizasiya,role="feed", geri qayıdanda scroll-un bərpası. - Bu cədvəl niyə yavaşdır? Əvvəlcə ölç: Performance paneli, DOM ölçüsü, React Profiler. Datanın emalına olduğu kimi render-ə də baxdığını göstər.
Bal itirdən səhvlər
- 50 elementlik siyahını virtualizasiya etmək və ya nə qədər data yüklədiyini yoxlamadan ona əl atmaq.
- Görünən kəsikdəki indeksi key kimi istifadə etmək.
- Əlçatanlığın qiymətini unutmaq: səhifədə axtarış,
aria-rowcount/aria-rowindexvə yaaria-setsize/aria-posinset, unmount olan sətirlərdəki fokus. content-visibilityilə windowing-i eyni şey saymaq: biri DOM-u saxlayıb render işini ötürür, digəri node-ları silir.- Siyahı qısalandan sonra aralığı məhdudlaşdırmamaq.
Senior səviyyəni göstərən məqamlar
Trade-off-lar və rəqəmlərlə danış: hansı DOM büdcəsini qoyduğunu, onu CI-da necə yoxladığını (yükləmədən sonra element sayı, yazarkən uzun task-lar), bu məhsul üçün niyə səhifələmə yox, windowing seçdiyini, axtarışı, ekran oxuyucuları və back düyməsini necə işlək saxladığını izah et.
Platformada məşq
"Sifarişlər cədvəli donur" (orders-unvirtualized) insidenti, həmçinin "Sonsuz xəbər lenti" (infinite-feed) və "Analitika dashboard-u" (analytics-dashboard) dizayn tapşırıqları.
A 30-second answer. "Every DOM node costs creation, style, layout and memory, and in React every row is also re-rendered on updates. Windowing renders only the rows in the viewport plus overscan inside a spacer as tall as the whole list, so the DOM stays constant. With fixed heights the range is floor(scrollTop / h) to ceil((scrollTop + height) / h); with variable heights you estimate, measure, cache by key and correct the scroll position."
Questions you are likely to get
- Implement a virtual list. Write the range math with overscan and clamping, the spacer, and key rows by id. Mention measuring the viewport and updating state only when the range changes.
- Rows have different heights. Prefix sums plus binary search, estimates,
ResizeObservermeasurements cached by key, and scroll correction for rows above the viewport. - Design an infinite feed. IntersectionObserver sentinel with a
rootMargin, cursor pagination, virtualization for long sessions,role="feed", scroll restoration on back. - Why is this table slow? Measure first: Performance panel, DOM size, React Profiler. Show that you look at the rendering as well as at the data work.
Mistakes that cost points
- Virtualizing a list of 50 items, or reaching for it before checking how much data you load.
- Using the index in the visible slice as the key.
- Forgetting the accessibility costs: find-in-page,
aria-rowcount/aria-rowindexoraria-setsize/aria-posinset, focus on rows that unmount. - Believing
content-visibilityand windowing are the same: one keeps the DOM and skips rendering work, the other removes nodes. - Not clamping the range after the list shrinks.
Senior signal
Talk in trade-offs and numbers: the DOM budget you set, how you checked it in CI (element count after load, long tasks while typing), why you chose windowing over pagination for this product, and how you kept search, screen readers and the back button working.
Practise on the platform
The incident "The orders table freezes" (orders-unvirtualized), and the design problems "Infinite news feed" (infinite-feed) and "Analytics dashboard" (analytics-dashboard).
What to check when reviewing a virtualized list
Bu yoxlama siyahısı sənin yazmadığın virtual siyahını (komanda yoldaşının pull request-ini, kitabxananın nümunəsini və ya AI assistentin təklifini) review edəndə lazımdır. Onun xətaları kiçik test datasının arxasında gizlənir və production-da üzə çıxır: başqa elementin state-ini göstərən sətirlər, boş viewport, sıçrayan məzmun, itən fokus.
- Sətirlərin key-i indeks yox, elementin sabit id-sidirmi? İndeks key-i ilə pəncərə sürüşdükcə sətrin state-i və DOM-u başqa elementə keçir. TanStack Virtual-da default key indeksdir, ona görə
getItemKey-i axtar. - DOM həqiqətən kiçik qalırmı? Aralıq viewport-un hündürlüyündən hesablanır, ona görə scroll konteynerinə sabit hündürlük və
overflow-y: autolazımdır (ya da siyahıuseWindowVirtualizerilə səhifə ilə birgə scroll olunmalıdır).document.querySelectorAll("*").length-i siyahının əvvəlində və xeyli aşağıda müqayisə et: rəqəm demək olar ki, dəyişməməlidir. - Siyahı qısalanda aralıq məhdudlaşdırılırmı? Sona qədər scroll et, sonra filtrlə cəmi bir neçə sətir saxla: viewport boş qalırsa, köhnə
scrollTopməhdudlaşdırılmayıb. - Dəyişən hündürlükdə sətirlər
ResizeObserverilə (TanStack-dameasureElement) ölçülür və key-ə görə cache-lənirmi? Style yazan dövrün içindəgetBoundingClientRect()hər sətir üçün bir yaradır. Viewport-dan yuxarıdakı sətrin ölçüsü dəyişəndəscrollTopda həmin fərq qədər sürüşməlidir, yoxsa məzmun sıçrayır. - Scroll zamanı klaviatura fokusu qalırmı? Tab ilə linkə keç, təkərlə onun sətrini görünən sahədən çıxar, yenidən Tab bas. Fokus səhifənin başından başlayırsa, sətir unmount olub; onu render etməyə davam et (TanStack-ın
rangeExtractor-u). - Ekran oxuyucular və axtarış bütün siyahıya çata bilirmi?
aria-rowcountvəaria-rowindex(siyahılardaaria-setsizevəaria-posinset) vəaria-hiddenspacer-lər olmalıdır. Ctrl+F yalnız render olunan sətirləri tapır, ona görə datanın özü üzrə axtarış təklif et.
Use this list when you review a virtualized list you did not write (a teammate's pull request, a library's example or an AI assistant's suggestion). Its bugs hide behind small test data and show up in production: rows with another item's state, a blank viewport, content that jumps, lost focus.
- Are rows keyed by a stable item id, not by index? With index keys, a row's state and DOM pass to another item as the window moves. TanStack Virtual's default key is the index, so look for
getItemKey. - Does the DOM really stay small? The range comes from the viewport's height, so the scroll container needs a fixed height and
overflow-y: auto(or the list scrolls with the page viauseWindowVirtualizer). Comparedocument.querySelectorAll("*").lengthat the top and far down: it should barely change. - Is the range clamped when the list gets shorter? Scroll to the bottom, then filter down to a few rows: a blank viewport means the old
scrollTopwas not clamped. - With variable heights, are rows measured by a
ResizeObserver(TanStack'smeasureElement) and cached by key?getBoundingClientRect()in a loop that writes styles forces a per row. When a row above the viewport changes size,scrollTopmust shift by that amount, or the content jumps. - Does keyboard focus survive scrolling? Tab to a link, scroll its row away with the wheel, press Tab. If focus restarts at the top of the page, the row was unmounted; keep it rendered (TanStack's
rangeExtractor). - Can screen readers and search reach the whole list? Look for
aria-rowcountandaria-rowindex(in lists,aria-setsizeandaria-posinset) andaria-hiddenspacers. Ctrl+F finds only rendered rows, so offer a search over the data.
Check your understanding
Practise this
Hands-on work that uses this topic.