Skip to content

Commit

Permalink
Bail on realizing region around last focused cell if we don't know wh…
Browse files Browse the repository at this point in the history
…ere it is (facebook#36541)

Summary:
Pull Request resolved: facebook#36541

We only know where the last focused cell lives after it is rendered. Apart from dead refs handled in D43835135, this means items added or removed before the focused cell will lead to a stale last index for the next state update.

We don't have a good way to correlate cells after data change. This effects the implementation for [`maintainVisibleContentPosition`](facebook#35993) as well, but needs some thought on the right way to handle it. For now, we bail when we don't know where the last focused cell lives.

Changelog:
[General][Fixed] - Bail on realizing region around last focused cell if we don't know where it is

Differential Revision: D44221162

fbshipit-source-id: 30e842261dfc0a4a17944430c65f487fb414b4b1
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 22, 2023
1 parent cf43f9c commit 5f7cbe1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,19 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
const focusedCellIndex = lastFocusedCellRenderer.props.index;
const itemCount = props.getItemCount(props.data);

// The last cell we rendered may be at a new index. Bail if we don't know
// where it is.
if (
focusedCellIndex >= itemCount ||
this._keyExtractor(
props.getItem(props.data, focusedCellIndex),
focusedCellIndex,
props,
) !== this._lastFocusedCellKey
) {
return [];
}

let first = focusedCellIndex;
let heightOfCellsBeforeFocused = 0;
for (
Expand Down

0 comments on commit 5f7cbe1

Please sign in to comment.