You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Default sites to theme development mode so new theme patterns register - #5159
Claude (via the Pi coding agent in a Roadie session) found this while comparing Studio Code agent runs, traced it to the code, wrote the change and its test, and ran the verification below. Opened as a draft for human review.
Proposed Changes
A pattern file added to a theme's patterns/ directory isn't registered on a Studio site until the theme's pattern cache is cleared. That's because WP_Theme::get_block_patterns() only skips its cache in theme development mode, and Studio sites leave WP_DEVELOPMENT_MODE empty. theme.json edits go through a similar cache.
New and existing sites now get define( 'WP_DEVELOPMENT_MODE', 'theme' ) in wp-config.php when the site doesn't define it already. A site's own value, such as all or '', is never replaced.
It goes in wp-config.php because WordPress reads the mode in wp_initial_constants(), before mu-plugins load, and caches the result. Defining it from Studio's mu-plugin loader would be too late.
Trade-off: local sites skip core's theme pattern and theme.json caches. That's what this mode exists for, but it's a default change for every Studio user.
Testing Instructions
Create and start a site on Twenty Twenty-Five. wp-config.php contains define( 'WP_DEVELOPMENT_MODE', 'theme' );.
Load the front page, then add wp-content/themes/twentytwentyfive/patterns/repro.php with the header Slug: twentytwentyfive/repro.
studio wp eval 'var_dump( WP_Block_Patterns_Registry::get_instance()->is_registered( "twentytwentyfive/repro" ) );' prints true. On trunk it prints false until wp_get_theme()->delete_pattern_cache() runs.
Change the define to 'all', then restart the site. The value stays 'all'.
Steps 1–4 were run on a throwaway site. npx vitest run apps/cli/lib/native-php/tests/site-setup.test.ts passes.
Pre-merge Checklist
Have you checked for TypeScript, React or other console errors?
Closing in favour of a narrower fix. Measured on a fresh site, WP_DEVELOPMENT_MODE made the front page about twice as slow (median 0.18 s with it off, 0.39 s with theme, 0.47 s with all), because every request rebuilds patterns and global styles. That cost would land on every Studio user just to fix a case that only comes up when a pattern file is added.
The agent now clears that theme's pattern cache (WP_Theme::delete_pattern_cache()) right after it writes a file in patterns/, on the spike in #5146. I checked it end to end: a new pattern that was not registered became registered after the clear. #5158 stays open for people who add pattern files by hand.
AI assistance: Claude (via the Pi coding agent in a Roadie session) took the measurements and wrote this comment, as asked by Chris.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
How AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) found this while comparing Studio Code agent runs, traced it to the code, wrote the change and its test, and ran the verification below. Opened as a draft for human review.
Proposed Changes
patterns/directory isn't registered on a Studio site until the theme's pattern cache is cleared. That's becauseWP_Theme::get_block_patterns()only skips its cache in theme development mode, and Studio sites leaveWP_DEVELOPMENT_MODEempty.theme.jsonedits go through a similar cache.define( 'WP_DEVELOPMENT_MODE', 'theme' )inwp-config.phpwhen the site doesn't define it already. A site's own value, such asallor'', is never replaced.wp-config.phpbecause WordPress reads the mode inwp_initial_constants(), before mu-plugins load, and caches the result. Defining it from Studio's mu-plugin loader would be too late.theme.jsoncaches. That's what this mode exists for, but it's a default change for every Studio user.Testing Instructions
wp-config.phpcontainsdefine( 'WP_DEVELOPMENT_MODE', 'theme' );.wp-content/themes/twentytwentyfive/patterns/repro.phpwith the headerSlug: twentytwentyfive/repro.studio wp eval 'var_dump( WP_Block_Patterns_Registry::get_instance()->is_registered( "twentytwentyfive/repro" ) );'printstrue. On trunk it printsfalseuntilwp_get_theme()->delete_pattern_cache()runs.'all', then restart the site. The value stays'all'.Steps 1–4 were run on a throwaway site.
npx vitest run apps/cli/lib/native-php/tests/site-setup.test.tspasses.Pre-merge Checklist