Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Jan 30, 2026

Summary

Adds optimistic caching with localStorage persistence to the PR status badge and branch display. When refreshing, badges now show cached status with a pulse animation instead of replacing content with a spinner. Extracts a reusable LRU cache helper and refactors existing caches to use it.

Background

Previously:

  • PR status and branch display used in-memory caches lost on app restart
  • When refreshing, both components showed spinners instead of cached values

The cache mechanism was already in place in PRStatusStore (it preserves prLink and status when setting loading: true), but the UI wasn't utilizing it. Branch selector had no caching at all.

Implementation

Phase 1: Generic LRU Cache Helper

  • New file: src/browser/utils/lruCache.ts
  • Extracted pattern from fileContentCache.ts and sharedUrlCache.ts
  • Features: per-entry localStorage keys, LRU index array, configurable TTL, update() for partial updates

Phase 2: Refactored Existing Caches

  • fileContentCache.ts and sharedUrlCache.ts now use createLRUCache
  • cachedAt moved from data types to LRU wrapper (managed internally)
  • ~70 lines removed from duplicate LRU logic

Phase 3: PR Status Persistence

  • Added prStatusLRU cache to PRStatusStore.ts
  • getWorkspacePR() checks localStorage if not in memory cache
  • Successful fetches persist to localStorage for instant display on app restart

Phase 4: Branch Selector Optimistic UI

  • Initialize from cached branch for instant display
  • Keep showing branch name during switch (was: show spinner)
  • Add animate-pulse effect during branch switch
  • Persist branch to localStorage on successful fetch/switch

Summary Table

Component Before After
PR Badge (refresh) Spinner only Cached status + pulse
PR Badge (restart) Spinner until fetch Cached status instantly
Branch Selector (switch) Spinner only Branch name + pulse
Branch Selector (restart) Spinner until fetch Cached branch instantly

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high • Cost: $1.17

@github-actions github-actions bot added the enhancement New feature or functionality label Jan 30, 2026
- Show cached status during refresh instead of spinner
- Add animate-pulse effect to indicate background refresh
- Keep status color and icon from cache while updating
…c UI

- Extract createLRUCache from fileContentCache and sharedUrlCache patterns
- Add localStorage persistence to PRStatusStore for instant display on app restart
- Add optimistic cache + pulse effect to BranchSelector during branch switch
- Refactor fileContentCache and sharedUrlCache to use the new LRU helper
- cachedAt is now managed by LRU helper, removed from ShareData/CachedFileContent types
@ammario ammario merged commit 7bef962 into main Jan 30, 2026
23 checks passed
@ammario ammario deleted the pr-status-badge-f38z branch January 30, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants