feat: implement SWR in-memory navigation cache hook to prevent redundant firestore listener mounts#457
Open
nitishchaubeyy wants to merge 4 commits into
Open
Conversation
…rbitrary point grants
…o reduce initial JS payload
…mounts on component failure
…ant firestore listener mounts
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
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.useFirestoreCacheHook: Engineered a custom SWR (Stale-While-Revalidate) hook that immediately returns memory-cached query results for instant UI paint, whilst silently revalidating viagetDocsin the background. It uses deep-comparison to trigger re-renders only if actual data mutates.GitRank.jsxOptimization: Successfully ripped out the expensiveonSnapshotreal-time listener and replaced it with agetDocsdriven 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.<AppRoutes />inside the<FirestoreCacheProvider>to ensure the memory map is globally accessible for future pages.Fixes #438