From 29c6e399c09fa1fd45f39238b9a8cba30aeb0187 Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Tue, 19 May 2026 19:44:20 +0200 Subject: [PATCH] perf: skip feed index fetch when navigating from activity feed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Write the activity summary to sessionStorage on click in ActivityFeed, then read it synchronously at module init in ActivityDetailLoader so the page renders immediately without the "Loading activity…" blank screen or the 2 round-trip index fetch. Direct URL / bookmark / shared link falls through to the existing slow path unchanged. --- .../components/ActivityDetailLoader.svelte | 23 +++++++++++++------ site/src/components/ActivityFeed.svelte | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/site/src/components/ActivityDetailLoader.svelte b/site/src/components/ActivityDetailLoader.svelte index 91cd3f9..857864e 100644 --- a/site/src/components/ActivityDetailLoader.svelte +++ b/site/src/components/ActivityDetailLoader.svelte @@ -7,9 +7,20 @@ export let base: string = '/'; - let activity: ActivitySummary | null = null; - let notFound = false; - let loading = true; + // Synchronous init — check sessionStorage before first render so "Loading activity…" + // is never shown when navigating from the feed. + const _activityId = window.location.pathname.match(/\/activity\/([^/]+)/)?.[1] ?? null; + let _initial: ActivitySummary | null = null; + if (_activityId) { + try { + const c = sessionStorage.getItem(`bincio:activity:${_activityId}`); + if (c) _initial = JSON.parse(c); + } catch {} + } + + let activity: ActivitySummary | null = _initial; + let notFound = _activityId === null; + let loading = _activityId !== null && _initial === null; /** * Build an ActivitySummary stub from a detail JSON object. @@ -85,11 +96,9 @@ } onMount(async () => { - // Extract activity ID from the URL path: /activity/{id}/ - const match = window.location.pathname.match(/\/activity\/([^/]+)/); - const id = match?.[1]; - if (!id) { notFound = true; loading = false; return; } + if (!loading) return; // fast path: summary already from sessionStorage + const id = _activityId!; try { // Load only the most-recent year shard — avoids downloading all years just // to look up one activity. Falls back to a direct file fetch if not found. diff --git a/site/src/components/ActivityFeed.svelte b/site/src/components/ActivityFeed.svelte index 619cd51..c30bf30 100644 --- a/site/src/components/ActivityFeed.svelte +++ b/site/src/components/ActivityFeed.svelte @@ -350,6 +350,7 @@ { try { sessionStorage.setItem(`bincio:activity:${a.id}`, JSON.stringify(a)); } catch {} }} >{a.title}