Skip to content
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

Layout: Skip outputting base layout rules that reference content or wide sizes if no layout sizes exist #60489

Conversation

andrewserong
Copy link
Contributor

What?

Fixes #60413

If the global theme JSON settings for settings.layout.contentSize or settings.layout.wideSize aren't set, skip outputting base layout styles that reference the CSS variables for those values.

Why?

As reported in #60413, when you add a wide block as a child of a Group block in a classic theme such as Twenty Twenty, then the layout support's constrained max-width styles wind up overriding the theme's styles for .alignwide. And since there are no content or wide size CSS variables available, this effectively results in wide size blocks being displayed as full width to their container.

With the approach in this PR, the output of the max-width rules that reference the CSS variables is skipped if there is no content or wide size value available, which should result in the bug being fixed for themes such as Twenty Twenty. Block themes that set content or wide size should be unaffected.

How?

In the Theme JSON class, skip output of base style rules that reference either of the content/wide size CSS variables if there is no content or wide size value available.

Testing Instructions

Activate Twenty Twenty theme and add the following test markup from #60413 to a post:

<!-- wp:group {"align":"full","backgroundColor":"primary","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull has-primary-background-color has-background"><!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">Full group.</p>
<!-- /wp:paragraph -->

<!-- wp:group {"align":"wide","backgroundColor":"accent","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide has-accent-background-color has-background"><!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">Wide group.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --></div>
<!-- /wp:group -->

Save and publish the post. On the site front end, prior to this PR, the wide group block will extend to the full width of its container. With this PR applied, its max-width should be that provided by the theme (in the case of Twenty Twenty, it's 120rem).

To test against regressions, switch to a block theme and make sure that constrained layout works as expected in the post and site editors and on the site front end.

Screenshots or screencast

Before

Note how the base layout rules are overriding rules:

image

After

The base layout rules for max-width are no longer output:

image

@andrewserong andrewserong added [Type] Bug An existing feature does not function as intended [Feature] Layout Layout block support, its UI controls, and style output. labels Apr 5, 2024
@andrewserong andrewserong self-assigned this Apr 5, 2024
@andrewserong andrewserong marked this pull request as draft April 5, 2024 01:12
Copy link

github-actions bot commented Apr 5, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: andersnoren <anlino@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@andrewserong
Copy link
Contributor Author

andrewserong commented Apr 5, 2024

Just switching this over to Draft — there are some tests to update, and we might also want to include the same logic in the site editor's JS version of global styles 🤔

@andrewserong andrewserong added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Apr 5, 2024
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This change LGTM as is (not taking into account the pending test updates of course 😅 )

I think adding this logic to the JS global styles output can be considered as a follow-up, because it's existing behaviour (the regression we need to fix was caused by the layout classnames changing places in classic themes only) and it doesn't seem to have caused problems in block themes so far, maybe because when the theme doesn't define content widths the wide/full align options aren't available to blocks. So let's try it by all means, but I think it's better to keep this fix small as it's meant to go into the next minor release.

@andrewserong
Copy link
Contributor Author

So let's try it by all means, but I think it's better to keep this fix small as it's meant to go into the next minor release.

Good thinking! Agreed. Let's go for the small change in this PR for 6.5.1, and we can explore the JS changes separately if need be 👍

I'll proceed with updating the tests.

@andrewserong andrewserong marked this pull request as ready for review April 5, 2024 05:07
@andrewserong andrewserong added the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Apr 5, 2024
@andrewserong
Copy link
Contributor Author

I've updated the tests, and I've started a draft backport PR in core over in: WordPress/wordpress-develop#6362 — I ran out of time to finish that off today, but I'll continue on with it on Monday.

For now, I'll merge this PR in. Thanks again for the review!

@andrewserong andrewserong merged commit 59a4104 into trunk Apr 5, 2024
68 checks passed
@andrewserong andrewserong deleted the try/fix-output-of-content-and-wide-size-rules-when-no-sizes-exist branch April 5, 2024 05:40
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 5, 2024
@andrewserong
Copy link
Contributor Author

Apologies everyone, I clicked merge too quickly and forgot to add in the props 🤦

Thanks again for the bug reports, triage, and reviews, everyone!

ramonjd pushed a commit that referenced this pull request Apr 9, 2024
…ide sizes if no layout sizes exist (#60489)

* Layout: Skip outputting base layout rules that reference content or wide sizes if no content or wide sizes exist

* Update tests
@ramonjd
Copy link
Member

ramonjd commented Apr 9, 2024

I just cherry-picked this PR to the release/18.1 branch to get it included in the next release: d639f38

@ramonjd ramonjd removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Apr 9, 2024
cbravobernal pushed a commit to garridinsi/gutenberg that referenced this pull request Apr 9, 2024
…ide sizes if no layout sizes exist (WordPress#60489)

* Layout: Skip outputting base layout rules that reference content or wide sizes if no content or wide sizes exist

* Update tests
@creativecoder creativecoder added the Backported to WP Core Pull request that has been successfully merged into WP Core label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release Backported to WP Core Pull request that has been successfully merged into WP Core [Feature] Layout Layout block support, its UI controls, and style output. [Type] Bug An existing feature does not function as intended
Projects
Development

Successfully merging this pull request may close these issues.

6.5: Maximum width of wide blocks inside group set to Alignment: Full is overwritten in classic themes
4 participants