Skip to content

Commit 776fe7a

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Bail on realizing region around last focused cell if we don't know where it is (#36541)
Summary: Pull Request resolved: #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`](#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 Reviewed By: yungsters Differential Revision: D44221162 fbshipit-source-id: 8fc7e726fe13c62b98870600563857bb89290280
1 parent aab4763 commit 776fe7a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/virtualized-lists/Lists/VirtualizedList.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,19 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
18861886
const focusedCellIndex = lastFocusedCellRenderer.props.index;
18871887
const itemCount = props.getItemCount(props.data);
18881888

1889+
// The last cell we rendered may be at a new index. Bail if we don't know
1890+
// where it is.
1891+
if (
1892+
focusedCellIndex >= itemCount ||
1893+
this._keyExtractor(
1894+
props.getItem(props.data, focusedCellIndex),
1895+
focusedCellIndex,
1896+
props,
1897+
) !== this._lastFocusedCellKey
1898+
) {
1899+
return [];
1900+
}
1901+
18891902
let first = focusedCellIndex;
18901903
let heightOfCellsBeforeFocused = 0;
18911904
for (

0 commit comments

Comments
 (0)