@@ -120,13 +120,21 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
120120 let horizontalSpacing = Math . floor ( ( visibleWidth - numColumns * itemWidth ) / ( numColumns + 1 ) ) ;
121121 this . gap = new Size ( horizontalSpacing , minSpace . height ) ;
122122
123+ // If there is a skeleton loader within the last 2 items in the collection, increment the collection size
124+ // so that an additional row is added for the skeletons.
123125 let collection = this . virtualizer ! . collection ;
124- // Make sure to set rows to 0 if we performing a first time load or are rendering the empty state so that Virtualizer
125- // won't try to render its body. If we detect a skeleton as the first item, then we want to render the skeleton items in place of
126- // the renderEmptyState.
127- let isSkeletonLoading = collection . getItem ( collection . getFirstKey ( ) ! ) ?. type === 'skeleton' ;
128- let isEmptyOrLoading = collection ?. size === 0 && ! isSkeletonLoading ;
129- let rows = isEmptyOrLoading ? 0 : Math . ceil ( isSkeletonLoading ? 1 : collection . size / numColumns ) ;
126+ let collectionSize = collection . size ;
127+ let lastKey = collection . getLastKey ( ) ;
128+ for ( let i = 0 ; i < 2 && lastKey != null ; i ++ ) {
129+ let item = collection . getItem ( lastKey ) ;
130+ if ( item ?. type === 'skeleton' ) {
131+ collectionSize ++ ;
132+ break ;
133+ }
134+ lastKey = collection . getKeyBefore ( lastKey ) ;
135+ }
136+
137+ let rows = Math . ceil ( collectionSize / numColumns ) ;
130138 let iterator = collection [ Symbol . iterator ] ( ) ;
131139 let y = rows > 0 ? minSpace . height : 0 ;
132140 let newLayoutInfos = new Map ( ) ;
0 commit comments