Make WordPress Core

Opened 9 months ago

Closed 9 months ago

Last modified 5 months ago

#62234 closed enhancement (fixed)

Theme JSON: remove redundant check and relocate $selectors assignment in get_block_nodes()

Reported by: ramonopoly's profile ramonopoly Owned by: ramonopoly's profile ramonopoly
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch, gutenberg-merge
Focuses: Cc:

Description

A ticket to track the backport of Gutenberg PR: https://github.com/WordPress/gutenberg/pull/66154

In WP_Theme_JSON::get_block_nodes(), remove the redundant check for $theme_json['styles'], which means WP_Theme_JSON::get_blocks_metadata() is only called if necessary.

This also has the potential to slightly improve the performance of functions such as [wp_add_global_styles_for_blocks](https://github.com/wordpress/wordpress-develop/blob/trunk/src/wp-includes/global-styles-and-settings.php#L254) that call WP_Theme_JSON::get_styles_block_nodes(), where no block styles exist.

Change History (9)

This ticket was mentioned in PR #7575 on WordPress/wordpress-develop by @ramonopoly.


9 months ago
#1

Backporting:

## What? Why? How?

In WP_Theme_JSON::get_block_nodes(), Remove redundant check for $theme_json['styles'], which means WP_Theme_JSON::get_blocks_metadata() is only called if necessary.

This also has the potential to slightly improve the performance of functions such as wp_add_global_styles_for_blocks that call WP_Theme_JSON::get_styles_block_nodes(), where no block styles exist.

## Testing Instructions
CI tests should pass.
Smoke test in a block theme with lots of block styles, like TT4 and a theme with none, like Emptytheme

@mukesh27 commented on PR #7575:


9 months ago
#2

@ramonjd Good if we commit for 6.7. WDYT?

@ramonopoly commented on PR #7575:


9 months ago
#3

Good if we commit for 6.7. WDYT?

Thank you, yes!

@ramonopoly commented on PR #7575:


9 months ago
#4

Updated with code suggestion. Ready for final ✔️

@mukesh27 commented on PR #7575:


9 months ago
#5

@ramonjd Move into 6.7 and commit when you have moment.

#6 @ramonopoly
9 months ago

  • Milestone changed from 6.8 to 6.7

#7 @ramonopoly
9 months ago

  • Owner set to ramonopoly
  • Resolution set to fixed
  • Status changed from new to closed

In 59262:

Theme JSON: remove redundant styles check and relocate $selectors assignment.

In WP_Theme_JSON::get_block_nodes(), remove redundant check for $theme_json['styles'], which means WP_Theme_JSON::get_blocks_metadata() is only called if necessary.

Also skip unnecessary $selector assignment if only nodes are to be returned.

Props ramonopoly, mukesh27.
Fixes #62234.

@ramonopoly commented on PR #7575:


9 months ago
#8

Committed in r59262 / 1508e5bf0fa3ad2d001de08eab4dee49985bb322

#9 @joemcgill
5 months ago

  • Keywords changed from has-patch gutenberg-merge to has-patch, gutenberg-merge
Note: See TracTickets for help on using tickets.