impr: optimize virtualizer resizeobserver (#688)

* impr: use one resize observer that observes all elements 1984 style instead of 1 agent per element

* design: tweak VirtualFeed.svelte to have a more modern retry window
This commit is contained in:
xylight authored and GitHub committed 2025-11-19 01:33:43 +00:00
1 parent 2d2a9a5671
commit 568bb3330a
8 files changed
+53 -52

No files matched your search

+25 -24
View File
@@ -139,38 +139,38 @@
}
function resizeObserver(node: HTMLElement) {
const debouncedUpdate = debounce((entries: ResizeObserverEntry[]) => {
for (const entry of entries) {
const indexAttr = node.getAttribute('data-index')
if (indexAttr === null) continue
const index = Number(indexAttr)
if (isNaN(index)) continue
const newHeight = entry.contentRect.height
if (itemHeights[index] !== newHeight) {
itemHeights[index] = newHeight
if (!initialRender) visibleItems = updateVisibleItems()
}
}
}, debounceResize)
const observer = new ResizeObserver((entries) => {
debouncedUpdate(entries)
})
observer.observe(node)
onDestroy(() => {
observer.disconnect()
})
return {
destroy() {
observer.disconnect()
observer.unobserve(node)
},
}
}
const debouncedUpdate = debounce((entries: ResizeObserverEntry[]) => {
for (const entry of entries) {
const indexAttr = entry.target.getAttribute('data-index')
if (indexAttr === null) continue
const index = Number(indexAttr)
if (isNaN(index)) continue
const newHeight = entry.contentRect.height
if (itemHeights[index] !== newHeight) {
itemHeights[index] = newHeight
if (!initialRender) visibleItems = updateVisibleItems()
}
}
}, debounceResize)
const observer = new ResizeObserver((entries) => {
debouncedUpdate(entries)
})
onDestroy(() => {
observer.disconnect()
})
// Scroll position changes (only every few px)
let oldScroll = $state(0)
$effect(() => {
@@ -196,6 +196,7 @@
itemHeights[index] = newHeight
}
})
untrack(() => {
visibleItems = updateVisibleItems()
initialRender = false