From 568bb3330a5446253286feb74a6cdb327e801adc Mon Sep 17 00:00:00 2001 From: xylight <80978739+Xyphyn@users.noreply.github.com> Date: Tue, 18 Nov 2025 17:33:43 -0800 Subject: [PATCH] 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 --- src/lib/app/render/VirtualList.svelte | 49 ++++++++++--------- src/lib/feature/post/feed/VirtualFeed.svelte | 39 +++++++-------- src/lib/ui/info/ErrorContainer.svelte | 6 ++- src/routes/go/+page.ts | 1 + static/.well-known/assetlinks.json | 2 +- static/manifest.json | 8 +-- static/other/mc.mp3 | Bin 17900 -> 0 bytes static/other/mc.png | Bin 90061 -> 0 bytes 8 files changed, 53 insertions(+), 52 deletions(-) delete mode 100644 static/other/mc.mp3 delete mode 100644 static/other/mc.png diff --git a/src/lib/app/render/VirtualList.svelte b/src/lib/app/render/VirtualList.svelte index dd25280d..fdad90af 100644 --- a/src/lib/app/render/VirtualList.svelte +++ b/src/lib/app/render/VirtualList.svelte @@ -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 diff --git a/src/lib/feature/post/feed/VirtualFeed.svelte b/src/lib/feature/post/feed/VirtualFeed.svelte index 92e69019..c27cfb01 100644 --- a/src/lib/feature/post/feed/VirtualFeed.svelte +++ b/src/lib/feature/post/feed/VirtualFeed.svelte @@ -2,12 +2,13 @@ import { browser } from '$app/environment' import { client } from '$lib/api/client.svelte' import type { GetPosts, PostView } from '$lib/api/types' + import { errorMessage } from '$lib/app/error' import { t } from '$lib/app/i18n' import VirtualList from '$lib/app/render/VirtualList.svelte' import { settings } from '$lib/app/settings.svelte' import Placeholder from '$lib/ui/info/Placeholder.svelte' import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte' - import { Button } from 'mono-svelte' + import { Button, Material, Spinner } from 'mono-svelte' import { onDestroy, onMount, untrack } from 'svelte' import { ArchiveBox, @@ -213,15 +214,16 @@ {#if settings.infiniteScroll && browser && posts.length > 0} {#if error} -
{error}
-