Clear persisted query cache on logout - #16527
Conversation
Cached application state must not survive sign-out on shared devices. The persisted TanStack Query localStorage blob (REACT_QUERY_OFFLINE_CACHE) previously outlived logout because clearQueryPersistenceCache() only invalidated queries (marking them stale) instead of removing them, and nothing called it from signOut anyway. Now signOut removes the in-memory persisted queries and deletes the localStorage entry via the persister's removeClient(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Deploying care-preview with
|
| Latest commit: |
5143d09
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://50e445d9.care-preview-a7w.pages.dev |
| Branch Preview URL: | https://issues-16509-clear-persisted.care-preview-a7w.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5143d09328
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Greptile SummaryThis PR fixes a security gap where the TanStack Query persisted cache (
Confidence Score: 4/5Safe to merge — the core fix correctly clears both in-memory queries and the localStorage blob on logout; one minor edge case with the persistence subscriber may re-create an empty key shortly after logout but no user data is involved. The fix is correct and the test validates the primary path. The only concern is a timing quirk where the debounced persistQueryClient subscriber can re-write an empty blob to localStorage after removeClient() has cleared it — no user data survives, but the key itself reappears for ~1 s. The cross-tab signout path properly routes through the same signOut function and will clear the cache there too. src/Utils/request/queryClient.ts — the interaction between removeQueries, the persistence subscriber, and removeClient is worth a second look Important Files Changed
Reviews (1): Last reviewed commit: "fix: clear persisted query cache on logo..." | Re-trigger Greptile |
Closes #16509
Stacked on #16514 (uses the Vitest harness for the new test). GitHub will retarget this to
developwhen that merges.What
Cached application state must not survive sign-out on shared devices — but the persisted TanStack Query blob (
REACT_QUERY_OFFLINE_CACHEin localStorage) previously outlived logout:clearQueryPersistenceCache()only calledinvalidateQueries(marks stale; removes nothing) and had zero callers.signOutremoved the auth-token keys but never touched the persisted cache.Changes:
src/Utils/request/queryClient.ts: persister key is now explicit;clearQueryPersistenceCache()doesremoveQueriesonmeta.persist === trueentries andpersister.removeClient()(actually deletes the localStorage entry), returning the promise so callers can await.src/Providers/AuthUserProvider.tsx:signOutawaits the purge right after the token removals. The cross-tab storage listener funnels through the samesignOut, so other tabs are covered.Verification
npm run typecheck→ exit 0npm run test:unit→ 6/6, including a new jsdom test proving the localStorage entry is gone after the purgegrep invalidateQueries src/Utils/request/queryClient.ts→ no matches🤖 Generated with Claude Code