diff --git a/packages/app/package.json b/packages/app/package.json index e5438261b64..2387474e386 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -17,8 +17,9 @@ "dev": "vite", "build": "vite build", "serve": "vite preview", - "test": "bun run test:unit", + "test": "bun run test:unit && bun run test:virtualizer", "test:unit": "bun test --only-failures --preload ./happydom.ts ./src", + "test:virtualizer": "bun test --conditions=browser --preload ./happydom.ts ./test-browser/solid-virtual.test.ts", "test:unit:watch": "bun test --watch --preload ./happydom.ts ./src", "test:e2e": "playwright test", "test:e2e:local": "playwright test", diff --git a/packages/app/test-browser/solid-virtual.test.ts b/packages/app/test-browser/solid-virtual.test.ts new file mode 100644 index 00000000000..01e2e6f7495 --- /dev/null +++ b/packages/app/test-browser/solid-virtual.test.ts @@ -0,0 +1,27 @@ +import { expect, test } from "bun:test" +import { createVirtualizer } from "@tanstack/solid-virtual" +import { createRoot, createSignal } from "solid-js" + +test("reactive count updates preserve measured row sizes", () => { + createRoot((dispose) => { + const [count, setCount] = createSignal(2) + const virtualizer = createVirtualizer({ + get count() { + return count() + }, + getScrollElement: () => null, + estimateSize: () => 60, + initialRect: { width: 800, height: 600 }, + }) + + expect(virtualizer.getTotalSize()).toBe(120) + virtualizer.resizeItem(0, 100) + expect(virtualizer.getTotalSize()).toBe(160) + + setCount(3) + + expect(virtualizer.itemSizeCache.get(0)).toBe(100) + expect(virtualizer.getTotalSize()).toBe(220) + dispose() + }) +})