perf: skip feed index fetch when navigating from activity feed

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.
This commit is contained in:
Davide Scaini
2026-05-19 19:44:20 +02:00
parent 1f6239e7d2
commit 29c6e399c0
2 changed files with 17 additions and 7 deletions
@@ -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.
+1
View File
@@ -350,6 +350,7 @@
<a
href={a.detail_url ? `${import.meta.env.BASE_URL}activity/${a.id}/` : `${import.meta.env.BASE_URL}activity/local/?id=${a.id}`}
class="before:absolute before:inset-0 before:content-[''] truncate"
on:click={() => { try { sessionStorage.setItem(`bincio:activity:${a.id}`, JSON.stringify(a)); } catch {} }}
>{a.title}</a>
</h3>
</div>