Skip to content

Commit

Permalink
Fix FillRateHelper Accessing -1 Frame
Browse files Browse the repository at this point in the history
Summary:
FillRateHelper accesses frame metrics based on passed state/cellsAroundViewport on scroll. cellsAroundViewport may be [0, -1] for no items. Usually this is captured by the check that item count is zero, but it is possible to have items without yet expanding state to render the items. This adds a check to bail early if we are not yet rendering any viewport-related cells.

Also renamed "state" to "cellsAroundViewport" for more consistent naming with the new list, where it is no longer the only state.

Reviewed By: javache

Differential Revision: D39345705

fbshipit-source-id: 198ab46ff2c8e8fe64076c9150edd4914dd745d7
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 8, 2022
1 parent e7d7563 commit 0526176
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Libraries/Lists/FillRateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class FillRateHelper {
initialNumToRender?: ?number,
...
},
state: {
cellsAroundViewport: {
first: number,
last: number,
...
Expand All @@ -158,6 +158,7 @@ class FillRateHelper {
if (
!this._enabled ||
props.getItemCount(props.data) === 0 ||
cellsAroundViewport.last < cellsAroundViewport.first ||
this._samplesStartTime == null
) {
return 0;
Expand All @@ -183,9 +184,12 @@ class FillRateHelper {
this._mostlyBlankStartTime = null;

let blankTop = 0;
let first = state.first;
let first = cellsAroundViewport.first;
let firstFrame = this._getFrameMetrics(first, props);
while (first <= state.last && (!firstFrame || !firstFrame.inLayout)) {
while (
first <= cellsAroundViewport.last &&
(!firstFrame || !firstFrame.inLayout)
) {
firstFrame = this._getFrameMetrics(first, props);
first++;
}
Expand All @@ -198,9 +202,12 @@ class FillRateHelper {
);
}
let blankBottom = 0;
let last = state.last;
let last = cellsAroundViewport.last;
let lastFrame = this._getFrameMetrics(last, props);
while (last >= state.first && (!lastFrame || !lastFrame.inLayout)) {
while (
last >= cellsAroundViewport.first &&
(!lastFrame || !lastFrame.inLayout)
) {
lastFrame = this._getFrameMetrics(last, props);
last--;
}
Expand Down

0 comments on commit 0526176

Please sign in to comment.