-
Notifications
You must be signed in to change notification settings - Fork 0
feat: #131 client-side SPA routing, review Apollo cache updates, and storage resilience #138
Conversation
…rage resilience
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. The router is small and easy to follow, and moving the album-return logic from the global document click listener to subscribeBeforeNavigate is a lot cleaner. Here is what I checked and what I think needs a change.
Looks good
- Base path:
appHrefandstripBasePathhandle/project2,/project2/and trailing slashes, and/project2foois not treated as part of the base. - Modifier keys:
Linkleaves Ctrl/Cmd/Shift/Alt clicks, non-primary buttons,target,downloadand cross-origin links to the browser. Middle click never reachesonClick. - Apache fallback: this works with the existing
FallbackResource /project2/index.htmlfrom #82 (docs/VM-setup.md) and the deploy check on/project2/album/1. Deep links, reloads and "open in new tab" from a card should all load on the VM. No Apache change is needed in this PR. - Back/forward: both the router and
useSearchStatenow listen to the samepopstatesubscription, so the URL and the search state can't get out of sync. - Cache:
mergeCursorConnectionbehaves the same as the two old merge functions. UpdatingAlbum:<id>keepsmyCratein sync, and evictingsearchAlbumsmakes Discover refetch rating sort, thereviewedfilter andreviewedCountwhen you go back. The restore effect fetches the missing pages after the eviction, so scroll restoration still works. userIdentity: the try/catch and the in-memory fallback are correct, and the "storage becomes writable again" test covers the tricky case.
Request changes
- Focus and announcements on route change. Before this PR, every navigation was a full page load, so screen readers announced the new page. Now nothing happens: the card link you clicked unmounts, focus falls back to
<body>, and there is no announcement.document.titlealso stays the same on every route. Please do this when the pathname changes (not when only the query changes): move focus to<main id="main">, which already hastabIndex={-1}, or to the page<h1>, and setdocument.titleper route (for example "Album title · Crate"). Skip it on the first load so you don't steal focus. A test that checksdocument.activeElementafter clicking an album card would cover it. - Stale chunks after a deploy. The deploy deletes
/var/www/html/project2and copies in new hashed assets. A tab that stays open (more likely now that navigation doesn't reload the page) then lazy-loads an oldAlbumDetailPage-<hash>.js.FallbackResourceanswers that withindex.htmlas 200text/html, so the dynamic import fails with a MIME error. There is no error boundary around theSuspense, so the whole app goes blank. A small error boundary, orlazy(() => import(...).catch(() => window.location.reload()))with a guard against reload loops, would fix it.
Non-blocking
- The skip link resets Discover's pagination. In Chrome and Firefox, clicking
<a href="#main">firespopstate.handlePopStatebumpslocationKey, sovisitKeychanges anduseAlbumSearchdrops back to 20 visible results, even if the user had loaded 60. You could ignorepopstatewhen only the hash changed, or leavelocation.keyout ofvisitKeyfor hash-only changes. I found this by reading the code, so it's worth checking in the browser. - Redundant
cache.modify.UPSERT_REVIEWandDELETE_REVIEWalready selectalbum { id averageRating reviewCount myReview { ... } }, and Apollo writes that intoAlbum:<id>beforeupdateruns. So thecache.modifyinupdateCacheAfterReviewMutationdoesn't change anything. Only theevictandgccalls are needed. It's harmless, but the comment makes it sound like it does more than it does. pushState(window.history.state, ...). This copies the previous entry's state into the new entry.null(or{ key }) would be clearer.
|
Thanks for the thorough review, @evenkkl! Addressed all requested changes and non-blocking notes in
Verified locally with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this addresses everything. Approving.
- Focus on route change: fixed. Focus moves to
<main id="main">only when the pathname changes. For lazy routes,RouteFocusSettlermoves focus to the real<main>once the Suspense fallback unmounts.AlbumDetailPage's own loading state returns a<main>at the same position, so React keeps the same DOM node and focus isn't lost a second time when the data arrives. - Stale chunks: fixed, and it can't get stuck in a reload loop. It reloads at most once per URL every 30 s. If
sessionStorageis blocked it never reloads automatically, and therole="alert"fallback with a "Reload page" button covers the rest. Non-chunk errors now show the fallback instead of a blank page, which is a nice bonus. - Skip link: fixed. A
popstatethat only changes the hash, and anavigate()that only changes the hash, no longer bumplocationKey. cache.modifyandpushState: both done.document.title: fine to leave to #140. I checked that #140 sets it for Discover, album detail (loading/unavailable/title) and the crate.
Optional: the lazy-route focus handoff (fallback → real <main>) doesn't seem to have its own test. A test with a lazy component that resolves after a delay would lock it in.
Closes #131
What was done
client/src/router.ts,client/src/components/Link.tsx,client/src/App.tsx,AlbumCard.tsx,AlbumDetailPage.tsx,CratePage.tsx,useSearchState.ts):<a href>reloads with a lightweight, zero-dependency History API router under/project2/supporting Discover (/), Album Detail (/album/:id), and Your Crate (/crate).InMemoryCacheacross navigations (includingmySearchHistoryswitched tocache-firstinuseSearchHistory.ts), deep links, reloads, browser back/forward, modifier-key native link behavior, scroll reset on forward route transitions, and warm-cache loaded-page + scroll restoration on return to Discover (replacing the globaldocumentclick listener inuseAlbumSearch.tswithsubscribeBeforeNavigate).client/src/api/reviews.ts,ReviewForm.tsx,client/src/generated/):UPSERT_REVIEWandDELETE_REVIEWto select updatedalbum { id averageRating reviewCount myReview { id rating comment createdAt updatedAt } }and regenerated GraphQL types.updateCacheAfterReviewMutationto immediately sync normalizedAlbumrecords (updatingAlbumDetailPageandmyCrateviews in place) and evict cachedsearchAlbumsentries so Discover reflects rating/count/facet/sort changes on return.client/src/api/userIdentity.ts,userIdentity.test.ts):localStorage.getItem/setItemintry/catchwith a session-scoped in-memory UUID fallback so blocked/full storage never breaks GraphQL requests.client/src/api/client.ts,useAlbumSearch.ts,DiscoveryPage.tsx,vite.config.ts):mergeCursorConnectionhelper used by bothsearchAlbumsandmyCrate.setPaginationinuseAlbumSearch.tsby deriving pagination per searchvisitKey.DiscoveryPagefromApp.tsxtoclient/src/pages/DiscoveryPage.tsx.// TODO(#6)comment inclient/vite.config.ts.What was tested
pnpm codegen && pnpm format:check && pnpm lint && pnpm typecheck && pnpm test && pnpm buildrouter.test.tsx,client.test.tscrate & review cache tests,userIdentity.test.tsstorage fallback tests).client/dist/assets/*.js, CI budget <= 512,000 B):index390,435 B (630 B smaller thanmain),CrateButton58,489 B,AlbumDetailPage11,989 B,CratePage2,329 B,rolldown-runtime599 B.