Skip to content

Commit

Permalink
Fix infinite setState in VirtualizedList
Browse files Browse the repository at this point in the history
Reviewed By: larrylin28

Differential Revision: D14990686

fbshipit-source-id: 632fa0e4e11feff9dcfb4ac62ba8bc7a6c0393a5
  • Loading branch information
sahrens authored and facebook-github-bot committed Apr 23, 2019
1 parent c0efa16 commit 88787b5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,19 @@ class VirtualizedList extends React.PureComponent<Props, State> {
tuple.viewabilityHelper.resetViewableIndices();
});
}
// The `this._hiPriInProgress` is guaranteeing a hiPri cell update will only happen
// once per fiber update. The `_scheduleCellsToRenderUpdate` will set it to true
// if a hiPri update needs to perform. If `componentDidUpdate` is triggered with
// `this._hiPriInProgress=true`, means it's triggered by the hiPri update. The
// `_scheduleCellsToRenderUpdate` will check this condition and not perform
// another hiPri update.
const hiPriInProgress = this._hiPriInProgress;
this._scheduleCellsToRenderUpdate();
// Make sure setting `this._hiPriInProgress` back to false after `componentDidUpdate`
// is triggered with `this._hiPriInProgress = true`
if (hiPriInProgress) {
this._hiPriInProgress = false;
}
}

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

0 comments on commit 88787b5

Please sign in to comment.