Skip to content

Try generating block element selectors only when element styles exist - #79465

Open
tellthemachines wants to merge 2 commits into
trunkfrom
try/element-selectors-only-when-needed
Open

Try generating block element selectors only when element styles exist#79465
tellthemachines wants to merge 2 commits into
trunkfrom
try/element-selectors-only-when-needed

Conversation

@tellthemachines

Copy link
Copy Markdown
Contributor

What?

The description of #76556 states that "For one site I was using to test with I found that there were over 4,000 calls to prepend_to_selector() just to bootstrap WordPress". That sounds like a lot for a function that's only called inside get_block_element_selectors so I looked into it. Turns out we're generating element selectors for every single block that's registered (not even only the blocks on the page that loads), whether it has element styles or not. We shouldn't need to do that.

This PR introduces a check for the existence of element styles, or nested element styles inside breakpoints or style variations for each block, so that we can generate the selectors only for the blocks that need them.

This is not intended as a replacement for #76556, but as a further optimisation.

Testing Instructions

Check that element styles are still being applied correctly to blocks, their viewport state styles and their style variations.

Use of AI Tools

Used codex/gpt 5.5 to validate my initial assessment and make changes based on it. Human reviewed by myself.

@tellthemachines tellthemachines self-assigned this Jun 24, 2026
@tellthemachines tellthemachines added the [Type] Performance Related to performance efforts label Jun 24, 2026
@github-actions

Copy link
Copy Markdown

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: tellthemachines <isabel_brison@git.wordpress.org>

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

@github-actions

Copy link
Copy Markdown

Flaky tests detected in a859f86.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28077257124
📝 Reported issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Performance Related to performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant