Performance: Migrate ToggleControl to @wordpress/components#48177
Performance: Migrate ToggleControl to @wordpress/components#48177
Conversation
Direct swap of the three ToggleControl usages on the Jetpack Performance settings screen off the @automattic/jetpack-components wrapper onto the upstream @wordpress/components primitive. Preserves click-blocking during save operations by merging the wrapper's `toggling` prop into the existing `disabled` prop. Part of #48160.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
nerrad
left a comment
There was a problem hiding this comment.
Code looks okay. This does change behaviour of the toggle though where it isn't actually toggled until the action completes successfully. On slow connections or saving actions that are slower, that does mean the only feedback the user will have is the disabled button and the toast notification. Arguably, this could be better than an optimistic toggle and then it unsets on unsuccessful saves.
I don't know whether in practice this is a big deal though, and the loss of the optimistic saves is already noted in the PR description, so I'll preapprove.
CGastrell
left a comment
There was a problem hiding this comment.
LGTM! Concern raised by @nerrad is legit, but this is already handling the possible "is toggling" state through disabled state.
Worth keeping this in mind if we're gonna turn the settings behavior to an optimistic approach.
Proposed changes
ToggleControlusages on the Jetpack Performance settings screen off the@automattic/jetpack-componentswrapper and onto@wordpress/componentsdirectly. Files:_inc/client/performance/speed-up-site.jsx,media.jsx,search.jsx.togglingprop todisabled={ toggling || existingDisabled }at each call site so click-blocking during in-flight saves is preserved.__nextHasNoMarginBottomat each call site (the wrapper set this automatically).projects/js-packages/components/components/toggle-control/and its re-export in@automattic/jetpack-componentsare untouched. Dead-code cleanup, if desired, belongs in a follow-up.Other information
Part of #48160.
The
@automattic/jetpack-componentsToggleControlwrapper does more than re-export the upstream primitive — it styles the track in Jetpack green, ships custom track/thumb sizing, fades opacity while saving, and optimistically flips the thumb before the API round-trip returns.@wordpress/uihas noToggleControlyet, so this consumer lands on@wordpress/componentsas an interim step. Expected UX deltas on the Performance screen:--jp-green-40→--wp-admin-theme-color.@wordpress/componentsFormTogglesizing.is-togglingopacity fade while a setting is saving.disabled.Screenshots
JN rsync target:
plugins/jetpack· Baseline: current JN state with Jetpack connected · JN site:thoughtfully-remarkable-device.jurassic.ninjaTesting instructions
__nextHasNoMarginBottomor deprecated props on the Performance screen.plugins/jetpack(other/patch).