From 2e734707edfbf183f818fde2d5514845177d2774 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Wed, 26 Apr 2023 14:46:46 +0300 Subject: [PATCH] fix: edge case with a single group Fixes #886 --- src/sizeSystem.ts | 3 ++- src/upwardScrollFixSystem.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sizeSystem.ts b/src/sizeSystem.ts index 9bc4a4c6d..b9fd772ed 100644 --- a/src/sizeSystem.ts +++ b/src/sizeSystem.ts @@ -459,7 +459,8 @@ export const sizeSystem = u.system( while (prependedGroupItemsCount < unshiftWith) { const theGroupIndex = sizes.groupIndices[groupIndex] - const groupItemCount = sizes.groupIndices[groupIndex + 1] - theGroupIndex - 1 + const groupItemCount = + sizes.groupIndices.length === groupIndex + 1 ? Infinity : sizes.groupIndices[groupIndex + 1] - theGroupIndex - 1 initialRanges.push({ startIndex: theGroupIndex, diff --git a/src/upwardScrollFixSystem.ts b/src/upwardScrollFixSystem.ts index 46861d398..54110b430 100644 --- a/src/upwardScrollFixSystem.ts +++ b/src/upwardScrollFixSystem.ts @@ -124,7 +124,8 @@ export const upwardScrollFixSystem = u.system( recognizedOffsetItems++ amount += defaultGroupSize - let groupItemCount = groupIndices[groupIndex + 1] - groupIndices[groupIndex] - 1 + let groupItemCount = + groupIndices.length === groupIndex + 1 ? Infinity : groupIndices[groupIndex + 1] - groupIndices[groupIndex] - 1 // if the group is larger than the offset, we have an expanded group. remove the group size, and replace with 1 item. if (recognizedOffsetItems + groupItemCount > offset) {