Skip to content

Commit c40a938

Browse files
sahrensgrabbou
authored andcommitted
Fix infinite setState in VirtualizedList
Reviewed By: larrylin28 Differential Revision: D14990686 fbshipit-source-id: 632fa0e4e11feff9dcfb4ac62ba8bc7a6c0393a5
1 parent 84e2636 commit c40a938

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,19 @@ class VirtualizedList extends React.PureComponent<Props, State> {
982982
tuple.viewabilityHelper.resetViewableIndices();
983983
});
984984
}
985+
// The `this._hiPriInProgress` is guaranteeing a hiPri cell update will only happen
986+
// once per fiber update. The `_scheduleCellsToRenderUpdate` will set it to true
987+
// if a hiPri update needs to perform. If `componentDidUpdate` is triggered with
988+
// `this._hiPriInProgress=true`, means it's triggered by the hiPri update. The
989+
// `_scheduleCellsToRenderUpdate` will check this condition and not perform
990+
// another hiPri update.
991+
const hiPriInProgress = this._hiPriInProgress;
985992
this._scheduleCellsToRenderUpdate();
993+
// Make sure setting `this._hiPriInProgress` back to false after `componentDidUpdate`
994+
// is triggered with `this._hiPriInProgress = true`
995+
if (hiPriInProgress) {
996+
this._hiPriInProgress = false;
997+
}
986998
}
987999

9881000
_averageCellLength = 0;
@@ -993,13 +1005,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
9931005
_frames = {};
9941006
_footerLength = 0;
9951007
_hasDataChangedSinceEndReached = true;
1008+
_hasDoneInitialScroll = false;
9961009
_hasInteracted = false;
9971010
_hasMore = false;
9981011
_hasWarned = {};
999-
_highestMeasuredFrameIndex = 0;
10001012
_headerLength = 0;
1013+
_hiPriInProgress: boolean = false; // flag to prevent infinite hiPri cell limit update
1014+
_highestMeasuredFrameIndex = 0;
10011015
_indicesToKeys: Map<number, string> = new Map();
1002-
_hasDoneInitialScroll = false;
10031016
_nestedChildLists: Map<
10041017
string,
10051018
{ref: ?VirtualizedList, state: ?ChildListState},
@@ -1422,7 +1435,10 @@ class VirtualizedList extends React.PureComponent<Props, State> {
14221435
// Otherwise, it would just render as many cells as it can (of zero dimension),
14231436
// each time through attempting to render more (limited by maxToRenderPerBatch),
14241437
// starving the renderer from actually laying out the objects and computing _averageCellLength.
1425-
if (hiPri && this._averageCellLength) {
1438+
// If this is triggered in an `componentDidUpdate` followed by a hiPri cellToRenderUpdate
1439+
// We shouldn't do another hipri cellToRenderUpdate
1440+
if (hiPri && this._averageCellLength && !this._hiPriInProgress) {
1441+
this._hiPriInProgress = true;
14261442
// Don't worry about interactions when scrolling quickly; focus on filling content as fast
14271443
// as possible.
14281444
this._updateCellsToRenderBatcher.dispose({abort: true});

0 commit comments

Comments
 (0)