Skip to content

Regenerate native PHP mu-plugins when an existing file has stale content - #4196

Merged
sejas merged 2 commits into
trunkfrom
fix-regenerate-stale-native-php-mu-plugins
Jul 15, 2026
Merged

Regenerate native PHP mu-plugins when an existing file has stale content#4196
sejas merged 2 commits into
trunkfrom
fix-regenerate-stale-native-php-mu-plugins

Conversation

@sejas

@sejas sejas commented Jul 14, 2026

Copy link
Copy Markdown
Member

Related issues

How AI was used in this PR

AI assisted with the implementation, tests, and verification; all changes were reviewed and validated manually against a live native PHP site.

Proposed Changes

Sites running on the native PHP runtime never picked up updated Studio mu-plugin content. Studio writes its mu-plugins to a temp directory and reuses that directory on subsequent site starts when it looks valid — but the validity check only compared plugin filenames. When a Studio update changed a plugin's content without renaming the file (e.g. the upcoming STU-1945 change that also disables Jetpack Stats in 0-deactivate-jetpack-modules.php), existing sites kept loading the stale version forever; only newly created sites got the updated behavior.

The reuse check now also compares each plugin file's content against what the current Studio version generates, and regenerates the whole directory on any mismatch. As a bonus, partially written or corrupted plugin files now self-heal on the next site start instead of being silently reused.

No user-visible behavior change for up-to-date sites: the directory is still reused when contents match, so there is no extra churn on every start or wp-cli invocation.

Testing Instructions

  • Apply this diff
diff --git a/packages/common/lib/mu-plugins.ts b/packages/common/lib/mu-plugins.ts
index 200c9277e..2cd79386e 100644
--- a/packages/common/lib/mu-plugins.ts
+++ b/packages/common/lib/mu-plugins.ts
@@ -339,6 +339,7 @@ function getStandardMuPlugins( options: MuPluginOptions ): MuPlugin[] {
 	muPlugins.push( {
 		filename: '0-deactivate-jetpack-modules.php',
 		content: `<?php
+			die('This mu-plugin got updated! 🔥');
 			// Disable Jetpack Protect so local auto-login is not blocked by 2FA.
 			// Disable Jetpack Stats so local previews and thumbnails do not bump remote site stats.
 			add_filter( 'jetpack_active_modules', 'studio_deactivate_jetpack_modules' );
  • npm run start and start a native PHP site.
  • Open the site and confirm the message from the diff appears, meaning the mu-plugin got updated
  • On trunk the mu-plugin was only updated for new sites and not existing ones

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@sejas sejas self-assigned this Jul 14, 2026
@wpmobilebot

wpmobilebot commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing e55c2a3 vs trunk

app-size

Metric trunk e55c2a3 Diff Change
App Size (Mac) 1352.85 MB 1352.85 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk e55c2a3 Diff Change
load 1069 ms 1062 ms 7 ms ⚪ 0.0%

site-startup

Metric trunk e55c2a3 Diff Change
siteCreation 7003 ms 6988 ms 15 ms ⚪ 0.0%
siteStartup 2359 ms 2350 ms 9 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

…-native-php-mu-plugins

# Conflicts:
#	packages/common/lib/tests/mu-plugins.test.ts
@sejas
sejas requested a review from a team July 15, 2026 13:21

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

Nice catch 🙌
Tested and confirmed the behavior and the fix, LGTM 👍

@sejas
sejas merged commit 47326e7 into trunk Jul 15, 2026
13 of 14 checks passed
@sejas
sejas deleted the fix-regenerate-stale-native-php-mu-plugins branch July 15, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants