From 36c53a4b3b41fa85629bce6c9f7609281a49b4f3 Mon Sep 17 00:00:00 2001 From: Jeongmin Woo Date: Fri, 28 Mar 2025 15:36:23 +0900 Subject: [PATCH 1/3] fix(virtual-core): fix total size calculation for single item in multi-lane --- packages/virtual-core/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index b3b4a90d5..6ba08ab77 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -1046,7 +1046,7 @@ export class Virtualizer< } else { const endByLane = Array(this.options.lanes).fill(null) let endIndex = measurements.length - 1 - while (endIndex > 0 && endByLane.some((val) => val === null)) { + while (endIndex >= 0 && endByLane.some((val) => val === null)) { const item = measurements[endIndex]! if (endByLane[item.lane] === null) { endByLane[item.lane] = item.end From 3a9149f200d541fcccbb4bdea590e6521ba7b704 Mon Sep 17 00:00:00 2001 From: Jeongmin Woo Date: Sat, 29 Mar 2025 00:44:35 +0900 Subject: [PATCH 2/3] test(virtual-core): add test for total size with one item in multi-lane layout Refs #963 --- packages/virtual-core/tests/index.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/virtual-core/tests/index.test.ts b/packages/virtual-core/tests/index.test.ts index 35430a57e..12b49ffd5 100644 --- a/packages/virtual-core/tests/index.test.ts +++ b/packages/virtual-core/tests/index.test.ts @@ -16,3 +16,16 @@ test('should return empty items for empty scroll element', () => { }) expect(virtualizer.getVirtualItems()).toEqual([]) }) + +test('should return correct total size with one item and multiple lanes', () => { + const virtualizer = new Virtualizer({ + count: 1, + lanes: 2, + estimateSize: () => 50, + getScrollElement: () => null, + scrollToFn: vi.fn(), + observeElementRect: vi.fn(), + observeElementOffset: vi.fn(), + }) + expect(virtualizer.getTotalSize()).toBe(50) +}) From d82f15fff57ff8d265fab430a058a7ff40cd1be3 Mon Sep 17 00:00:00 2001 From: Jeongmin Woo Date: Sat, 29 Mar 2025 00:59:59 +0900 Subject: [PATCH 3/3] fix(virtual-core): fix loop condition in calculateRange --- packages/virtual-core/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index 6ba08ab77..3a0c4460f 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -1162,7 +1162,7 @@ function calculateRange({ // Expand backward until we include all lanes' visible items // closer to the top const startPerLane = Array(lanes).fill(scrollOffset + outerSize) - while (startIndex > 0 && startPerLane.some((pos) => pos >= scrollOffset)) { + while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) { const item = measurements[startIndex]! startPerLane[item.lane] = item.start startIndex--