Skip to content

Commit 5dbf204

Browse files
committed
fixing estimated loader position if sections exist
taken from #8326
1 parent 1b4b7b5 commit 5dbf204

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/@react-stately/layout/src/ListLayout.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
262262
y = 0;
263263
}
264264

265-
for (let node of collection) {
265+
for (let node of collectionNodes) {
266266
let rowHeight = (this.rowHeight ?? this.estimatedRowHeight ?? DEFAULT_HEIGHT) + this.gap;
267267
// Skip rows before the valid rectangle unless they are already cached.
268268
if (node.type === 'item' && y + rowHeight < this.requestedRect.y && !this.isValid(node, y)) {
@@ -279,12 +279,13 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
279279
}
280280

281281
// Build each loader that exists in the collection that is outside the visible rect so that they are persisted
282-
// at the proper estimated location
283-
if (y > this.requestedRect.maxY) {
282+
// at the proper estimated location. If the node.type is "section" then we don't do this shortcut since we have to
283+
// build the sections to see how tall they are.
284+
if ((node.type === 'item' || node.type === 'loader') && y > this.requestedRect.maxY) {
284285
let lastProcessedIndex = collectionNodes.indexOf(node);
285286
for (let loaderNode of loaderNodes) {
286287
let loaderNodeIndex = collectionNodes.indexOf(loaderNode);
287-
// Subtract by an addition 1 since we've already added the current item's height to y
288+
// Subtract by an additional 1 since we've already added the current item's height to y
288289
y += (loaderNodeIndex - lastProcessedIndex - 1) * rowHeight;
289290
let loader = this.buildChild(loaderNode, this.padding, y, null);
290291
nodes.push(loader);

0 commit comments

Comments
 (0)