WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.19k forks source link

Block Style Variations: Reuse block metadata in WP_Theme_JSON::get_valid_block_style_variations() for better performance #66539

Closed ramonjd closed 3 days ago

ramonjd commented 4 days ago

What?

Backporting theme json performance optimizations from https://github.com/WordPress/wordpress-develop/pull/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 https://github.com/WordPress/gutenberg/pull/57908 that you can add under /styles.

{
    "$schema": "https://schemas.wp.org/trunk/theme.json",
    "version": 2,
    "title": "Variation A",
    "blockTypes": [ "core/group", "core/columns", "core/media-text" ],
    "styles": {
        "color": {
            "background": "#eed8d3",
            "text": "#201819"
        },
        "elements": {
            "heading": {
                "color": {
                    "text": "#201819"
                }
            }
        },
        "blocks": {
            "core/group": {
                "color": {
                    "background": "#825f58",
                    "text": "#eed8d3"
                },
                "elements": {
                    "heading": {
                        "color": {
                            "text": "#eed8d3"
                        }
                    }
                }
            }
        }
    }
}
github-actions[bot] commented 4 days ago

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.

github-actions[bot] commented 4 days ago

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.

github-actions[bot] commented 4 days ago

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

ramonjd commented 3 days ago

Thanks for the help and reviews, everyone!