Skip to content

Commit cab865b

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Fix VirtualizedList usage of potentially stale state on cell focus
Summary: State updates can be batched together idependent of `this.state`, so we should do any calculation deriving state from state within a `setState()` callback. This fixes a bug where we were relying on potentially stale state, a RenderMask derived from `this.state` instead of the `state` callback parameter, when triggering updates from focus. Note that this is not exercised on Android/iOS, but it on desktop/web. I noticed this a while back while making another change, but that change got abandoned, so this is the independent fix. Changelog: [General][Fixed] - Calculate VirtualizedList render mask for focused cell during batched state updates Reviewed By: javache Differential Revision: D43073415 fbshipit-source-id: dee4197ec925a6d8d427b63fb063aa4e3b58c595
1 parent 1058bb8 commit cab865b

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

packages/virtualized-lists/Lists/VirtualizedList.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,18 +1229,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
12291229

12301230
_onCellFocusCapture(cellKey: string) {
12311231
this._lastFocusedCellKey = cellKey;
1232-
const renderMask = VirtualizedList._createRenderMask(
1233-
this.props,
1234-
this.state.cellsAroundViewport,
1235-
this._getNonViewportRenderRegions(this.props),
1236-
);
1237-
1238-
this.setState(state => {
1239-
if (!renderMask.equals(state.renderMask)) {
1240-
return {renderMask};
1241-
}
1242-
return null;
1243-
});
1232+
this._updateCellsToRender();
12441233
}
12451234

12461235
_onCellUnmount = (cellKey: string) => {

0 commit comments

Comments
 (0)