impr: untrack dependency changes in virtual list to avoid recursion

This commit is contained in:
James Xylight committed 2025-06-26 10:56:01 -07:00
1 parent dd8e055cef
commit de3ca92544
2 files changed
+6 -5

No files matched your search

@@ -189,7 +189,6 @@
class="divide-y -mx-4 sm:-mx-6 divide-slate-200 dark:divide-zinc-900"
items={posts}
{initialOffset}
overscan={500}
bind:restore={postFeeds.value[feedId].clientData}
bind:this={listComp}
>
+6 -4
View File
@@ -20,7 +20,7 @@
let {
items,
estimatedHeight = 100,
overscan = 5,
overscan = 3,
item: itemSnippet,
initialOffset = 0,
restore = $bindable(),
@@ -100,11 +100,10 @@
const firstIndex = findFirstVisibleIndex(scrollTop, cumulativeItemHeights)
let i = firstIndex
let offset = i == 0 ? 0 : cumulativeItemHeights[i - 1]
let offset = i === 0 ? 0 : cumulativeItemHeights[i - 1]
while (
i < items.length &&
i < firstIndex + overscan &&
offset < scrollTop + viewportHeight + overscan * estimatedHeight
) {
newVisibleItems.push({ index: i, offset: offset })
@@ -113,7 +112,7 @@
i++
}
return newVisibleItems ?? []
return newVisibleItems
}
function resizeObserver(node: HTMLElement) {
@@ -167,12 +166,15 @@
}
})
// Scroll position changes (only every few px)
let oldScroll = $state(0)
$effect(() => {
const currentScrollY = scrollY.current ?? 0
if (Math.abs(currentScrollY - oldScroll) > estimatedHeight) {
untrack(() => {
visibleItems = updateVisibleItems()
oldScroll = currentScrollY
})
}
})
</script>