Skip to content

Commit 88787b5

Browse files
sahrensfacebook-github-bot
authored andcommittedApr 23, 2019
Fix infinite setState in VirtualizedList
Reviewed By: larrylin28 Differential Revision: D14990686 fbshipit-source-id: 632fa0e4e11feff9dcfb4ac62ba8bc7a6c0393a5
1 parent c0efa16 commit 88787b5

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed
 

‎Libraries/Lists/VirtualizedList.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,19 @@ class VirtualizedList extends React.PureComponent<Props, State> {
970970
tuple.viewabilityHelper.resetViewableIndices();
971971
});
972972
}
973+
// The `this._hiPriInProgress` is guaranteeing a hiPri cell update will only happen
974+
// once per fiber update. The `_scheduleCellsToRenderUpdate` will set it to true
975+
// if a hiPri update needs to perform. If `componentDidUpdate` is triggered with
976+
// `this._hiPriInProgress=true`, means it's triggered by the hiPri update. The
977+
// `_scheduleCellsToRenderUpdate` will check this condition and not perform
978+
// another hiPri update.
979+
const hiPriInProgress = this._hiPriInProgress;
973980
this._scheduleCellsToRenderUpdate();
981+
// Make sure setting `this._hiPriInProgress` back to false after `componentDidUpdate`
982+
// is triggered with `this._hiPriInProgress = true`
983+
if (hiPriInProgress) {
984+
this._hiPriInProgress = false;
985+
}
974986
}
975987

976988
_averageCellLength = 0;
@@ -981,13 +993,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
981993
_frames = {};
982994
_footerLength = 0;
983995
_hasDataChangedSinceEndReached = true;
996+
_hasDoneInitialScroll = false;
984997
_hasInteracted = false;
985998
_hasMore = false;
986999
_hasWarned = {};
987-
_highestMeasuredFrameIndex = 0;
9881000
_headerLength = 0;
1001+
_hiPriInProgress: boolean = false; // flag to prevent infinite hiPri cell limit update
1002+
_highestMeasuredFrameIndex = 0;
9891003
_indicesToKeys: Map<number, string> = new Map();
990-
_hasDoneInitialScroll = false;
9911004
_nestedChildLists: Map<
9921005
string,
9931006
{ref: ?VirtualizedList, state: ?ChildListState},
@@ -1411,7 +1424,10 @@ class VirtualizedList extends React.PureComponent<Props, State> {
14111424
// Otherwise, it would just render as many cells as it can (of zero dimension),
14121425
// each time through attempting to render more (limited by maxToRenderPerBatch),
14131426
// starving the renderer from actually laying out the objects and computing _averageCellLength.
1414-
if (hiPri && this._averageCellLength) {
1427+
// If this is triggered in an `componentDidUpdate` followed by a hiPri cellToRenderUpdate
1428+
// We shouldn't do another hipri cellToRenderUpdate
1429+
if (hiPri && this._averageCellLength && !this._hiPriInProgress) {
1430+
this._hiPriInProgress = true;
14151431
// Don't worry about interactions when scrolling quickly; focus on filling content as fast
14161432
// as possible.
14171433
this._updateCellsToRenderBatcher.dispose({abort: true});

0 commit comments

Comments
 (0)
Please sign in to comment.