Skip to content

Sync: Remove unnecesary ref when initializing Push states - #1980

Merged
epeicher merged 1 commit into
trunkfrom
update/sync-context-update-push-states
Oct 31, 2025
Merged

Sync: Remove unnecesary ref when initializing Push states#1980
epeicher merged 1 commit into
trunkfrom
update/sync-context-update-push-states

Conversation

@epeicher

@epeicher epeicher commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • Removes the ref that prevented the useEffect to run multiple times as it is not necessary anymore after be16976
  • Removes the void operator as the promise is handled by the .catch

Testing Instructions

  • Apply these changes and run npm start
  • Navigate to the Sync tab and connect a site or use any existing connected site
  • Select Push
  • Wait for the status to be progressed to Backing up remote site…
  • Select another site before leaving Studio
  • Press Cmd+Q to quit Studio
  • Check that the dialog appears and notify that the operation will continue. Accept and quit Studio
  • Open Studio again
  • Select the site that has a Push in progress
  • Navigate to the Sync tab
  • Check the progress continues
  • Check in the network tab the import endpoint is checked only once for the connected sites initially, and it is not executed when selecting the Sync tab of different sites every time. Please note that if there is an operation in progress, the import endpoint will be checked periodically.
CleanShot 2025-10-30 at 18 48 01@2x

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@epeicher
epeicher requested a review from a team October 30, 2025 17:49
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Test Results

Comparing 9b7589b vs trunk

site-editor

Metric trunk 9b7589b Diff Change
load 15559.00 ms 11644.00 ms -3915.00 ms 🟢 -25.2%

site-startup

Metric trunk 9b7589b Diff Change
siteCreation 23217.00 ms 21196.00 ms -2021.00 ms 🟢 -8.7%
siteStartup 6997.00 ms 6007.00 ms -990.00 ms 🟢 -14.1%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

@fredrikekelund fredrikekelund 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.

LGTM 👍 I haven't tested, but I feel confident about the code changes.


const { client } = useAuth();
const { pushStatesProgressInfo } = useSyncStatesProgressInfo();
const hasInitialized = useRef( false );

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.

At first, I was going to say that I think it's a good idea to make our intention explicit, only to run this effect once (i.e., to preserve the ref). However, after thinking about it, I realized that re-running it whenever client changes actually makes a lot of sense, since it will rerun when the user authenticates with WordPress.com.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, indeed, I didn't think of that use case, but I have tested it, and it works perfectly. The progress is displayed after authentication 👍

};

void initializePushStates().catch( ( error ) => {
initializePushStates().catch( ( error ) => {

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.

👍

@epeicher
epeicher merged commit 0115c08 into trunk Oct 31, 2025
14 checks passed
@epeicher
epeicher deleted the update/sync-context-update-push-states branch October 31, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants