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: Add a disable-layout-styles theme supports flag to opt out of all layout styles #42544

Merged
merged 5 commits into from
Jul 29, 2022

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Jul 20, 2022

What?

Add a theme support flag to allow themes to opt out of all Layout block support styles via add_theme_support( 'disable-layout-styles' );.

A draft dev note for this feature can be found in this comment: #42544 (comment)

Why?

As discussed in #41487 (comment), #42333, #41431 and elsewhere, many themes decided to opt-out of Layout styles altogether via overriding or removing the 'gutenberg_render_layout_support_flag' filter. This results in two issues:

So, this PR proposes providing an explicit approach for themes that wish to opt-out of Layout styles altogether to do so, via add_theme_support( 'disable-layout-styles' );. Note that themes that opt-out of Layout styles will then be responsible for providing all CSS styling for block layouts. However, as discussed in related issues, many (particularly Classic themes) expect to do so.

The goal here is to reduce friction caused by the Layout block support, and more explicitly define the expectations of the Layout support.

How?

  • Add a disable-layout-styles theme support flag, and expose it in block editor settings, so that it's available in JS.
  • Skip outputting all Layout block support styles if this flag is set to true, however continue to render semantic classnames. (For themes that also wish to opt-out of semantic classnames, they can do this via also overriding the 'gutenberg_render_layout_support_flag' — this PR does not propose adding a flag to switch off semantic classnames)

Testing Instructions

  1. With this PR applied, double-check that blocks like Columns, Social Icons, Buttons, etc render correctly
  2. Add the following line to a theme's functions.php file (e.g. in TwentyTwentyTwo add it to the twentytwentytwo_support function):
		// Opt in to remove layout styles.
		add_theme_support( 'disable-layout-styles' );
  1. In the editor, and on the site frontend, default and flex layouts provided by the layout block support should no longer render.
  2. If you inspect the markup of blocks that use the Layout support, the semantic classnames should still be output (e.g. a Buttons block that sets space-between content justification will have a classname string of "is-content-justification-space-between is-layout-flex wp-block-buttons")
  3. Test with both a blocks-based theme (e.g. TwentyTwentyTwo) and a classic theme (e.g. TwentyTwentyOne)
Here's some markup for testing
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"style":{"color":{"background":"#f0e8f7"},"spacing":{"padding":{"top":"15px","right":"15px","bottom":"15px","left":"15px"}}}} -->
<div class="wp-block-column has-background" style="background-color:#f0e8f7;padding-top:15px;padding-right:15px;padding-bottom:15px;padding-left:15px"><!-- wp:paragraph -->
<p>Column A</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"color":{"background":"#f0e8f7"},"spacing":{"padding":{"top":"15px","right":"15px","bottom":"15px","left":"15px"}}}} -->
<div class="wp-block-column has-background" style="background-color:#f0e8f7;padding-top:15px;padding-right:15px;padding-bottom:15px;padding-left:15px"><!-- wp:paragraph -->
<p>Column B</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"color":{"background":"#f0e8f7"},"spacing":{"padding":{"top":"15px","right":"15px","bottom":"15px","left":"15px"}}}} -->
<div class="wp-block-column has-background" style="background-color:#f0e8f7;padding-top:15px;padding-right:15px;padding-bottom:15px;padding-left:15px"><!-- wp:paragraph -->
<p>Column C</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->

<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"space-between"}} -->
<div class="wp-block-buttons"><!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button A</a></div>
<!-- /wp:button -->

<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button B</a></div>
<!-- /wp:button -->

<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button C</a></div>
<!-- /wp:button -->

<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button D</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->

<!-- wp:social-links -->
<ul class="wp-block-social-links"><!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /-->

<!-- wp:social-link {"url":"https://wordpress.org","service":"wordpress"} /--></ul>
<!-- /wp:social-links -->

<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"space-between","orientation":"vertical"}} -->
<div class="wp-block-buttons"><!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button A</a></div>
<!-- /wp:button -->

<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button B</a></div>
<!-- /wp:button -->

<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button C</a></div>
<!-- /wp:button -->

<!-- wp:button -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Button D</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->

Screenshots or screencast

Note, this feature intentionally removes generated Layout styles, however styles provided by individual blocks in their own CSS files are not affected by this feature.

TwentyTwentyTwo without the setting TwentyTwentyTwo with the setting
image image
TwentyTwentyOne without the setting TwentyTwentyOne with the setting
image image

The new feature should also appear in API requests to the themes endpoint. One way to test this is to inspect network requests from the post editor, and filter by themes. The response for the current theme should include the default value in the theme_supports object:

image

@andrewserong andrewserong self-assigned this Jul 20, 2022
@andrewserong andrewserong added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement. [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jul 20, 2022
@github-actions
Copy link

github-actions bot commented Jul 20, 2022

Size Change: +2.51 kB (0%)

Total Size: 1.26 MB

Filename Size Change
build/block-editor/index.min.js 153 kB +168 B (0%)
build/block-editor/style-rtl.css 14.6 kB -2 B (0%)
build/block-editor/style.css 14.6 kB -2 B (0%)
build/block-library/blocks/button/style-rtl.css 542 B -1 B (0%)
build/block-library/blocks/button/style.css 542 B -1 B (0%)
build/block-library/blocks/comments/editor-rtl.css 834 B +739 B (+778%) 🆘
build/block-library/blocks/comments/editor.css 832 B +737 B (+776%) 🆘
build/block-library/blocks/cover/style-rtl.css 1.55 kB +7 B (0%)
build/block-library/blocks/cover/style.css 1.55 kB +7 B (0%)
build/block-library/blocks/post-comments/editor-rtl.css 0 B -77 B (removed) 🏆
build/block-library/blocks/post-comments/editor.css 0 B -77 B (removed) 🏆
build/block-library/blocks/post-comments/style-rtl.css 0 B -632 B (removed) 🏆
build/block-library/blocks/post-comments/style.css 0 B -630 B (removed) 🏆
build/block-library/blocks/social-link/editor-rtl.css 184 B +7 B (+4%)
build/block-library/blocks/social-link/editor.css 184 B +7 B (+4%)
build/block-library/editor-rtl.css 10.9 kB +595 B (+6%) 🔍
build/block-library/editor.css 10.9 kB +594 B (+6%) 🔍
build/block-library/index.min.js 184 kB -94 B (0%)
build/block-library/style-rtl.css 11.8 kB +150 B (+1%)
build/block-library/style.css 11.8 kB +150 B (+1%)
build/blocks/index.min.js 47.2 kB +27 B (0%)
build/components/index.min.js 230 kB +59 B (0%)
build/components/style-rtl.css 14 kB -5 B (0%)
build/components/style.css 14 kB +3 B (0%)
build/compose/index.min.js 11.7 kB -38 B (0%)
build/customize-widgets/index.min.js 11.2 kB +13 B (0%)
build/edit-post/index.min.js 30.5 kB +18 B (0%)
build/edit-post/style-rtl.css 6.94 kB -26 B (0%)
build/edit-post/style.css 6.94 kB -27 B (0%)
build/edit-site/index.min.js 55 kB +868 B (+2%)
build/edit-site/style-rtl.css 8.21 kB -37 B (0%)
build/edit-site/style.css 8.19 kB -39 B (0%)
build/edit-widgets/index.min.js 16.5 kB +15 B (0%)
build/editor/index.min.js 41.3 kB +11 B (0%)
build/editor/style-rtl.css 3.66 kB +7 B (0%)
build/editor/style.css 3.65 kB +6 B (0%)
build/keycodes/index.min.js 1.39 kB +10 B (+1%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 982 B
build/annotations/index.min.js 2.76 kB
build/api-fetch/index.min.js 2.26 kB
build/autop/index.min.js 2.14 kB
build/blob/index.min.js 475 B
build/block-directory/index.min.js 6.58 kB
build/block-directory/style-rtl.css 990 B
build/block-directory/style.css 991 B
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 103 B
build/block-library/blocks/audio/style.css 103 B
build/block-library/blocks/audio/theme-rtl.css 110 B
build/block-library/blocks/audio/theme.css 110 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 59 B
build/block-library/blocks/avatar/style.css 59 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 441 B
build/block-library/blocks/button/editor.css 441 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 103 B
build/block-library/blocks/code/style.css 103 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 187 B
build/block-library/blocks/comment-template/style.css 185 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/style-rtl.css 632 B
build/block-library/blocks/comments/style.css 630 B
build/block-library/blocks/cover/editor-rtl.css 615 B
build/block-library/blocks/cover/editor.css 616 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 110 B
build/block-library/blocks/embed/theme.css 110 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 253 B
build/block-library/blocks/file/style.css 254 B
build/block-library/blocks/file/view.min.js 346 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 948 B
build/block-library/blocks/gallery/editor.css 950 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 333 B
build/block-library/blocks/group/editor.css 333 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 327 B
build/block-library/blocks/html/editor.css 329 B
build/block-library/blocks/image/editor-rtl.css 736 B
build/block-library/blocks/image/editor.css 737 B
build/block-library/blocks/image/style-rtl.css 627 B
build/block-library/blocks/image/style.css 630 B
build/block-library/blocks/image/theme-rtl.css 110 B
build/block-library/blocks/image/theme.css 110 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 463 B
build/block-library/blocks/latest-posts/style.css 462 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 705 B
build/block-library/blocks/navigation-link/editor.css 703 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation-submenu/view.min.js 423 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.96 kB
build/block-library/blocks/navigation/style.css 1.95 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 443 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 363 B
build/block-library/blocks/page-list/editor.css 363 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 260 B
build/block-library/blocks/paragraph/style.css 260 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 493 B
build/block-library/blocks/post-comments-form/style.css 493 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 605 B
build/block-library/blocks/post-featured-image/editor.css 605 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 282 B
build/block-library/blocks/post-template/style.css 282 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 370 B
build/block-library/blocks/pullquote/style.css 370 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 365 B
build/block-library/blocks/query/editor.css 364 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 385 B
build/block-library/blocks/search/style.css 386 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 464 B
build/block-library/blocks/shortcode/editor.css 464 B
build/block-library/blocks/site-logo/editor-rtl.css 708 B
build/block-library/blocks/site-logo/editor.css 708 B
build/block-library/blocks/site-logo/style-rtl.css 192 B
build/block-library/blocks/site-logo/style.css 192 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.39 kB
build/block-library/blocks/social-links/style.css 1.38 kB
build/block-library/blocks/spacer/editor-rtl.css 322 B
build/block-library/blocks/spacer/editor.css 322 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 494 B
build/block-library/blocks/table/editor.css 494 B
build/block-library/blocks/table/style-rtl.css 611 B
build/block-library/blocks/table/style.css 609 B
build/block-library/blocks/table/theme-rtl.css 175 B
build/block-library/blocks/table/theme.css 175 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 235 B
build/block-library/blocks/template-part/editor.css 235 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 561 B
build/block-library/blocks/video/editor.css 563 B
build/block-library/blocks/video/style-rtl.css 159 B
build/block-library/blocks/video/style.css 159 B
build/block-library/blocks/video/theme-rtl.css 110 B
build/block-library/blocks/video/theme.css 110 B
build/block-library/common-rtl.css 1.01 kB
build/block-library/common.css 1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 695 B
build/block-library/theme.css 700 B
build/block-serialization-default-parser/index.min.js 1.11 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/core-data/index.min.js 14.7 kB
build/customize-widgets/style-rtl.css 1.4 kB
build/customize-widgets/style.css 1.4 kB
build/data-controls/index.min.js 653 B
build/data/index.min.js 7.99 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 507 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.69 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 4.02 kB
build/edit-navigation/style.css 4.03 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-widgets/style-rtl.css 4.35 kB
build/edit-widgets/style.css 4.35 kB
build/element/index.min.js 4.27 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 6.75 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.64 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.77 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.78 kB
build/list-reusable-blocks/index.min.js 1.74 kB
build/list-reusable-blocks/style-rtl.css 835 B
build/list-reusable-blocks/style.css 835 B
build/media-utils/index.min.js 2.93 kB
build/notices/index.min.js 953 B
build/nux/index.min.js 2.05 kB
build/nux/style-rtl.css 732 B
build/nux/style.css 728 B
build/plugins/index.min.js 1.94 kB
build/preferences-persistence/index.min.js 2.22 kB
build/preferences/index.min.js 1.3 kB
build/primitives/index.min.js 933 B
build/priority-queue/index.min.js 612 B
build/react-i18n/index.min.js 696 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.68 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.1 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.53 kB
build/token-list/index.min.js 644 B
build/url/index.min.js 3.61 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.19 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@grappler
Copy link
Member

Thank you @andrewserong for working on the pull request.

I don't fully understand why should not the following in the theme.json to be sufficient to disable the block gap styles.

{
   "settings": { "spacing": { "blockGap": null } }
}

Also is there a defined "rule" when theme support is managed by add_theme_support() and when by theme.json?

@andrewserong
Copy link
Contributor Author

andrewserong commented Jul 20, 2022

I don't fully understand why should not the following in the theme.json to be sufficient to disable the block gap styles.

Thanks for taking a look @grappler! Before this PR is ready for review, I'll try adding a bit of documentation to help clarify the feature.

The implementation here is different to blockGap: null. blockGap: null switches off outputting the blockGap value and default layout styling, however flex-based styling rules for blocks like Columns, Social Icons, and Buttons are still rendered as they're viewed as a part of base layout styles in general.

With this PR, folks who currently completely opt-out of all generated styles via disabling the Layout block support, can do so via add_theme_support( 'disable-layout-styles' );. The expectation is that this would mostly be used by classic themes, as block themes have more control over the output thanks to the presence of the theme.json file.

The necessity for the feature is mostly due to the fact that #40875 moved where some of the Layout styles are generated, so the undocumented approach that some folks currently use by dequeueing or removing the filter 'gutenberg_render_layout_support_flag' will no longer work to remove these styles completely. Hopefully, with an explicit theme support flag for this use case, it'll be a reliable opt-out that folks can use if they need to.

@andrewserong andrewserong force-pushed the try/add-theme-support-to-disable-layout-styles branch from 819e9c3 to e825920 Compare July 21, 2022 05:59
*
* @return {boolean} Whether or not the theme opts-in to disable all layout styles.
*/
function useThemeHasDisabledLayoutStyles() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the site editor package access the hook from the block editor package instead of duplicating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question — I wasn't sure if we wanted to expose it for use anywhere else so left it as a duplication for now. But if it's an official theme support, then yes, it probably makes better sense to have it defined once in the block editor package, and then export it 👍

I'll have a play.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After taking another look, I think it makes the code a little clearer if we don't actually use the hook abstraction. It didn't add much, and meant that if you wanted to see what it was actually checking you'd have to look at the implementation of the hook. In 6b6dadb I've switched to inlining the settings checks, so that it's closer to the feature name, which I think on balance, is a little easier to read.

Happy to change it, though, if you think there's a better way to handle it!

@TimothyBJacobs
Copy link
Member

We should make sure to register this with register_theme_feature.

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.

Tested with both a block and a classic theme and it's working as expected! Only one code structure question below.

$class_names[] = $container_class;
wp_enqueue_block_support_styles( $style );
// Only generate Layout styles if the theme has not opted-out.
if ( ! current_theme_supports( 'disable-layout-styles' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also a bunch of layout-related logic towards the top of this function. Would it make sense to return early instead of adding this condition here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for testing! In this case, I don't think we can return early, because we still want the Layout support's semantic classnames to be added to the output which happens at line 260. Part of the feedback that inspired this PR was that there are Classic themes that would like the semantic classnames like layout type and content justification to be available, but not the generated Layout styles themselves.

It does make it a bit of an awkward place for the check to live, though! I suppose we could move it up to line 228 so that this if block includes the $gap_value declaration and everything below that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oooh, of course, that makes sense 🤦 Yeah, I guess we could move it up a little bit, so there are no unnecessary calculations performed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved it up a little in d77120e, which feels a bit more logical to me now, thanks for the suggestion! Also added a comment about the classnames so it's clearer why we're not returning early.

Separately to this PR, now that we've got a fair few classes being generated it might be worth us re-exploring splitting out the classnames logic to a separate function to make it a bit easier to read. We had it in a separate function for a little while but reverted in #41885 so that we could give it some more thought before committing to a particular approach that we then need to continue to support. But 🤞 we can settle on an approach before 6.1.

@andrewserong
Copy link
Contributor Author

andrewserong commented Jul 27, 2022

We should make sure to register this with register_theme_feature.

Thanks for the suggestion @TimothyBJacobs! I've added that in d77120e, and the default value is now being returned in API responses from the Themes API endpoint 👍

I think the only outstanding task now is to look at Glen's feedback (#42544 (comment)) about potentially removing the duplication of the hook to check the feature in the block editor versus global styles. I'll give this a little more thought, because I'm not quite sold on the hook, given that it's not doing very much. Will follow up tomorrow.

Thanks for the feedback, all! 🙇

@TimothyBJacobs
Copy link
Member

Thanks @andrewserong, looks good to me!

@andrewserong
Copy link
Contributor Author

I think the only outstanding task now is to look at Glen's feedback (#42544 (comment)) about potentially removing the duplication of the hook to check the feature in the block editor versus global styles. I'll give this a little more thought, because I'm not quite sold on the hook, given that it's not doing very much. Will follow up tomorrow.

After playing with a couple of options I wound up removing the hook in 6b6dadb as it felt a bit neater to me to inline the settings check so that the code is closer to the setting value. Happy to continue iterating on it if anyone has a preferred way to handle it.

I think this PR should be ready for a final review now, if I haven't missed anything!

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.

Re-tested all the screens with both block and classic themes, and all is working well ✅

One question that occurs to me: should we still display the content width controls if theme opts out of layout? Especially with the custom ones there will be no way for the theme to access the user set values, though if #42664 or #42763 goes ahead, they could be able to grab the global value if we output the custom property at root level. We might not want to, of course! It depends to what point themes having full control over layout mean users have no control over customisation.

(This is fine to work out as a follow-up!)

@andrewserong
Copy link
Contributor Author

Thanks for reviewing @tellthemachines! 🙇

One question that occurs to me: should we still display the content width controls if theme opts out of layout?

That's a great question, I think I'm leaning toward us figuring that out in a follow-up particularly with the WIP PRs to adjust how the content width works. Ideally this particular theme support just switches off the style output, but like you mention there are probably a few cases where the UI controls also need to be hidden if they're completely useless without the generated styles 🤔

Given that this is a new theme feature, rather than something used out in the wild yet, what do you think if we merge this PR as-is and then dig into it more deeply when we settle on one of the approaches in #42664 or #42763? (If so, I'll add a task to the Layout tracking issue so we don't forget).

@tellthemachines
Copy link
Contributor

Given that this is a new theme feature, rather than something used out in the wild yet, what do you think if we merge this PR as-is and then dig into it more deeply when we settle on one of the approaches in #42664 or #42763? (If so, I'll add a task to the Layout tracking issue so we don't forget).

Yup, that makes sense!

@andrewserong andrewserong merged commit 3c2ee63 into trunk Jul 29, 2022
@andrewserong andrewserong deleted the try/add-theme-support-to-disable-layout-styles branch July 29, 2022 04:05
@github-actions github-actions bot added this to the Gutenberg 13.9 milestone Jul 29, 2022
@andrewserong
Copy link
Contributor Author

andrewserong commented Jul 29, 2022

I believe this feature will require a dev note for WordPress 6.1, so that themes that currently remove the 'gutenberg_render_layout_support_flag' can be updated to use the explicit theme support instead. It probably doesn't require its own full post, but here's a draft for when we get to the core merge stage:


By default, WordPress outputs structural layout styles for blocks such as Group, Columns, Social Icons and Buttons, as part of the layout block support. Up until this point, some themes have been opting out of the generated base layout styles by using an undocumented approach of overriding or removing the render_layout_support_flag callback on the render_block filter.

In WordPress 6.1, base layout styles have been consolidated as part of global styles output (introduced in this PR), so the existing approach of opting out of generated layout styles will no longer work. In its place, there is now a new theme support flag that themes can use, called disable-layout-styles. Themes can opt-in to this feature using the following code:

// Opt in to remove layout styles.
add_theme_support( 'disable-layout-styles' );

Using this new theme support flag ensures that the expected behaviour is handled explicitly in code, and allows themes that use this flag to still make use of semantic classnames that are injected into layout blocks at render time, such as content justification classes.

Note that opting in to this feature will remove required styles for blocks such as Group, Columns, Social Icons and Buttons, so themes that use this feature will need to supply their own structural layout styles in order for these blocks to render correctly in the editor and on the site's frontend.

In most cases, particularly for blocks-based themes, the generated layout styles are preferable for ensuring the correct rendering of core blocks. For themes that are looking to adjust block spacing, see the handbook entry for "What is blockGap and how can I use it?" instead.

@andrewserong andrewserong added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Jul 29, 2022
@bph bph mentioned this pull request Aug 4, 2022
89 tasks
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Sep 14, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.


git-svn-id: https://develop.svn.wordpress.org/trunk@54159 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Sep 14, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159


git-svn-id: http://core.svn.wordpress.org/trunk@53718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Sep 14, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159


git-svn-id: https://core.svn.wordpress.org/trunk@53718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
whereiscodedude pushed a commit to whereiscodedude/wpss that referenced this pull request Sep 18, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159
@andrewserong andrewserong added the [Feature] Layout Layout block support, its UI controls, and style output. label Sep 29, 2022
ootwch pushed a commit to ootwch/wordpress-develop that referenced this pull request Nov 4, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.


git-svn-id: https://develop.svn.wordpress.org/trunk@54159 602fd350-edb4-49c9-b593-d223f7449a82
const _settings = select( blockEditorStore ).getSettings();
return {
themeHasDisabledLayoutStyles: _settings.disableLayoutStyles,
themeSupportsLayout: _settings.supportsLayout,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a new key config when we already have settings.supportsLayout ? Are these two things different and why?

Copy link
Contributor Author

@andrewserong andrewserong Nov 30, 2023

Choose a reason for hiding this comment

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

The names are unfortunately similar, but disableLayoutStyles only disables the layout styles output, but not the controls or the classname output. The use case is for themes that wish to provide their own styling rules for layout, using the classnames output by the controls / layout support. It's been a while now since we implemented this feature, but from memory, this was one of those features that helped some theme developers to adopt layout controls when they weren't ready yet to adopt all the generated layout styles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] Layout Layout block support, its UI controls, and style output. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants