Skip to content

Clear sync state on user logout#2707

Open
gcsecsey wants to merge 8 commits intotrunkfrom
gcsecsey/stu-166-clear-sync-on-logout
Open

Clear sync state on user logout#2707
gcsecsey wants to merge 8 commits intotrunkfrom
gcsecsey/stu-166-clear-sync-on-logout

Conversation

@gcsecsey
Copy link
Contributor

@gcsecsey gcsecsey commented Mar 4, 2026

Related issues

Fixes STU-166

How AI was used in this PR

I used AI to research the existing logout flow, then implemented and iterated on the changes using it.

Proposed Changes

When a user logged out, sync-related Redux state was not cleared, and the stale data remained in memory. If a different user logged in, they could see leftover sync UI state from the previous session.

This PR adds a userLoggedOut Redux action that is dispatched either when logging out explicitly or when an invalid token is detected. Multiple slices and a store listener react to this:

  • syncOperations slice resets pullStates and pushStates to empty
  • sync slice clears the remote file tree cache
  • connectedSites slice resets modal and selection state
  • A store listener cancels active main-process sync operations, stops renderer-side push/pull pollers, and resets authenticated RTK Query caches

Testing Instructions

  • Log in to a WordPress.com account and connect a remote site
  • Start a push or pull operation
  • Log out
  • Log in again with the same user or a different one
  • Check that the Sync tab shows the logged out state
  • Log in again (same or different account) and check that initial pull/push states are shown
CleanShot.2026-03-04.at.16.41.21.mp4

Pre-merge Checklist

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

Dispatch a shared userLoggedOut action on logout and invalid token detection
that resets sync slices, cancels active operations, stops pollers, and clears
authenticated RTK Query caches.
@gcsecsey gcsecsey self-assigned this Mar 4, 2026
@gcsecsey gcsecsey requested a review from a team March 4, 2026 16:54
@gcsecsey gcsecsey marked this pull request as ready for review March 4, 2026 16:54
Copy link
Contributor

@katinthehatsite katinthehatsite left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes @gcsecsey - nice work!

I found some issues on my end when testing this PR. This is what I saw on my end: I started the pull operation and waited until the downloading backup step. Then, I logged out and noticed that some of the buttons were stuck in the "Importing" state:

Image

(see the top right corner)

Then, when I log in as a different user, I see the following issue on the import screen:

Image

When importSite fails during a sync pull, the pull Redux state stays at
'importing' while the import context fires an error event. Since
canCancelPull only allows cancellation for 'in-progress' and
'downloading' states, the user gets stuck with a disabled dismiss button.

Add an isError flag to ImportProgressState and set it on import errors.
In the sync UI, detect when a pull is in 'importing' state but the
import has failed, and treat it as a pull error so the user can dismiss
it and retry.
@gcsecsey
Copy link
Contributor Author

Thanks for making the changes @gcsecsey - nice work!

I found some issues on my end when testing this PR. This is what I saw on my end: I started the pull operation and waited until the downloading backup step. Then, I logged out and noticed that some of the buttons were stuck in the "Importing" state:

Image (see the top right corner)

Then, when I log in as a different user, I see the following issue on the import screen:

Image

Thanks for the review @katinthehatsite, great catch! This was caused by the import/export also being tracked in the ImportExportProvider context, not just Redux. I set this to also be reset on logout.

I also encountered a stuck state when trying to pull a site that caused a db import issue:

image

I updated the component to treat this state as a pull error as well, to unblock this state. However, I'm not sure if this is the best approach to handle this. I think ideally we'd show the pull operation as completed, and separately also show the db import error in a dialog, similarly to how it's done when importing, right?

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Mar 13, 2026

📊 Performance Test Results

Comparing 0d93adc vs trunk

app-size

Metric trunk 0d93adc Diff Change
App Size (Mac) 1236.39 MB 1236.40 MB +0.01 MB ⚪ 0.0%

site-editor

Metric trunk 0d93adc Diff Change
load 1897 ms 1586 ms 311 ms 🟢 -16.4%

site-startup

Metric trunk 0d93adc Diff Change
siteCreation 7110 ms 7072 ms 38 ms ⚪ 0.0%
siteStartup 3929 ms 3926 ms 3 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

@gcsecsey gcsecsey requested review from a team and katinthehatsite March 13, 2026 15:10
@gcsecsey gcsecsey requested a review from fredrikekelund March 17, 2026 10:54
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.

4 participants