svelte-tiny-virtual-list icon indicating copy to clipboard operation
svelte-tiny-virtual-list copied to clipboard

fix: handle decrease in itemCount cleanly

Open ajhoddinott opened this issue 3 weeks ago • 0 comments

If itemCount decreases, for example due to filtering, there are two issues:

  • SizeAndPositionManager lastMeasuredIndex can point to items that no longer exist, causing "index X is outside of range"
  • VirtualList tries to render stale items before refresh() has updated

This fix:

  • Clamps lastMeasuredIndex in updateConfig()
  • Clamps the scroll offset in refresh()

I introduced a derived validItems to filter out stale items. This can be inlined as {#each items.filter((item) => item.index < itemCount) as item (getKey ? getKey(item.index) : item.index)} but I felt the line was long and hard to follow.

ajhoddinott avatar Dec 06 '25 05:12 ajhoddinott