From 47cf909f74e517bf2a56b8d40ce4a640686cf201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20Schr=C3=B6ter?= Date: Fri, 27 Mar 2026 19:58:28 +0100 Subject: [PATCH 1/2] chore: review --- .../react-aria-components/stories/utils.tsx | 2 +- packages/react-stately/src/layout/ListLayout.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/react-aria-components/stories/utils.tsx b/packages/react-aria-components/stories/utils.tsx index 581fb6506f1..5d5562e3e23 100644 --- a/packages/react-aria-components/stories/utils.tsx +++ b/packages/react-aria-components/stories/utils.tsx @@ -14,7 +14,7 @@ export const MyListBoxItem = (props: ListBoxItemProps) => { return ( classNames(styles, 'item', { focused: isFocused, selected: isSelected, diff --git a/packages/react-stately/src/layout/ListLayout.ts b/packages/react-stately/src/layout/ListLayout.ts index 2fd0a574f5a..8886bb49711 100644 --- a/packages/react-stately/src/layout/ListLayout.ts +++ b/packages/react-stately/src/layout/ListLayout.ts @@ -132,27 +132,27 @@ export class ListLayout exte } getVisibleLayoutInfos(rect: Rect): LayoutInfo[] { - let visibleRect = rect.copy(); let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y'; let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height'; // Adjust rect to keep number of visible rows consistent. // (only if height > 1 or width > 1 for getDropTargetFromPoint) - if (visibleRect[heightProperty] > 1) { + if (rect[heightProperty] > 1) { let rowHeight = (this.rowHeight ?? this.estimatedRowHeight ?? DEFAULT_HEIGHT) + this.gap; - visibleRect[offsetProperty] = Math.floor(visibleRect[offsetProperty] / rowHeight) * rowHeight; - visibleRect[heightProperty] = Math.ceil(visibleRect[heightProperty] / rowHeight) * rowHeight; + rect = rect.copy(); + rect[offsetProperty] = Math.floor(rect[offsetProperty] / rowHeight) * rowHeight; + rect[heightProperty] = Math.ceil(rect[heightProperty] / rowHeight) * rowHeight; } // If layout hasn't yet been done for the requested rect, union the // new rect with the existing valid rect, and recompute. - this.layoutIfNeeded(visibleRect); + this.layoutIfNeeded(rect); let res: LayoutInfo[] = []; let addNodes = (nodes: LayoutNode[]) => { for (let node of nodes) { - if (this.isVisible(node, visibleRect)) { + if (this.isVisible(node, rect)) { res.push(node.layoutInfo); if (node.children) { @@ -271,6 +271,9 @@ export class ListLayout exte protected buildCollection(offset: number = this.padding): LayoutNode[] { let collection = this.virtualizer!.collection; + let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y'; + let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY'; + // filter out content nodes since we don't want them to affect the height // Tree specific for now, if we add content nodes to other collection items, we might need to reconsider this let collectionNodes = toArray(collection, (node) => node.type !== 'content'); @@ -282,8 +285,6 @@ export class ListLayout exte } for (let node of collectionNodes) { - let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y'; - let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY'; let rowHeight = (this.rowHeight ?? this.estimatedRowHeight ?? DEFAULT_HEIGHT) + this.gap; // Skip rows before the valid rectangle unless they are already cached. if (node.type === 'item' && offset + rowHeight < this.requestedRect[offsetProperty] && !this.isValid(node, offset)) { From 2ece1c74cf16dd50ffa9fdd7383d990032139fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20Schr=C3=B6ter?= <25958801+nwidynski@users.noreply.github.com> Date: Mon, 30 Mar 2026 11:11:49 +0200 Subject: [PATCH 2/2] chore: review --- packages/react-stately/src/layout/ListLayout.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-stately/src/layout/ListLayout.ts b/packages/react-stately/src/layout/ListLayout.ts index 8886bb49711..610e6232df8 100644 --- a/packages/react-stately/src/layout/ListLayout.ts +++ b/packages/react-stately/src/layout/ListLayout.ts @@ -139,6 +139,7 @@ export class ListLayout exte // (only if height > 1 or width > 1 for getDropTargetFromPoint) if (rect[heightProperty] > 1) { let rowHeight = (this.rowHeight ?? this.estimatedRowHeight ?? DEFAULT_HEIGHT) + this.gap; + // Clone only before mutating rect = rect.copy(); rect[offsetProperty] = Math.floor(rect[offsetProperty] / rowHeight) * rowHeight; rect[heightProperty] = Math.ceil(rect[heightProperty] / rowHeight) * rowHeight;