Skip to content

Editor: Cache merged global styles in the theme_json group - #13192

Draft
sirreal wants to merge 2 commits into
WordPress:trunkfrom
sirreal:agent/test-order-block-supports-isolation
Draft

Editor: Cache merged global styles in the theme_json group#13192
sirreal wants to merge 2 commits into
WordPress:trunkfrom
sirreal:agent/test-order-block-supports-isolation

Conversation

@sirreal

@sirreal sirreal commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Removes the unresettable function-static global-styles snapshot from layout rendering.
  • Caches merged global styles in the invalidatable, non-persistent theme_json cache group, including origin and variable-resolution mode in each key.
  • Clears the new keys through wp_clean_theme_json_cache() and bypasses them in theme development mode.

Verification

  • Replayed the original failing seed and focused contaminator/consumer sequence during diagnosis.
  • 100 consecutive fresh randomized block-supports-group runs passed on the final implementation; each completed 400 tests and 532 assertions.
  • Seeds 1789070001 through 1789070100 all completed within the 30-second hard bound.
  • PHP syntax checks and git diff --check passed.

Trac: https://core.trac.wordpress.org/ticket/65893

`wp_get_global_styles()` is the only `theme_json` accessor without an
object cache. Every call builds a fresh `WP_Theme_JSON` and merges four
origins through `WP_Theme_JSON_Resolver::get_merged_data()`, at roughly
0.3ms per call.

`wp_render_layout_support_flag()` worked around that cost with a
function-static snapshot that nothing could invalidate, so a layout
rendered after a theme change kept the previous `blockGap` value for the
remaining lifetime of the PHP process. That is what forced the block
style variation test to run in a separate process.

Cache the merged styles in the non-persistent `theme_json` group, keyed
by origin and by the `resolve-variables` transform, and clear those keys
in `wp_clean_theme_json_cache()`, exactly as `wp_get_global_settings()`
already does. The function-static in `wp_render_layout_support_flag()` is
then unnecessary and is removed, so `switch_theme` refreshes layout
styles and `@runInSeparateProcess` can be dropped from the test.

`gallery.php` and `image.php` also call `wp_get_global_styles()` on every
render with no cache of their own, and benefit as well.

The function-static additionally ignored `wp_is_development_mode( 'theme' )`,
so theme developers saw stale block gaps in layout output. The object
cache respects that check.

Measured on this branch, 1,000 iterations, median of five runs:

  wp_get_global_styles()           before 311.61ms   after  0.23ms
  wp_render_layout_support_flag()  before  15.19ms   after 15.73ms

Trac ticket: https://core.trac.wordpress.org/ticket/65893
@sirreal sirreal changed the title Tests: Isolate block style variation layout test Editor: Cache merged global styles in the theme_json group Aug 20, 2026
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant