From 1f3f5b3d3bbba6be8f7744668758551f39a8016a Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Fri, 15 May 2026 09:14:56 +0200 Subject: [PATCH] =?UTF-8?q?Feed:=20fix=20date=20range=20eager-load=20?= =?UTF-8?q?=E2=80=94=20use=20primary=20let-vars,=20cover=20feed=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous attempt used dateFrom (a derived $: variable) as the trigger which Svelte 5 doesn't reliably track as a dependency of a side-effect $: block. Replace with the primary let-variables (customFrom, customTo, datePre) that Svelte does track statically. Also extend eager-loading to cover the global combined feed (feedNextPage) so date/search filtering works on multi-user instances too, not just per-user profile pages (pendingShards). --- site/src/components/ActivityFeed.svelte | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/site/src/components/ActivityFeed.svelte b/site/src/components/ActivityFeed.svelte index 0d0bf3e..71659fb 100644 --- a/site/src/components/ActivityFeed.svelte +++ b/site/src/components/ActivityFeed.svelte @@ -134,8 +134,12 @@ // When a search query or any date filter is active, eagerly load all // remaining shards so results aren't limited to the initially-loaded year. + // Use only primary let-variables here — Svelte 5 doesn't reliably track + // derived $: variables as dependencies of side-effect $: blocks. let loadingAllShards = false; - $: if ((query.trim() || dateFrom) && pendingShards.length > 0 && !loadingAllShards) { + let loadingAllFeedPages = false; + + $: if ((query.trim() || customFrom || customTo || datePre !== 'all') && pendingShards.length > 0 && !loadingAllShards) { loadingAllShards = true; (async () => { while (pendingShards.length > 0) { @@ -154,6 +158,25 @@ })(); } + $: if ((query.trim() || customFrom || customTo || datePre !== 'all') && feedNextPage > 0 && !loadingAllFeedPages) { + loadingAllFeedPages = true; + (async () => { + while (feedNextPage > 0) { + const page = feedNextPage; + feedNextPage = page < feedTotalPages ? page + 1 : 0; + try { + const fresh = await loadCombinedFeedPage(base, page); + const existing = new Map(all.map(a => [a.id, a])); + for (const a of fresh) if (!existing.has(a.id)) existing.set(a.id, a); + all = [...existing.values()].sort((a, b) => + (b.started_at ?? '').localeCompare(a.started_at ?? ''), + ); + } catch { /* ignore — partial results still useful */ } + } + loadingAllFeedPages = false; + })(); + } + $: if (mounted) { const params = new URLSearchParams(window.location.search); if (sport === 'all') params.delete('sport'); else params.set('sport', sport);