Fix bug caused by GroupedVirtuoso

If there are only empty groups, "computeItemKey" gets called with a none-existent index which leads to "Virtuoso.util::convertIndex" to throw an error
This commit is contained in:
schroda
2026-01-25 03:25:39 +01:00
parent 742a02c5cf
commit e63a51e060

View File

@@ -71,7 +71,7 @@ export class VirtuosoUtil {
}
}
throw new Error(`Unexpected "${index}" (${index}) and "groupCounts" (${groupCounts})`);
throw new Error(`Unexpected "index" (${index}) and "groupCounts" (${groupCounts})`);
}
static useCreateConvertIndex(
@@ -97,8 +97,15 @@ export class VirtuosoUtil {
): (index: number) => React.Key {
const convertIndex = this.useCreateConvertIndex(groupCounts);
const totalGroupItems = useMemo(() => groupCounts.reduce((acc, count) => acc + count, 0), [groupCounts]);
return useCallback(
(index) => {
// GroupedVirtuoso bug: If there are only empty groups, computeItemKey gets called with a none-existent index which leads to "convertIndex" to throw an error
if (index > groupCounts.length - 1 && totalGroupItems === 0) {
return -1;
}
const { type, index: convertedIndex, groupIndex } = convertIndex(index);
switch (type) {