Publish button shows previous user's cached remote sites after logout/login - #4589
Open
katinthehatsite wants to merge 4 commits into
Open
Publish button shows previous user's cached remote sites after logout/login#4589katinthehatsite wants to merge 4 commits into
katinthehatsite wants to merge 4 commits into
Conversation
Collaborator
📊 Performance Test ResultsComparing 7019af8 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses stale user-scoped React Query cache leaking across logout/login in the Agentic UI (apps/ui), which caused the Publish flow to show a previous user’s connected WordPress.com sites after switching accounts.
Changes:
- Exposes WPCOM-sites query keys so they can be targeted externally for cache removal on auth transitions.
- Removes (not just invalidates) several user-scoped queries when auth state changes and on logout success to prevent persisted-cache leakage between accounts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/ui/src/data/queries/use-wpcom-sites.ts | Exports WPCOM sites query keys so other modules can remove them on auth transitions. |
| apps/ui/src/data/queries/use-auth-user.ts | Adds logic to remove user-scoped queries on auth transitions and logout to prevent stale persisted data from showing for a different user. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+43
to
+50
| function useRemoveUserScopedQueries() { | ||
| const queryClient = useQueryClient(); | ||
| return useCallback( () => { | ||
| for ( const key of USER_SCOPED_QUERY_KEYS ) { | ||
| queryClient.removeQueries( { queryKey: key } ); | ||
| } | ||
| }, [ queryClient ] ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
Fixes STU-2281/
How AI was used in this PR
It was used to help identify the issue
Proposed Changes
This PR ensures that when the user logs out, all the user account queries get invalidated e.g. the snapshots or connected sites. It ensures that when the user B logs in, they would see only the data relevant for their account.
Testing Instructions
npm startPre-merge Checklist