diff --git a/src/List.tsx b/src/List.tsx index 9afe3bfb..0da61f32 100644 --- a/src/List.tsx +++ b/src/List.tsx @@ -279,13 +279,17 @@ export function RawList(props: ListProps, ref: React.Ref) { const changedRecord = heights.getRecord(); if (changedRecord.size === 1) { const recordKey = Array.from(changedRecord)[0]; - const startIndexKey = getKey(mergedData[start]); - if (startIndexKey === recordKey) { - const realStartHeight = heights.get(recordKey); - const diffHeight = realStartHeight - itemHeight; - syncScrollTop((ori) => { - return ori + diffHeight; - }); + // Quick switch data may cause `start` not in `mergedData` anymore + const startItem = mergedData[start]; + if (startItem) { + const startIndexKey = getKey(startItem); + if (startIndexKey === recordKey) { + const realStartHeight = heights.get(recordKey); + const diffHeight = realStartHeight - itemHeight; + syncScrollTop((ori) => { + return ori + diffHeight; + }); + } } }