Skip to content

feat: implement SWR in-memory navigation cache hook to prevent redundant firestore listener mounts#457

Open
nitishchaubeyy wants to merge 4 commits into
indresh404:mainfrom
nitishchaubeyy:feature/firestore-memory-cache
Open

feat: implement SWR in-memory navigation cache hook to prevent redundant firestore listener mounts#457
nitishchaubeyy wants to merge 4 commits into
indresh404:mainfrom
nitishchaubeyy:feature/firestore-memory-cache

Conversation

@nitishchaubeyy

Copy link
Copy Markdown
Contributor

Description

Addresses #438 by mitigating excessive Firestore read charges caused by redundant listener tear-downs during same-session route navigation.

Key Additions

  • FirestoreCacheContext.jsx: Created a dedicated Context-backed store that persists across route unmounts, managing custom TTL cache maps.
  • useFirestoreCache Hook: Engineered a custom SWR (Stale-While-Revalidate) hook that immediately returns memory-cached query results for instant UI paint, whilst silently revalidating via getDocs in the background. It uses deep-comparison to trigger re-renders only if actual data mutates.
  • GitRank.jsx Optimization: Successfully ripped out the expensive onSnapshot real-time listener and replaced it with a getDocs driven fetch function wrapped in the new caching layer. Included local state synchronization to ensure the infinite-scroll pagination (startAfter) logic remains functional within the cached bounds.
  • App Shell Scope: Wrapped the overarching <AppRoutes /> inside the <FirestoreCacheProvider> to ensure the memory map is globally accessible for future pages.

Fixes #438

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ranker-hub Ready Ready Preview, Comment Jun 11, 2026 9:16am

@github-actions github-actions Bot added backend Backend/Firebase related changes bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review labels Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend/Firebase related changes bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance][Level 3]: In-Memory Navigation Cache Hook for Firestore Leaderboard and Profile Reads

1 participant