Skip to content

Commit 7aa203b

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Attempt fix for cellsAroundViewport reaching out of bounds
Summary: VirtualizedList would more gracefully handle out of range cells than VirtualizedList_EXPERIMENTAL, which treats it as an invariant violation. This attempts to fix an issue where recalculation of cells around viewport can include out of range cells. Reviewed By: rshest Differential Revision: D39244112 fbshipit-source-id: 20fe6ea552035061d9d00720fcab77b29a785771
1 parent a50e6fb commit 7aa203b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Libraries/Lists/VirtualizeUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function computeWindowedRenderLimits(
128128
} {
129129
const itemCount = props.getItemCount(props.data);
130130
if (itemCount === 0) {
131-
return prev;
131+
return {first: 0, last: -1};
132132
}
133133
const {offset, velocity, visibleLength, zoomScale = 1} = scrollMetrics;
134134

Libraries/Lists/VirtualizedList_EXPERIMENTAL.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
641641
!this._scrollMetrics.offset &&
642642
Math.abs(distanceFromEnd) >= Number.EPSILON
643643
) {
644-
return cellsAroundViewport;
644+
return cellsAroundViewport.last >= getItemCount(data)
645+
? VirtualizedList._constrainToItemCount(cellsAroundViewport, props)
646+
: cellsAroundViewport;
645647
}
646648

647649
newCellsAroundViewport = computeWindowedRenderLimits(

0 commit comments

Comments
 (0)