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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user