-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Theme JSON: use block global style for block gap where no gap value exists in layout.php #39870
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2bf7d9b
In the theme JSON class, only skip top-level style properties when co…
ramonjd b703a73
In the theme JSON class, linting
ramonjd aac2cef
Updated tests to reflect the changed situation:
ramonjd 88d1f54
A test to check whether this solution will solve the columns regressi…
ramonjd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Why is this needed? isn't the fallback supposed to happen using the CSS variable?
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.
(And we can only set the CSS variable at the global level theme.json)
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 question.
Logically it's not.
I only put it there so we could skip over trying to fetch the global value via
gutenberg_get_global_styles
if a gap value set in the block's local styles attribute is found, which would take precedence anyway.It will either way, unless I'm missing something, which could be the case 😇
My thinking went along of these lines: if the block's local styles attribute does not contain a gap value, we'll try the block's global styles.
Either could still be
null
by the time we callgutenberg_get_layout_style()
in which case the fallback would be--wp--style--block-gap
, which is set at the root.Does that sound right?
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.
It does feel like duplication to me, since if the first one is null, the fallback will be the CSS variable (which corresponds to the root value).
Or in other words, if we do the fallback in php, why do we have the CSS variable in the first place.
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 clarifying.
Just so I understand your concerns, are you seeing somewhere where the root block gap value, as opposed to the block-level global style value, is returned from
on this line?
If so, yes, that would be a mistake.
The intention of this PR is to get gap working for block-level global styles by:
style.spacing.blockGap
value. If the former doesn't exist, we'll use the root value.The effect of point 1 is that a user sets the value of, say, the Group block's gap in global styles,
.wp-block-group { --wp--style--block-gap: '{someCustomValue}px}
won't be rendered:The consequence of point 2 – at least what I'm attempting - is that if a user has set the value of Group block's gap in global styles it will be used when an individual block's attributes do not contain a
style.spacing.blockGap
value.So the priority should still be:
If things aren't working that way in this PR it means I've done something wrong! 😬
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.
You raise good points, thanks for clarifying.
Yeah, I see what you mean. We might run into trouble if we mix block support style attributes with global styles.
I wasn't aware of Style Partials (theme.json) so I agree that a change like the one in this PR might come back to bite us. 👍
I was having a discussion with @tellthemachines about something similar over at Try using variable for root padding value #39926
I was wondering about an alternative: a
const VALID_TOP_LEVEL_STYLES
(or whatever) inWP_Theme_JSON_Gutenberg
that explicitly defines unique, root-level-only CSS vars.I haven't really thought this through, but I was venturing towards checking
VALID_TOP_LEVEL_STYLES
when we assemble the styles incompute_style_properties
and appending--wp--root-style--
forROOT_BLOCK_SELECTOR
styles.Or there might be a tricky way to assemble them in
sanitize()
via$schema['styles']
,$schema['styles']['elements']
and$schema['styles']['blocks']
.Uniquely identifying global CSS vars has a benefit, aside from explicitly stating their purpose, in that their values can be used for top-level layout calculation.
For example, in #39926, full-width blocks can use a root padding CSS var set a negative margins so that they stretch to the "full-width" of the screen.
Ultimately, we need to know how to treat
blockGap
when it is a root or a block/element style value and output something different accordingly.I can chat about it with @andrewserong and see what we can cook up.
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.
Great questions.
Totally, I think it reveals some pragmatic challenges surrounding how we output styles, particularly for the layout support, which as @ramonjd mentions further down, is a little different to the other block supports.
In the case of this PR (and the current implementation of the layout support), everything happens at the individual block level when it's rendered, so out of necessity, to factor in global styles, we've kinda got to "look up" to the parents in order to deal with those values (or use CSS variables to stand-in for it).
In an ideal circumstance, with the style engine, how differently might we be doing things? The model for the style engine is a lot clearer for supports like padding, margin, typography, etc, where we'd like to consolidate the approach at the individual block level and global styles, and using a block's classname is an appropriate hook for it. In some of the explorations (like #39374) it looks like we'll be able to move more to global styles, but the unique block gap values was still a bit of mystery to me as to how best to handle it, and neatly declare values that get passed down / or cascade down correctly.
With block gap, because the value is used directly in different circumstances (rendering
flow
vsflex
gap), it does create this additional challenge. I think because the use case is so different to each of the other block supports, I'm wondering if the approach in this PR would be an acceptable way to unblock getting the global styles support in, and if we could treat it as an implementation detail we could potentially swap out if and when partials in #39281 is explored.From my perspective, it could be worthwhile proceeding with this change, so long as:
blockGap
values at the block level withintheme.json
and via the global styles interface in the site editor.From some of the explorations we've looked at recently, given that a fair bit of the logic winds up being moved to the Theme JSON class anyway, I don't think that the current change here would preclude further work, but very happy to be proved wrong, as I definitely don't want to nudge us into a decision that's difficult to reverse!
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.
One alternative could be to keep the current logic (selectors specific styles but output something like):
To be honest, I didn't think much about this, it's just a random idea for now, but it's an alternative that allows us to avoid that dependency to parent global style.
I don't know 🤷 to be honest, personally I don't have a full confidence here but I trust your judgement.
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 really like that approach — I'd like it if we can output something like that in the longer term. I might be overthinking it, but I think that approach slightly opens up the can-of-worms surrounding rendering out semantic classnames, which we're in more of the proposal / exploratory phase of (since we'd need to adjust the logic for how the theme JSON class outputs styles, and then the layout support to inject the classnames).
Thank you, much appreciated! Since I was one of the folks to propose the idea of looking up global styles, I think I'd feel more comfortable with getting a couple more opinions if you're not totally sold on the idea, to confidence check before proceeding. I think my main interest is to see how viable we think a short-term fix is (so that we can fix this bug in WP 6.0) and then aim to have the class-based approach like in your code snippet in time for WP 6.1.
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.
cc @jorgefilipecosta @oandregal @mcsf if you have any opinions here.