-
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
Don't output base flow and constrained layout rules on themes without theme.json #60764
Conversation
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. |
@@ -1608,6 +1608,11 @@ protected function get_layout_styles( $block_metadata ) { | |||
foreach ( $base_style_rules as $base_style_rule ) { | |||
$declarations = array(); | |||
|
|||
// Skip outputting base styles for flow and constrained layout types if theme doesn't support theme.json. | |||
if ( ! wp_theme_has_theme_json() && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) { |
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 we achieve the same differently, without using wp_theme_has_theme_json
here? The WP_Theme_JSON
class is WordPress agnostic: doesn't use "WordPress utilities" (theme supports, doesn't know what a theme is, etc.).
I don't know the details of how the "layout styles" work, so I may be missing tons of context. However, I'd think this kind of logic (whether a theme has or doesn't a theme.json
) pertains to the public function gutenberg_get_global_stylesheet
that then makes the proper calls to the utilities.
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.
The WP_Theme_JSON class is WordPress agnostic
Oooh great to know, I hadn't realised that! Was there any thought of using the class outside of WP, or is it just a separation of concerns thing?
I guess if we want the logic to reside in gutenberg_get_global_stylesheet
we can pass a flag down through get_stylesheet
.
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.
Hmm, we're using current_theme_supports
further up in get_layout_styles
; should the same logic apply there?
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.
separation of concerns thing?
This. It simplifies a lot of things (testing, reasoning about the code, etc.).
Hmm, we're using current_theme_supports further up in get_layout_styles; should the same logic apply there?
In my view, we shouldn't have done that there.
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.
Just wondering how we might implement it differently. Would it be something like moving the logic to the resolver around here?
if ( ! wp_theme_has_theme_json() ) { |
If so, then it looks like the current approach is for keys to be set within the $theme_support_data
array, so would we have something like $theme_support_data['settings']['layout']['disableLayoutStyles']
as a supported theme.json
key?
Then we might also have a key to flag skipping the base layout styles for default and constrained layouts... but how to do that without getting stuck with awkward naming, or an awkward API shape of the layout
settings object 🤔
Also, this bug fix is targeting 6.5.3 so we might not want to try to change too much in one go?
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.
Is it something that could be returned from gutenberg_get_layout_definitions()?
So check for wp_theme_has_theme_json()
in gutenberg_get_layout_definitions()
and just remove them before returning? Or something? 😄
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 the ideas folks!
but how to do that without getting stuck with awkward naming
This is the eternal problem 😂
Would something like disableContentWidthStyles
work? It's not technically a theme support, but all classic themes that don't have a theme.json in practice don't support it. We haven't needed to check for the presence of a theme.json file in any other part of this class so far, so perhaps there isn't a need for a more generic disableThemeJson
type thing.
Is it something that could be returned from gutenberg_get_layout_definitions()?
Hmm that might be messier because we don't want to output base flow/constrained styles but we still want to output gap styles if the theme supports appearance-tools
.
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.
Would something like disableContentWidthStyles work?
Feels pretty consistent with disableLayoutStyles
, so I don't mind it!
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 just thought of another possibility: we could leverage the base-layout-styles
type because that only gets set when there's no theme.json. The name might be a bit confusing because we also have baseStyles
in the layout definitions, but it's an existing property so would be a small change.
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.
Oh, clever, I like it!
So long as there's a code comment alongside the logic for it, re-using base-layout-styles
sounds reasonable to me 👍
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.
For what it's worth this is testing nicely for me! Using wp_theme_has_theme_json
(wherever it's called from) as the guard makes sense as it parallels the logic of when the group inner container is output for Classic themes. Each of the Classic themes I tested with provide their own rules for align left/right etc, so it feels natural to me that they wouldn't depend on the rules provided by layout for flow and constrained layouts.
Edit: also, confirmed that either adding a theme.json
file or add_theme_support( 'appearance-tools' );
to a Classic theme results in these rules being output again, so there's a clear path for any Classic themes that do want these rules after all 👍
Here's something interesting: all the test failures resulting from this change point to us running all of |
Oh! Shouldn't we be testing it on both classic and block themes? |
I don't think we need to test everything on both; maybe run a couple tests on classic themes where expected behaviour is different. Such as the behaviour this PR introduces 😄 |
OK I've updated the PR to use Potentially, we could use another type flag to check if theme support for layout styles is disabled, or maybe that one makes more sense in the resolver as @andrewserong suggested? In any case, given it's an enhancement, let's leave it for a follow-up. It would also be good to follow up with ensuring the tests are mostly run on a block theme; I'll add a note to #60842. |
Agreed. The shape of this PR looks good to me for a 6.5.x fix 👍 |
Given that this fixes a trac ticket slated for WP 6.5.3, I've added the "Backport to WP Minor Release" and "Needs PHP Backport" labels to this PR--but please let me know if I'm missing something and that isn't correct. |
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 testing great for me, and works as expected across all the block and classic themes I tested it with (around half a dozen of each).
Just wanted to clarify one question:
Check that block spacing rules are still output if the theme has support for appearance-tools.
In this case, the margin-left
/ margin-right
base layout rules are still skipped, but we get the vertical spacing rules for flow and constrained layouts. Is that the expected behaviour? I assume so, but just thought I'd double-check. I only get those left/right rules if a theme.json
file is added 👍
LGTM! ✨
@andrewserong correct, left/right margin rules are skipped if the theme has no theme.json, regardless of |
d61edc1
to
483e862
Compare
Thanks for the reviews everyone! |
I've opened a sync PR in core: WordPress/wordpress-develop#6410 |
… theme.json (#60764) Co-authored-by: tellthemachines <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: creativecoder <[email protected]>
I manually cherry-picked this PR to the |
… theme.json (#60764) Co-authored-by: tellthemachines <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: creativecoder <[email protected]>
What?
Fixes https://core.trac.wordpress.org/ticket/60981.
If the theme has no theme.json, outputting base rules for flow and constrained layout types doesn't make sense, because there's no content/wide width defined.
This change should work even for the edge case of block themes with no theme.json, because the absence of a theme.json implies the theme is providing all the necessary styles.
Apart from the auto left and right margin rule mentioned in the trac ticket, this change also affects the
alignleft
andalignright
rules. These rules also contain margin values that can override those defined by classic themes, so I think it makes sense to remove them too.Testing Instructions
body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull))
CSS rule that sets left and right margins toauto !important
.appearance-tools
.Testing Instructions for Keyboard
Screenshots or screencast