-
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
Fix block gap in group blocks in classic themes #47451
Conversation
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 opening this PR @carolinan!
I'm wondering if we could support classic themes that opt in to appearance tools in a slightly different way. What if instead of adding additional layout rules, with the presence of the appearance tools setting, we instead skipped the wp_restore_group_inner_container
behaviour (i.e. add a check to that function and return early)?
The support for the legacy group inner container markup was so that classic themes aren't adversely affected by new features in core/Gutenberg — however, if themes are opting in to use the appearance tools, I think it'd be good if they were also using the new markup, as it will help to keep the layout support a little more streamlined.
What do you think?
I don't know how that would be possible in an already existing theme, where users already have been able to target this element with custom CSS. For example the bundled themes. |
Ah, gotcha. In that case, though, if the themes are wishing to opt-in to new features, shouldn't they be decoupling from the legacy group block markup before adopting appearance tools? My understanding was that the goal for the back-compat code for legacy group blocks was to give themes more time before adopting new features. I think it'd be preferable to avoid that back-compat code growing to include additional rules being output by the layout support, as they're rules that would need to be maintained and would be redundant on block themes. Apologies if I'm missing something, I haven't seen the discussions surrounding the appearance tools feature for classic themes, but my preference would be to try to avoid adding additional complexity to the layout support if it isn't needed, since the rules are already quite complex. |
I don't understand what "decoupling from the legacy markup" means and if that is something I should be able to do with a PR to the bundled themes. |
Apologies, I'm not really too sure what the path forward would be here, as I'm still trying to understand the objective behind opting in to blockGap for Classic themes, as it seems like the wrong way around to me. My opinion is that for features that are designed for sites with My main concerns are about the maintainability of the layout support, and the addition of code to target classic themes. Perhaps it would be better for the appearance tools feature in classic themes to skip blockGap? |
My main concern is that if blocks in the bundled classic themes are broken, that will discourage users from switching to using blocks. And broken blocks are what they are experiencing and reporting now. The main problem with supporting blocks in the classic themes is not blockgap. |
I would still like to understand what negative effects adding this selector would have. It is a small code change for a rather big win for users of classic themes. |
That's a very reasonable question. I'll try to share where I'm coming from. There are a few things to evaluate when deciding whether or not to introduce a change like this beyond the size of the code itself. While the size of the change is fairly minimal on the surface, some of the concerns that come to mind are:
In this case, while the code change is small, it deviates from the intended use cases behind the feature it's a part of (layout) which was designed with block themes in mind, and it expands the scope of the backwards compatibility area of layout, which is an area that folks are attempting to reduce rather than increase. So part of my concern is that this PR is less of a bug fix, and more an enhancement request, as it increases the intended scope of the block support. The way that's been recommended for themes to start using layout and block spacing features up until now has been to adopt This is all just my opinion, though, from working on the layout block support for a while, and running into lots of edge cases with it as it's a very complex feature. Small additions might appear to be simple in isolation, however I believe we need to be careful whenever we increase the scope to ensure that the direction is consistent with future intended usage. Very happy to hear others' feedback if there are more opinions on all this! |
It's unclear what the best solution might be here because this is a feature that tries to meld two incompatible paradigms: classic themes and block themes. It may work well for design tools that apply to a single block, such as border, padding and line-height, but for layout-related controls such as block gap (and I'd argue even margin) it's not ideal, because classic themes already define such styles themselves. I understand that it's useful to have Group, Row and Stack blocks in classic themes, but that tension between paradigms keeps popping up in the form of bugs and unexpected behaviour. For instance, Row block doesn't work at all in TT1 due to an overly-specific theme style. But these thoughts can hardly help to solve the problem at hand 😅 I agree with @andrewserong that adding extra styles to the layout logic is not great, mainly due to the back-compat nature of the Group inner wrapper, and the transitional nature of the appearance tools support feature meaning this is a bit of an edge case. Ideally, we would be able to scrap the group inner wrapper. But if we can't, how about adding the layout classes on the inner wrapper instead? We could add it somewhere in here, so the logic to support the edge case scenario will all be in one place. |
The feature, the theme support, was added in August: #43337 |
That sounds like a better compromise to me, in that the layout rules would be unchanged, it's just where they're being attached in Classic themes, so could be a better way to contain it. |
I think it is only this class that needs to be moved? |
If you're injecting layout classnames to group, you might also need If you need to do a look-up from the layout definitions, though, another approach might be to borrow some of code from $global_settings = gutenberg_get_global_settings();
$global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null );
$layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() );
$layout_type = _wp_array_get( $block, array( 'attrs', 'layout', 'type' ), null );
if ( $layout_type && ! empty( $layout_definitions ) ) {
$layout_classname = _wp_array_get( $layout_definitions, array( $layout_type, 'className' ), '' );
} else {
$layout_classname = _wp_array_get( $layout_definitions, array( 'default', 'className' ), '' );
} |
The appearance tools enables margin, padding, block gap but not layout. Row and stack were implemented without the inner div, so they already work well with block gap. |
Only the default 24px spacing is working, and this should have been obvious to me: |
...Or should I be using this as a reference? https://github.com/WordPress/gutenberg/pull/44600/files |
Ah, of course!
The HTML tag processor would be a neat way to do this actually, then you wouldn't need to construct the layout classnames manually. It should be possible to use |
I think it is better if we make a decision early to revert the appearance-tools theme support in core than to stress the solution. |
@carolinan now that appearance tools are getting reverted via https://core.trac.wordpress.org/ticket/57649. Are you ok with me punting this to 6.3 on the project board? |
Yes, please, we need to discuss it further. |
So first step would be to decide if block gap should be supported in themes without theme.json. |
Hey @carolinan, this PR is on the 6.3 project board since it was punted from 6.2, but it doesn't look like any progress has been made. It is ok if I remove it from the 6.3 board as well? |
@ndiego The problem is that the underlying issue still needs to be solved. I still need the project's decision-makers to look into the issue and decide whether classic themes can regain features like the link color controls. By removing it from the board the issue is only going to be more invisible. |
|
TLDR
The remaining question is if that should be fixed, or if the block gap can be excluded from the theme support. |
This is not a straightforward bug fix, and it's not a regression from the previous WP release either, so it should be punted to the next release. |
I've been testing this and noticed couple of things: With the changes in this PR, Row and Stack do display block gap correctly in classic themes: I might be doing something wrong, but the regular Group block however (constrained) isn't working for me. It looks like .wp-container-5.wp-container-5.wp-container-5.wp-container-5 > * + * {
margin-block-start: 100px;
margin-block-end: 0;
} To be honest I'm not confident enough to say either way. @tellthemachines and @andrewserong have good judgement in this area, which tells me it can probably be postponed until 6.4. That is, work on a fix in Gutenberg and stabilize it until then. |
Oh, just saw this was posted after I hit "Comment". Thanks @tellthemachines |
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/block-supports/layout.php |
So is the consensus now that the block gap should be enabled for themes without theme.json? |
Flaky tests detected in 5fe9051. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5784393473
|
This is not resolved, it is still unclear if the feature should be enabled for classic themes or not. Removing it from the 6.4 board. |
Now that #56130 has been merged, we can close this PR. Thanks for all your work and patience with the endless back and forth on this one @carolinan! |
What?
In preparation for WordPress 6.2, appearance-tools theme support was made available.
With the theme support, but without theme.json, the block gap setting does not work with the group block, because the CSS is only applied to the inner container div, the
wp-block-group__inner-container
, not the inner blocks.Update: This affects both classic themes and block themes with the above condition.
This PR adds the
.wp-block-group__inner-container
as an additional partial selector for block gap.Closes #47386
Why?
To allow classic themes to take advantage of new features.
How?
Testing Instructions
With WordPress 6.2 alpha:
add_theme_support( 'appearance-tools');
to the themes setup function in functions.php.Screenshots or screencast