Skip to content

Conversation

@nightnei
Copy link
Contributor

Followup to Add mu-plugin to prevent updates on selected WordPress versions #1120

Proposed Changes

Previously, users could select specific version for their WP site, but it worked incorrectly - it was still autoupdated to the latest. With this PR we give opportunity to select specific version and opportunity to keep always latest (with auto-updating it). Also This PR adds a few UI improvements and some refacrtoring:

  1. Created a new shared component for selecting WP version. So it will be consistently used in different places, w/o duplication of code.
  2. Previously, we went with approach to store wpVersion inside appdata-v1.json. It's an option, but there are a few disadvantages:
    2.1. With wpVersion were have 2 source of truth what is definitely not good. Much more reliable and stable to retrieve wp version from site instance, as we did it before.
    2.2 If user selected latest and we store it in appdata-v1.json, then to get specific version we always had to do soothing like wpVersions.find(iteam => item.version === 'latest'), what is not very nice.
    2.3 Folowing to 2.2 point above - even if we get the specific version with item.value === 'latest', we can't be sure that it' exactly the version which is used on this specific wp instance, so this way we can bugs.
    2.4. Storing isWpAutoUpdating: boolean makes code much cleaner, as you can see in this PR, since we don't need to add extra condition and we can easily distinguish the version and auto-updating status, since it's 2 different things.

Testing Instructions

I decided to record video, since there are a lot of testing instructions and video will simplify go through them.
Also, it will help you (the reviewer) to quickly understand how it works in all scenarios.

https://drive.google.com/file/d/1eXwUk_B8Gkd3-28cVIEj4Sg7YCV9t4Sq/view?usp=sharing


type Option = { label: string; value: string };

export const addWpVersionToList = ( newOption: Option, options: Option[] ): Option[] => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I rewrote this function from mutability to immutability.
  2. Moved close to wpVersionsSelector, since it doesn';t make sense to keep it globally now, when we have only one pleace where we use it.

@@ -0,0 +1,121 @@
import { SelectControl, Icon } from '@wordpress/components';
Copy link
Contributor Author

@nightnei nightnei Apr 10, 2025

Choose a reason for hiding this comment

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

Now we have separate component which doesn't store any context, so it's already used in 2 places and can be easily reused in the future, w/o extra conditions.
Also now we have consistency with rendering it for creating/updating website, so it works the same way, we don't need to copy-paste etc.

const { __ } = useI18n();
const { updateSite, selectedSite, stopServer, startServer } = useSiteDetails();
const [ isChangeWpError, setIsChangeWpError ] = useState( '' );
const [ errorUpdatingWpVersion, setErrorUpdatingWpVersion ] = useState< string | null >( null );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just renamed, since it's not a predicate


// Only add the auto-updates disabling plugin for non-latest WordPress versions
if ( options?.wordPressVersion && options.wordPressVersion !== 'latest' ) {
if ( ! options.isWpAutoUpdating ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also good example of benefit from isWpAutoUpdating - the condition is much more simple.


// We use SiteDetails for storing it in appdata-v1.json, so this meta was introduced for extra data which is not stored locally
type SiteServerMeta = {
wpVersion?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sejas This is only one point where I am not sure that it's the best approach. I am not very familiar with wpnow etc, so could you please take a look on my approach to say - is it good, or maybe it's better to go another way.

@nightnei nightnei requested review from a team, sejas and wojtekn April 10, 2025 14:56
Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

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

I tested multiple cases of existing and new sites, and everything worked correctly. I'll give it a second pass tomorrow.

First, I like that we have a common component. We could rename the label Keep Latest Stable to Latest or Autoupdate Latest. Sites with older versions are marked as "Keep Latest Stable," which I believe is correct, as they will eventually be auto-updated.

For now, the edge case I'm uncertain about are Beta/Nightly versions. Existing sites with those versions are marked as Keep Latest Stable when they are not stable at all.
We add the version to the options, which is great. I think we should also mark that version as selected.
Additionally, I think we should continue auto-updating those beta versions, but it's not a strong opinion.

Screenshot 2025-04-14 at 18 29 58 2

</Tooltip>
</div>

<WPVersionSelector
Copy link
Member

Choose a reason for hiding this comment

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

Nice! A single component 💪

};
}

if ( newSite.wpVersion !== wpVersion ) {
Copy link
Member

Choose a reason for hiding this comment

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

Everything seems to be working correctly, creating new sites and editing sites.
So removing the test should update site with WordPress version after creation makes sense.

@wojtekn
Copy link
Contributor

wojtekn commented Apr 15, 2025

Can we display the actual version, e.g., "6.7.2 (latest)" instead of "Keep Latest Stable"?

For now, the edge case I'm uncertain about are Beta/Nightly versions. Existing sites with those versions are marked as Keep Latest Stable when they are not stable at all.
We add the version to the options, which is great. I think we should also mark that version as selected.
Additionally, I think we should continue auto-updating those beta versions, but it's not a strong opinion.

I think those shouldn't be auto-updated, and the first one should be the only one that is getting auto-updated.

Regarding the edit form, it seems there is a bug there as the "Keep Latest Stable" is displayed for each site. I think the currently used version should be preselected.

Copy link
Member

sejas commented Apr 15, 2025

All existing sites are auto-updated, so eventually if those sites are used they will get updated to the latest version. That's the logic behind the picker showing "Keep Latest Stable" and not the specific version.

These existing sites are an edge case and any logic we add to handle them should be something "temporal". @nightnei, Maybe the first time Studio starts we could check the WP version in all existing sites and add isWpAutoUpdating: false in all of them that doesn't have the 6.7.2 version.

Regarding the edit form, it seems there is a bug there as the "Keep Latest Stable" is displayed for each site. I think the currently used version should be preselected.

Cool!, let's keep them as "pinned" versions.

@nightnei
Copy link
Contributor Author

Can we display the actual version, e.g., "6.7.2 (latest)" instead of "Keep Latest Stable"?

@wojtekn regarding this point - I found it confusing to have both "6.7.2" and "6.7.2 latest", more details I descibed in this thread -p1744195024724019-slack-C04GESRBWKW.

Also, I was talking with ChatGPT about it and even w/o providing my thoughts he said that it's not clear for users to understand the difference bethween these options, since in both cases 6.7.2 is indeed latest. So he recommended to flag that the first option keeps site wiuth latest WP version and in teh second it uses static version.

Take a look please on the thread.
WDYT?

@nightnei
Copy link
Contributor Author

All existing sites are auto-updated, so eventually if those sites are used they will get updated to the latest version. That's the logic behind the picker showing "Keep Latest Stable" and not the specific version.

These existing sites are an edge case and any logic we add to handle them should be something "temporal".

@wojtekn @sejas I have teh same thoughts. Also, additionally, as @sejas mentioned before - we would have inconsistency with rendering this warning
Screenshot 2025-04-15 at 09 53 51

@nightnei
Copy link
Contributor Author

@nightnei, Maybe the first time Studio starts we could check the WP version in all existing sites and add isWpAutoUpdating: false in all of them that doesn't have the 6.7.2 version.

@sejas hm, it seems it's great idea to achive consistency 👍 I will think about it

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

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

I didn't test it yet. I left a few comments in the new code. Let me know what you think.

@nightnei nightnei force-pushed the add/preventUpdatesWpVersion branch from c334dcd to 88f70be Compare April 15, 2025 13:18
@bcotrim bcotrim force-pushed the add/prevent_updates_wp_versions branch from e4e75d9 to fad6c3d Compare April 15, 2025 15:14
@nightnei nightnei changed the base branch from add/prevent_updates_wp_versions to trunk April 16, 2025 09:29
Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

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

Feature-wise works well.

Copy link
Member

@sejas sejas 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 the changes.
I confirm new created sites work as expected and latest will be autoupdated, while betas and stables have "isWpAutoUpdating": false,

Existing sites are identified with the correct version too.

text={ __( 'WordPress Core automatic updates will be disabled for this site.' ) }
placement="top"
>
<Icon icon={ warning } className="text-[#ae5c00]" size={ 16 } />
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this color is required. I don't see any change in the UI after removing it.

Suggested change
<Icon icon={ warning } className="text-[#ae5c00]" size={ 16 } />
<Icon icon={ warning } size={ 16 } />

Screenshot 2025-04-21 at 11 52 02

@sejas
Copy link
Member

sejas commented Apr 21, 2025

I noticed the performance metrics is failing in this PR. I think we need to fix that before merging it.

@nightnei nightnei merged commit 452ff62 into trunk Apr 21, 2025
8 checks passed
@nightnei nightnei deleted the add/preventUpdatesWpVersion branch April 21, 2025 12:05
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.

5 participants