Style engine: switch off optimize by default #53085
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #52646
What?
The style engine's default behavior of combining selectors where the CSS declarations are equal results in errors where order matters.
This PR doesn't address the core issue, that is, maintaining the order of general selectors where CSS stylesheet opt-in to optimization.
I'm not convinced that it can given how general elements rules are. Optimization should therefore be "opt-in" only.
For example, many blocks, children of children of parents or whichever, can have the following selector applied to them:
.wp-element-1 a
. It's impossible for the style engine to know the intended hierarchy when combining such selectors with matching declarations. cc @aristath for thoughts.If we want the optimizations to work universally, I think elements block supports should create rules specific to the block that needs them. How, I'm not sure. Maybe if we're applying a link color to a paragraph block we could do something like
p.wp-element-1 > a
. 🤷🏻Why?
See: https://core.trac.wordpress.org/ticket/58811
Core patch: WordPress/wordpress-develop#4902
The bug is most evident in elements block supports CSS (links), which applies CSS rules to block wrappers that affect all child elements.
If a child element and another parent element (not the child's) share CSS declarations, the CSS selectors will be combined and placed towards of the end of the stylesheet thereby overriding any previous rules.
So far it's only occurring for elements (link colors) but it potentially affects any selector that has general application, e.g.,
.block-wrapper-class a
The bug is only visible on the frontend (not the editor).
How?
Flipping the
optimize
flag and updating testsTesting Instructions
Follow the test instructions in #52646
Here is some test HTML:
Using the above code you should see the following on the frontend