Skip to content

Publish button shows previous user's cached remote sites after logout/login - #4589

Open
katinthehatsite wants to merge 4 commits into
trunkfrom
fix/clear-wpcom-sites-cache-on-logout
Open

Publish button shows previous user's cached remote sites after logout/login#4589
katinthehatsite wants to merge 4 commits into
trunkfrom
fix/clear-wpcom-sites-cache-on-logout

Conversation

@katinthehatsite

Copy link
Copy Markdown
Contributor

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

  • Pull the changes from this branch
  • Start Studio with npm start
  • Enable Agentic UI
  • Log in with user A
  • Create a site
  • Click on Live > Publish
  • Connect WP.com sites of the user A
  • Log out
  • Log in with user B
  • Confirm that you can not see the sites of the user A in the connected sites dropdown when logged in with the user B

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@katinthehatsite katinthehatsite self-assigned this Aug 18, 2026
@katinthehatsite
katinthehatsite requested a review from a team August 18, 2026 13:42
@wpmobilebot

wpmobilebot commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 7019af8 vs trunk

app-size

Metric trunk 7019af8 Diff Change
App Size (Mac) 1435.99 MB 1435.99 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 7019af8 Diff Change
load 1188 ms 1167 ms 21 ms ⚪ 0.0%

site-startup

Metric trunk 7019af8 Diff Change
siteCreation 7516 ms 7520 ms +4 ms ⚪ 0.0%
siteStartup 2869 ms 2871 ms +2 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants