-
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
Fix: Preset controls need the preset CSS variables in scope #27119
Fix: Preset controls need the preset CSS variables in scope #27119
Conversation
Size Change: +102 B (0%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
5fbf985
to
71d8c39
Compare
👋 I've tested this and these are my thoughts:
The first issue seems solvable by following the proposal at #26511 (comment) The second one is a bit more convoluted. On the one hand, in the site editor, we need to grab the preset styles to update their values upon user changes ― so far, we've done this by creating our own style node in the client. On the other hand, the stylesheet needs to be ready for when the HTML block (and potentially others such as classic?) grabs them to use in its iframe. I'm not sure how to balance the two needs without looking at how the HTML preview works. I can perhaps offer some ideas about how to address this but they need some investigation:
|
Issues for the HTML block that may relevant to look at together with this |
71d8c39
to
fd70f5e
Compare
fd70f5e
to
7396e22
Compare
Hi @nosolosw thank you for the review and for suggesting possible paths to address the issues. I updated this PR and it follows the path "It looks like adding presets to the settings.style key as it works now wouldn't work. Perhaps we can teach this code to avoid wrapping some styles? This would have the benefit that observers of the styles would still work as expected.". |
7396e22
to
fd719dd
Compare
To avoid CSS conflicts, in the editors, we should have this:
Code-wise:
|
4a585ef
to
210782e
Compare
Hi @nosolosw, Thank you for the review, all your feedback was applied 👍 |
Going to take a look at the code now, but here's what I've found in testing this:
h1 {
}
// ...
h1 {
font-size: var(--wp--preset--font-size--gigantic);
line-height: 1.1;
} Other than that, it works as advertised. |
* @return string Stylesheet. | ||
*/ | ||
public function get_stylesheet() { | ||
return array_reduce( $this->contexts, array( $this, 'to_stylesheet' ), '' ); | ||
public function get_stylesheet( $type = 'all' ) { |
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'd like us to keep adding tests for the new things. In this case, get_stylesheet( 'block_styles' ) and get_stylesheet( 'css_variables' ). I believe that would have caught the issue with the empty rulesets.
lib/class-wp-theme-json.php
Outdated
return array_reduce( $this->contexts, array( $this, 'to_stylesheet' ), '' ); | ||
public function get_stylesheet( $type = 'all' ) { | ||
switch ( $type ) { | ||
case 'all': |
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.
What if instead of using the case all
we move this code to the default
fallback? We'd have every code path covered.
lib/class-wp-theme-json.php
Outdated
@@ -816,13 +816,14 @@ function ( $carry, $element ) { | |||
/** | |||
* Converts each context into a list of rulesets | |||
* to be appended to the stylesheet. | |||
* These rulesets contain the all css variables (custom variables and preset variables) | |||
* and all the preset classes. |
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 comment seems to need updating?
lib/class-wp-theme-json.php
Outdated
// Attach the ruleset for style and custom properties. | ||
$stylesheet .= self::to_ruleset( $context['selector'], $declarations ); | ||
} | ||
|
||
// Attach the rulesets for the classes. | ||
self::compute_preset_classes( $stylesheet, $context ); |
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.
Conceptually, I don't like that we output the preset classes here. In practical terms, I guess it's fine? Flagging in case you have thoughts.
@@ -135,9 +136,9 @@ function gutenberg_experimental_global_styles_get_stylesheet( $tree ) { | |||
} | |||
} | |||
|
|||
$stylesheet = $tree->get_stylesheet(); | |||
$stylesheet = $tree->get_stylesheet( $type ); |
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, now, the resulting stylesheet can be actually 3 different stylesheets, however, we only have 1 cache. I presume that can be a source of conflicts we need to fix?
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 catch we should only cache type all which is the one used on the front end.
210782e
to
dc1ea0f
Compare
All the feedback was addressed before the merge. |
Fixes: #26511
This PR makes sure presets and CSS vars are available in the scope of editor UI. These styles are just defining CSS variables and specific classes they should not impact anything in the UI. But if a UI component needs a variable e.g: a gradient preset that depends on a color preset having the variable available makes the UI components look as expected.
How has this been tested?
I enabled 2021 blocks.
I added the following declaration to theme.json:
I verified the gradient control circle renders as expected.