-
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
Try reducing specificity of global styles selectors only. #60106
Conversation
Size Change: +45 B (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
Flaky tests detected in fb490fb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8386140666
|
On a first quick glance this is looking good on my testing. Are we planning on changing specificity to the block's CSS or is that something we want to keep as is? I'm looking at the block's stylesheets to see what could be overriding theme styling via theme.json and I don't find much, so it might not be a big deal. I'll come back with more testing. |
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. |
Ok, delving deeper into the blocks' stylesheets I see that we have already covered our based in terms of what can be overrideable via GS. We need to think that in the future some of the things that can't be styled via GS will be and we will need to go back to the blocks' styles to ensure that specificity war is being won, but that shouldn't block this PR. Maybe we need to document that somewhere. |
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.
There are some weird :where
nesting when we have some elements inside blocks on theme.json. The final output seems to be working fine and the specificity is 0 like expected, but the CSS is a bit ugly I suppose. Not a blocker but I guess worth commenting.
The case in my example on TT4 would be:
"core/post-title": {
"elements": {
"link": {
"typography": {
"textDecoration": "none"
}
}
}
},
Turning into:
:where(.wp-block-post-title a:where(:not(.wp-element-button))) {
text-decoration: none;
}
Where in trunk it's just:
.wp-block-post-title a:where(:not(.wp-element-button)) {
text-decoration: none;
}
Thanks for reviewing and testing @MaggieCabrera !
I ended up not removing the
It would be good to ensure minimal specificity for all block-library styles as that's the general direction we've been heading in for a few years now. Again, that could be done as a follow-up. Also, as has already been commented in #57841, CSS cascade layers could be a great candidate for solving this problem in one go, but an exploration is needed to see if it's actually a viable solution for us right now. In the meantime, reducing global styles specificity is the main blocker for the extension of block style variations, so we're proceeding down this safer route for now. |
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 continuing to split up and work through #57841 👍
It looks like we're missing the :where
around global styles for blocks that use custom feature-level selectors e.g Image block and borders.
The required change is in the original PR and works when applied here. Once applied though the unit tests for the useGlobalStylesOutput
hook will need updating as per #57841 too.
I've mostly tested via the site editor's style book so far and from that side most blocks are working as expected.
Well spotted! Updated now. Thanks for reviewing! |
Sorry I missed some of the comments on the original PR! yeah, none of my comments are blockers, it seems like you've covered all the bases |
bbedcfb
to
d2b2b91
Compare
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've rebased this one to resolve the conflicts with the theme.json unit tests after the recent switch from body
to :root
for custom CSS properties (#42084).
Following that I've also given this another smoke test and it's testing well for me. Using the site editor's style book, all the global styles I tweaked were applied to the block. Those styles were also then reflected on the frontend still.
The prior issue with the feature selectors has been resolved as well.
I think this is in reasonable shape so I'll give it a tentative approval. Given the broad nature of the changes, it might pay to get an extra set of eyes from @MaggieCabrera before hitting merge.
@@ -244,12 +244,12 @@ function Iframe( { | |||
height: auto !important; | |||
min-height: 100%; | |||
} | |||
|
|||
body { | |||
/* Lowest specificity to not override global styles */ |
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.
Can confirm that this doesn't break the zoomed-out mode 👍
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.
This is looking good to me too, let's bring this in!
Awesome, thanks for reviewing folks! |
…60106) Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
…60106) Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
What?
Split out from #57841. This part handles only the global styles selectors: block, element and feature level. The layout selectors will follow in another PR, but I think, from my local testing, that this change works pretty well by itself.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast