Skip to content

Commit d939a83

Browse files
hakankosdagzombieJ
andauthored
fix: add mergedData length check (#306)
* fix: add mergedData length check * chore: check first --------- Co-authored-by: 二货机器人 <[email protected]>
1 parent 66e8450 commit d939a83

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/List.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,17 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
279279
const changedRecord = heights.getRecord();
280280
if (changedRecord.size === 1) {
281281
const recordKey = Array.from(changedRecord)[0];
282-
const startIndexKey = getKey(mergedData[start]);
283-
if (startIndexKey === recordKey) {
284-
const realStartHeight = heights.get(recordKey);
285-
const diffHeight = realStartHeight - itemHeight;
286-
syncScrollTop((ori) => {
287-
return ori + diffHeight;
288-
});
282+
// Quick switch data may cause `start` not in `mergedData` anymore
283+
const startItem = mergedData[start];
284+
if (startItem) {
285+
const startIndexKey = getKey(startItem);
286+
if (startIndexKey === recordKey) {
287+
const realStartHeight = heights.get(recordKey);
288+
const diffHeight = realStartHeight - itemHeight;
289+
syncScrollTop((ori) => {
290+
return ori + diffHeight;
291+
});
292+
}
289293
}
290294
}
291295

0 commit comments

Comments
 (0)