Skip to content

Commit de39cb5

Browse files
NickGerlemanOlimpiaZurek
authored andcommitted
Attempt fix facebook#2 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. D39244112 (facebook@7aa203b) attempted to fix an issue where recalculation of cells around viewport can include out of range cells, but it is still showing up later. This change adds a bounds check to the remaining branch we control, and an assertion that `computeWindowedRenderLimits` is not returing something out of range to discover if that is the cause. Reviewed By: yungsters Differential Revision: D39267445 fbshipit-source-id: 64c99da28b5b01ef61784079b586e355f73764a1
1 parent 09fe1e6 commit de39cb5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Libraries/Lists/VirtualizedList_EXPERIMENTAL.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
608608
// Wait until the scroll view metrics have been set up. And until then,
609609
// we will trust the initialNumToRender suggestion
610610
if (visibleLength <= 0 || contentLength <= 0) {
611-
return cellsAroundViewport;
611+
return cellsAroundViewport.last >= getItemCount(data)
612+
? VirtualizedList._constrainToItemCount(cellsAroundViewport, props)
613+
: cellsAroundViewport;
612614
}
613615

614616
let newCellsAroundViewport: {first: number, last: number};
@@ -654,6 +656,10 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
654656
this.__getFrameMetricsApprox,
655657
this._scrollMetrics,
656658
);
659+
invariant(
660+
newCellsAroundViewport.last < getItemCount(data),
661+
'computeWindowedRenderLimits() should return range in-bounds',
662+
);
657663
}
658664

659665
if (this._nestedChildLists.size > 0) {

0 commit comments

Comments
 (0)