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