Skip to content

Default sites to theme development mode so new theme patterns register - #5159

Closed
chubes4 wants to merge 1 commit into
trunkfrom
fix/theme-development-mode
Closed

chubes4 wants to merge 1 commit into
trunkfrom
fix/theme-development-mode

Conversation

@chubes4

@chubes4 chubes4 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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

  1. Create and start a site on Twenty Twenty-Five. wp-config.php contains define( 'WP_DEVELOPMENT_MODE', 'theme' );.
  2. Load the front page, then add wp-content/themes/twentytwentyfive/patterns/repro.php with the header Slug: twentytwentyfive/repro.
  3. 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.
  4. 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?

@chubes4

chubes4 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

@chubes4 chubes4 closed this Oct 16, 2026
@chubes4
chubes4 deleted the fix/theme-development-mode branch October 16, 2026 20:58
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.

Theme pattern files are not registered until the pattern cache is cleared

1 participant