MSD: Show version switch progress when changing WordPress version#109795
MSD: Show version switch progress when changing WordPress version#109795arthur791004 wants to merge 4 commits intotrunkfrom
Conversation
Jetpack Cloud Live (direct link)
Automattic for Agencies Live (direct link)
Dashboard Live (dotcom) (direct link)
|
|
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
| const mutation = useMutation( { | ||
| ...siteWordPressVersionMutation( site.ID ), | ||
| onSuccess: () => { | ||
| backupState.setEnqueued( true ); | ||
| setIsSwitched( false ); | ||
| queryClient.invalidateQueries( sitePendingWordPressVersionQuery( site.ID ) ); | ||
| }, | ||
| meta: { | ||
| snackbar: { | ||
| error: __( 'Failed to save WordPress version.' ), | ||
| }, | ||
| }, | ||
| } ); |
There was a problem hiding this comment.
Spreading siteWordPressVersionMutation and then declaring onSuccess at the same level silently replaces the mutation's own onSuccess, so queryClient.invalidateQueries( siteWordPressVersionQuery( siteId ) ) defined there is never called.
❌ Incorrect - overrides mutation option callbacks
onSuccess: () => setShowSuccessMessage( true ), // Breaks cache updates!
The component-specific side-effects should be passed as a callback to mutate(). Since the callbacks reference hook-internal state, expose a switchVersion wrapper from this hook instead of the raw mutation:
| const mutation = useMutation( { | |
| ...siteWordPressVersionMutation( site.ID ), | |
| onSuccess: () => { | |
| backupState.setEnqueued( true ); | |
| setIsSwitched( false ); | |
| queryClient.invalidateQueries( sitePendingWordPressVersionQuery( site.ID ) ); | |
| }, | |
| meta: { | |
| snackbar: { | |
| error: __( 'Failed to save WordPress version.' ), | |
| }, | |
| }, | |
| } ); | |
| const mutation = useMutation( { | |
| ...siteWordPressVersionMutation( site.ID ), | |
| meta: { | |
| snackbar: { | |
| error: __( 'Failed to save WordPress version.' ), | |
| }, | |
| }, | |
| } ); | |
| const switchVersion = ( version: string ) => { | |
| mutation.mutate( version, { | |
| onSuccess: () => { | |
| backupState.setEnqueued( true ); | |
| setIsSwitched( false ); | |
| }, | |
| } ); | |
| }; |
Then update VersionSwitchState to expose switchVersion (and isPending from mutation.isPending) instead of the raw mutation, and call versionSwitch.switchVersion( formData.version ) from VersionForm.
When changing the WordPress version, show contextual notices that track the full switch lifecycle: - "Switching to WordPress X..." while backup is queued - Progress percentage while backup runs - "Backup completed. Now switching..." after backup finishes - "Your site is now running WordPress X." once the version changes - Error notice if the backup fails The Save button stays disabled throughout the switch. After backup completes, the WP version is polled until the switch is confirmed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Wrap form in a fieldset that disables both the dropdown and Save
button while the version switch is in progress.
- Show backup progress in the notice content ("Generating backup...
(X% progress)") with a clean title ("Switching to WordPress X...").
- Poll backups throughout the entire switch, not just during backup.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add fetchPendingWordPressVersion and sitePendingWordPressVersionQuery to poll /hosting/wp-version/pending for in-progress updates. - Split settings-wordpress into index.tsx (page shell), version-form.tsx (form with version switch logic), and version-switch-notice.tsx. - Track isSwitched as the transition from switching to not switching (wasSwitching && !isSwitching) so it works even if the page loads mid-switch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add fetchPendingWordPressVersion and sitePendingWordPressVersionQuery
to poll /hosting/wp-version/pending for in-progress updates.
- Split settings-wordpress into index.tsx (page shell),
version-form.tsx (form), use-version-switch.ts (hook), and
version-switch-notice.tsx (notices).
- Track isSwitched via usePrevious (wasSwitching && !isSwitching).
- Resolve version tag ("beta") to display string ("7.0-RC2") via
wpOrgCoreVersionQuery. Show actual software_version in success notice.
- Re-fetch site data after switch completes to get latest
software_version for the success notice.
- Show fallback notice when pending version exists but backup is idle.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
32e9f5e to
cfe227c
Compare
| // Check if there's a pending version switch. | ||
| const { data: pendingVersion } = useQuery( sitePendingWordPressVersionQuery( site.ID ) ); | ||
| const isSwitching = !! pendingVersion; | ||
| const wasSwitching = usePrevious( isSwitching ); |
There was a problem hiding this comment.
I think using useReducer could simplify state handling. Let me spin up a branch to test that.
fushar
left a comment
There was a problem hiding this comment.
I'm not sure why, but I can't see the new backup if I test this on an A4A dev site. But on regular Business site, it appears correctly 🤔 can anyone also test (cc @StevenDufresne), maybe we need to exclude A4A from the beta program.
| <Button | ||
| variant="primary" | ||
| type="submit" | ||
| isBusy={ isPending } |
There was a problem hiding this comment.
I think it's visually nicer if we keep the button busy until the version switch actually finishes.
Fixes DOTCOM-16577
Summary
useBackupStatehook for backup lifecycle trackingDepends on: #109747
Demo
demo.mov
Test plan
Pre-merge Checklist
🤖 Generated with Claude Code