Skip to content

feat: add persistent Apollo cache for proposal data#571

Open
rickstaa wants to merge 1 commit intofeat/apollo-cache-and-network-votesfrom
feat/apollo-persistent-cache
Open

feat: add persistent Apollo cache for proposal data#571
rickstaa wants to merge 1 commit intofeat/apollo-cache-and-network-votesfrom
feat/apollo-persistent-cache

Conversation

@rickstaa
Copy link
Member

@rickstaa rickstaa commented Mar 3, 2026

Summary

  • Installs apollo3-cache-persist (compatible with current Apollo Client 3.13.1)
  • Persists the InMemoryCache to localStorage so previously fetched data (especially finished proposals) survives full page reloads
  • App waits for cache restoration before rendering to avoid flicker
  • Capped at 1 MB maxSize to prevent localStorage bloat

Stack

This is part of a stacked PR chain:

  1. #561 feat/improve-treasury-votes-caching-behavior — ENS caching
  2. #569 feat/ens-cache-improvements — remove redundant localEnsCache + add TTL
  3. #570 feat/apollo-cache-and-network-votes — Apollo fetch policy for vote data
  4. This PR feat/apollo-persistent-cache — persistent Apollo cache via localStorage

Test plan

  • Navigate to a treasury proposal — votes load normally
  • Hard refresh (Ctrl+Shift+R) — data should restore from localStorage instantly
  • Verify localStorage contains Apollo cache data (check in DevTools > Application > Local Storage)
  • Confirm cache doesn't exceed 1 MB

🤖 Generated with Claude Code

Persist the InMemoryCache to localStorage so previously fetched data
(especially finished proposals) survives full page reloads. The app
waits for cache restoration before rendering to avoid flicker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rickstaa rickstaa requested a review from ECWireless as a code owner March 3, 2026 10:13
@vercel
Copy link
Contributor

vercel bot commented Mar 3, 2026

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

Project Deployment Actions Updated (UTC)
explorer-arbitrum-one Building Building Preview, Comment Mar 3, 2026 10:13am

Request Review


export * from "./subgraph";

const cache = new InMemoryCache();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apollo cache created at module load time as singleton, causing data leakage between SSR requests in the same Node.js process

Fix on Vercel

export function useApolloReady() {
const [ready, setReady] = useState(typeof window === "undefined");
useEffect(() => {
cachePersistPromise.then(() => setReady(true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cachePersistPromise.then(() => setReady(true));
cachePersistPromise
.then(() => setReady(true))
.catch(() => setReady(true)); // Even if cache persistence fails, proceed with the app

Missing error handling for cache persistence failure causes app to remain in loading state indefinitely when localStorage is unavailable

Fix on Vercel


/** Wait for the persisted cache to restore before rendering queries. */
export function useApolloReady() {
const [ready, setReady] = useState(typeof window === "undefined");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [ready, setReady] = useState(typeof window === "undefined");
const [ready, setReady] = useState(false);

useApolloReady hook causes hydration mismatch by initializing different state on server vs client

Fix on Vercel

@ECWireless
Copy link
Collaborator

@rickstaa should this be closed given #572 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants