feat: add SWR local storage cache layer for offline dashboard resiliency (#2801) - #3348
Open
yachikadev wants to merge 5 commits into
Open
feat: add SWR local storage cache layer for offline dashboard resiliency (#2801)#3348yachikadev wants to merge 5 commits into
yachikadev wants to merge 5 commits into
Conversation
Adds saveSnapshot/getSnapshot/clearSnapshot helpers with try-catch guards so localStorage failures (disabled, quota full, SSR context) never throw at runtime.
Adds saveSnapshot/getSnapshot/clearSnapshot helpers with try-catch guards so localStorage failures (disabled, quota full, SSR context) never throw at runtime.
- Load last cached streak/contribution data from localStorage on mount before the network request resolves - Persist fresh data to localStorage on successful fetch - Fall back to cached snapshot instead of showing an error when the live fetch fails (offline / rate-limited) Part of Priyanshu-byte-coder#2801
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
This was referenced Aug 2, 2026
- Load last cached goals list from localStorage on mount - Persist fresh goals to localStorage on successful load - Fall back to cached goals instead of an error message when the live fetch fails Closes Priyanshu-byte-coder#2801
yachikadev
force-pushed
the
feat/swr-dashboard-cache
branch
from
August 3, 2026 16:43
7675cab to
5e31350
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a Stale-While-Revalidate (SWR) local storage cache layer for the dashboard's Streak Tracker and Goal Tracker widgets, so users see their last-known data instantly on load instead of a blank/loading state — even on spotty networks, during GitHub API rate-limiting, or fully offline.
Closes #2801
Changes
src/lib/localCache.ts(new) — lightweightsaveSnapshot/getSnapshot/clearSnapshothelpers backed bylocalStorage, withtry/catchguards so a full, disabled, or missinglocalStoragenever throws at runtime.src/components/StreakTracker.tsx— on mount, hydrates instantly from the last cached streak/contribution snapshot before the network call resolves. On successful fetch, persists the new snapshot. On fetch failure, falls back to the cached snapshot instead of showing an error.src/components/GoalTracker.tsx— same pattern applied to the goals list: instant hydration from cache, snapshot saved on successful load, cached goals shown if the live fetch fails.How it works
useEffecton mount reads the cached snapshot fromlocalStorageand populates state immediately, skipping the loading spinner if data is available.Notes
/api/metricsand/api/goals(streaks + goals), matching the issue's acceptance criteria. Other widgets are untouched and can adopt the samelocalCache.tsutility in future PRs if desired.