File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -277,15 +277,19 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
277
277
// Let's sync scroll top to avoid jump
278
278
React . useLayoutEffect ( ( ) => {
279
279
const changedRecord = heights . getRecord ( ) ;
280
- if ( changedRecord . size === 1 && mergedData . length > 0 ) {
280
+ if ( changedRecord . size === 1 ) {
281
281
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
+ }
289
293
}
290
294
}
291
295
You can’t perform that action at this time.
0 commit comments