**Priority:** High (Final sprint before 27 Nov) **Source:** Peer feedback + pre-submission code audit ## Problem 1. **Full-page reload navigation wipes Apollo cache (`client/src/App.tsx:11-36`, `AlbumCard.tsx:8,52`, `AlbumDetailPage.tsx:33,99,118`, `CratePage.tsx:12,97`, `useAlbumSearch.ts:206-291`):** - Route transitions between Discover, `/album/:id`, and `/crate` use plain `<a href>` full-page reloads. Every navigation discards Apollo's `InMemoryCache`, re-fetches `mySearchHistory`, undermines `cache-first` and code-splitting sustainability gains, and forced PR #121's `sessionStorage` workaround to sequentially re-fetch loaded pages on Back. 2. **Review mutations do not update Apollo cache (`client/src/api/reviews.ts:14-38`, `ReviewForm.tsx:27-28,56,68,91,102`, `AlbumDetailPage.tsx:218`):** - `UPSERT_REVIEW` and `DELETE_REVIEW` only select `album { id }`, triggering a blind full `ALBUM_DETAIL` refetch while leaving cached `searchAlbums` and `myCrate` lists/facets stale (especially visible once client-side routing preserves cache across pages). Pairs with server-side DataLoader clearing in #129. 3. **Unguarded `localStorage` breaks all GraphQL requests (`client/src/api/userIdentity.ts:24-31`, `client/src/api/client.ts:111-113`):** - `getUserId()` calls `window.localStorage.getItem`/`setItem` without `try/catch` inside Apollo's `setContext` link on every request; if storage throws (`SecurityError`/`QuotaExceededError`), even anonymous reads fail. 4. **Client state & code hygiene (`client/src/api/client.ts:37-99`, `client/src/hooks/useAlbumSearch.ts:71-79`, `client/src/App.tsx:71-138`, `client/vite.config.ts:12`):** - `searchAlbums.merge` and `myCrate.merge` duplicate cursor-append and ID deduplication. - `useAlbumSearch.ts:71-79` calls `setPagination` during render, `DiscoveryPage` lives inline in `App.tsx:71-138`, and `client/vite.config.ts:12` still has a stale `// TODO(#6)` comment. ## Suggested solution - Introduce lightweight client-side routing under `/project2/` (History API + `popstate` or `react-router` staying well within the 512 KB JS bundle budget) for Discover, `/album/:id`, and `/crate`, keeping direct URLs, reloads, browser back/forward, and scroll restoration working while simplifying redundant full-reload workarounds. - Update `UPSERT_REVIEW` / `DELETE_REVIEW` to select updated `album { id averageRating reviewCount myReview { ... } }` and update/evict Apollo cache entries cleanly so Discover and Crate reflect rating/review changes immediately. - Wrap `localStorage` access in `client/src/api/userIdentity.ts` in `try/catch` with a module-scoped in-memory UUID fallback and add unit tests in `userIdentity.test.ts`. - Extract a shared connection merge helper in `client/src/api/client.ts`, remove render-time `setPagination` in `useAlbumSearch.ts`, move `DiscoveryPage` to `client/src/pages/DiscoveryPage.tsx`, and delete the stale `TODO(#6)` comment in `client/vite.config.ts`. ## Acceptance criteria - [ ] Navigating between Discover, Album Detail, and Your Crate happens client-side without full document reloads, preserving Apollo `InMemoryCache`, deep links, page reloads, browser back/forward, and Discover scroll/loaded-page state under `/project2/`. - [ ] All JS bundles remain under the 512 KB CI budget after adding client-side routing. - [ ] Saving or deleting a review updates cached album rating/count/`myReview` and invalidates/updates affected cached `searchAlbums` / `myCrate` views without stale ratings on return. - [ ] `getUserId()` degrades gracefully to an in-memory UUID when `localStorage.getItem` or `setItem` throws, verified by unit tests. - [ ] `client/src/api/client.ts` uses a shared connection merge helper, `useAlbumSearch.ts` has no render-time `setState`, `DiscoveryPage` is extracted to `client/src/pages/DiscoveryPage.tsx`, and stale `TODO(#6)` in `client/vite.config.ts` is removed. ### Optional stretch (if time permits) - [ ] Decompose `AlbumDetailPage.tsx` (e.g. `Tracklist` / `ReviewSection`) and `FilterPanel.tsx` (e.g. `ActiveFilterChips` / `FilterGroup`) if the diff stays clean.