Skip to content

Commit cf17381

Browse files
2wheehclaude
andcommitted
test(virtual-core): add incremental measurement test for deferLaneAssignment
Verify that lane assignments are cached progressively as items are measured and that earlier cached lanes remain stable when later items are measured. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e71a42b commit cf17381

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

packages/virtual-core/tests/index.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,43 @@ test('should defer lane caching until measurement when deferLaneAssignment is tr
270270
expect(lanesBeforeResize).toEqual(lanesAfterResize)
271271
})
272272

273+
test('should cache lanes incrementally as items are measured with deferLaneAssignment', () => {
274+
const virtualizer = new Virtualizer({
275+
count: 4,
276+
lanes: 2,
277+
estimateSize: () => 100,
278+
deferLaneAssignment: true,
279+
getScrollElement: () => null,
280+
scrollToFn: vi.fn(),
281+
observeElementRect: vi.fn(),
282+
observeElementOffset: vi.fn(),
283+
})
284+
285+
virtualizer['getMeasurements']()
286+
expect(virtualizer['laneAssignments'].size).toBe(0)
287+
288+
// Measure only the first 2 items (simulating viewport-visible items)
289+
virtualizer.resizeItem(0, 200)
290+
virtualizer.resizeItem(1, 50)
291+
292+
const m1 = virtualizer['getMeasurements']()
293+
expect(virtualizer['laneAssignments'].size).toBe(2)
294+
295+
const lane0 = m1[0].lane
296+
const lane1 = m1[1].lane
297+
298+
// Measure the remaining items
299+
virtualizer.resizeItem(2, 80)
300+
virtualizer.resizeItem(3, 120)
301+
302+
const m2 = virtualizer['getMeasurements']()
303+
expect(virtualizer['laneAssignments'].size).toBe(4)
304+
305+
// Previously cached lanes must remain stable
306+
expect(m2[0].lane).toBe(lane0)
307+
expect(m2[1].lane).toBe(lane1)
308+
})
309+
273310
test('should cache lanes immediately when deferLaneAssignment is false (default)', () => {
274311
const virtualizer = new Virtualizer({
275312
count: 4,

0 commit comments

Comments
 (0)