Skip to content

Commit

Permalink
Attempt fix #2 for cellsAroundViewport reaching out of bounds
Browse files Browse the repository at this point in the history
Summary: VirtualizedList would more gracefully handle out of range cells than VirtualizedList_EXPERIMENTAL, which treats it as an invariant violation. D39244112 (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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 8, 2022
1 parent f44dfef commit 0ef7705
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Libraries/Lists/VirtualizedList_EXPERIMENTAL.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
// Wait until the scroll view metrics have been set up. And until then,
// we will trust the initialNumToRender suggestion
if (visibleLength <= 0 || contentLength <= 0) {
return cellsAroundViewport;
return cellsAroundViewport.last >= getItemCount(data)
? VirtualizedList._constrainToItemCount(cellsAroundViewport, props)
: cellsAroundViewport;
}

let newCellsAroundViewport: {first: number, last: number};
Expand Down Expand Up @@ -654,6 +656,10 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
this.__getFrameMetricsApprox,
this._scrollMetrics,
);
invariant(
newCellsAroundViewport.last < getItemCount(data),
'computeWindowedRenderLimits() should return range in-bounds',
);
}

if (this._nestedChildLists.size > 0) {
Expand Down

0 comments on commit 0ef7705

Please sign in to comment.