-
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
Layout: merge CSS rule for block gap #43052
Conversation
I tested this one as well, and it works as expected. Thanks! That said, as you mentioned in your comment, things definitely get a bit tricky here. I think I would be inclined to disable optimization for now until more testing is done. The batching is pretty slick, but I'm worried about other issues related to style order. I'll be doing more testing this week to see if I can find anything else. |
Same here. Thanks for getting the multiple PRs up, though, so we've got options! |
I guess it wouldn't hurt to merge this one anyway, what do you think @andrewserong ? Or should we keep it to use as a test case for follow up tweaks to the optimization code? |
I haven't had a chance to test this yet, but I'd lean toward keeping it as a test case, personally. Ideally we're adding a single selector at a time? Happy to give it a test later on today if you think it's better to get it technically working first, though! |
lib/block-supports/layout.php
Outdated
'declarations' => array( | ||
'margin-block-start' => '0', | ||
'margin-block-end' => '0', | ||
'margin-block-end' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => "$selector > * + *", |
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.
We could simply change this selector to be more specific... Since this needs to override the other one and they both have the same specificity, we should raise the specificity of this one
'selector' => "$selector > * + *", | |
'selector' => "$selector.$selector > * + *", |
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.
Works great! Committed (without the extra .
)
I'm happy to go with either if we think we should merge this one.
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.
Nice that this one fixes the current use case, and it feels a bit neater than combining the selectors in the first rule. Since this is only output when there is a real gap value, I don't at all object to upping the specificity here 👍
I'm wondering if it reveals a drawback or potential issue for the optimisation that we should look into separately, though. It's possibly going to be fairly common for themes to expect styles to override earlier styles with the same specificity due to the order in which they're added. In the case of this particular gap rule, I believe it might have been originally implemented based on the rules from the following article / generator: https://every-layout.dev/layouts/stack/#the-generator
Also, once we go to implement optimisation in global styles, we'll need to be careful about the specificity of the rules, as upping the specificity at one level of the style chain might make it harder for rules at other levels. (e.g. base layout gap, versus block-level in theme gap, versus block-level in block attributes gap).
Resolves #43046
Alternative to
What?
In the layout abstraction, merge
$selector > *,$selector > * + *
selectors, only setmargin-block-start
if a gap value is available.Why?
So that the style engine optimization engine prints out the rules separately.
Note: this doesn't address to root cause, that is, the style engine doesn't care about the order of rules when combining selectors. Combined selectors are printed at the bottom of the stylesheet.
Testing Instructions
(Taken from #43046)
Example block code
Trunk
This PR