-
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
Apply ! important to user preset styles for theme.json themes only #39660
Apply ! important to user preset styles for theme.json themes only #39660
Conversation
…d provide opt-out
Hey, just commenting on direction, not implementation: if we make it optional, how do we make sure users can style blocks whose selector has a higher specificity? Example. Personally, I feel that our goal should be to explore whether we can remove Two potential approaches we could explore are:
|
@oandregal The theory was to have it turned on by default for I think it would be good if we can see the above as a short term temporary fix to get around the issues that
This would be a useful exercise I think - only fixes things for core blocks of course, but we could provide guidance to 3rd party block authors on how to ensure the user applied block supports are applied correctly.
👍 |
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 have removed the As it stands now the PR provides a quick fix to remove the issues that Classic themes are experiencing with the addition of |
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.
Thank you for all the efforts in refining a short term solution for this issue @glendaviesnz 🙇
I believe the current approach that avoids adding a specific theme.json flag makes sense. Given the direction we appear to be heading in removing all !important
rules, I agree the new flag would likely have just added to our backwards compatibility concerns.
✅ This PR tests as advertised for me.
✅ The compute_preset_classes
function migrated to 6.0
compat folder follows 5.9
but with desired tweak
🟠 @ramonjd's suggestion to tweak prioritise
to prioritize
is still relevant
🔴 WP_Theme_JSON_Gutenberg_Test
needs updating
I think this is the best direction, though there is some concern about browser support and excessive use of .wp-block-post-title {
color: green;
}
.wp-block-post-title h1 {
color: inherit;
}
.has-red-color {
color: red;
} |
@aaronrobertshaw have fixed the above |
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 those fixes @glendaviesnz 👍
✅ All the unit tests are now passing
✅ PR still tests as advertised
✅ !important
is included/excluded from styles appropriately
@oandregal what are your thoughts on the approach of just disabling this by default for non theme.json themes in 6.0, so at least Classic themes go back to how they were before this change, with a view to following up as quickly as possible with an option to remove it for all themes if feasible. I removed the toggle in theme.json because of potential issues with backwards compat, etc. especially if this is only a temporary solution. |
foreach ( $slugs as $slug ) { | ||
$css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ); | ||
$class_name = static::replace_slug_in_string( $class, $slug ); | ||
$prioritize_user_presets = ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) ? ' !important' : ''; |
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.
So far the WP_Theme_JSON
class has stayed theme-agnostic and it was pure (it only used the input data passed to it to compute the output, nothing from the surrounding environment). The WP_Theme_JSON_Resolver
was the one that picked up environment data. I think we should keep these concerns separated.
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.
👍 Good point
I stand by #39660 (comment) This logic was introduced for user styles to have higher priority than theme styles. Changing the behavior introduces some other issues (classic themes being able to override user styles). You may want to engage others as well: cc @youknowriad @mtias @mcsf @jorgefilipecosta |
Yep, I understand and agree with the need for this. The use of |
I think we will struggle to get an agreement that a temporary fix like this should be included, and the time is probably better spent looking for a permanent fix that allows the removal of |
This is a proposed interim solution to the issues outlined here, with the view to exploring removal of the
! important
from user presets across all themes.What?
Limits the addition of
! important
to user preset property values to themes with atheme.json
file. The problems outlined by theme authors were all related to Classic themes (that we are aware of), so this change puts Classic themes back to the pre 5.9 state. A Classic theme can still opt in to have the! important
applied to user presets by adding a theme.json file to the theme.Why?
The blanket addition of
! important
to these property values causes some issues for theme authors, particularly with the likes of responsive font sizing.How?
Checks for the existence of a
theme.json
file before applying! important
Testing Instructions
! important
in the GB presets is overriding the responsive typography CSS! important
set, eg.