-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Style Variations: Reuse block metadata in WP_Theme_JSON::get_valid_block_style_variations() for better performance #66539
Conversation
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
…_Type_Registry` to get block names.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
$registry = WP_Block_Type_Registry::get_instance(); | ||
$valid_block_names = array_keys( $registry->get_all_registered() ); | ||
$blocks_metadata = static::get_blocks_metadata(); | ||
$valid_block_names = array_keys( $blocks_metadata ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tentatively backporting this change too.
Core uses ::get_blocks_metadata()
to get valid block names. See: https://github.com/mukeshpanchal27/wordpress-develop/blob/trunk/src/wp-includes/class-wp-theme-json.php#L762
It has done it this way since 5.9 😄
Then I found this Gutenberg PR from 2022, which doesn't appear to have been backported:
Which is correct?
I think maybe we could use what Core has since ::get_valid_block_style_variations()
will now call ::get_blocks_metadata()
anyway.
cc @ajlende @oandregal @aaronrobertshaw @mukeshpanchal27 for advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for highlighting this. It might have been a factor in why the valid variations function evolved as it did.
I think maybe we could use what Core has since ::get_valid_block_style_variations() will now call ::get_blocks_metadata() anyway.
Agreed. It saves another update in core too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm, perhaps something that was added in gutenberg but not backported later to core? anyway, this seems a safe change to me given blocks metadata will recalculate the blocks that are registered (if they're different).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ramonjd, LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the help and reviews, everyone! |
…block_style_variations() for better performance (WordPress#66539) * Backporting theme json performance optimizations from WordPress/wordpress-develop#7586 * Tentatively backport using `get_blocks_metadata` instead of `WP_Block_Type_Registry` to get block names. Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
What?
Backporting theme json performance optimizations from WordPress/wordpress-develop#7586
Props @mukeshpanchal27
Why?
Reduce unnecessary calls to
::get_blocks_metadata()
.How?
Passing already-fetched data from
::get_blocks_metadata()
to::get_valid_block_style_variations(()
Testing Instructions
CI tests should pass. Smoke test a theme with style variations in the site editor.
Here's an example from #57908 that you can add under
/styles
.