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

Add utility classnames back to blocks that have layout attributes specified #41487

Merged
merged 7 commits into from
Jun 9, 2022

Conversation

glendaviesnz
Copy link
Contributor

@glendaviesnz glendaviesnz commented Jun 1, 2022

What?

Add several layout utility classnames to blocks that have layout attributes specified

Why?

In 5.9 these utility classnames were removed which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block

How?

Adds these classes dynamically based on attributes, rather than saving them to the serialized content

Testing Instructions

  • Add a Buttons block with one child Button block
  • On parent Buttons block set alignment to centre and turn off the wrapping option
  • Check that is-content-justification-center and is-nowrap classes are added in editor and frontend

Screenshots or screencast

Screen Shot 2022-06-02 at 11 17 33 AM

@glendaviesnz glendaviesnz added the CSS Styling Related to editor and front end styles, CSS-specific issues. label Jun 1, 2022
@glendaviesnz glendaviesnz self-assigned this Jun 1, 2022
@github-actions
Copy link

github-actions bot commented Jun 1, 2022

Size Change: -577 B (0%)

Total Size: 1.24 MB

Filename Size Change
build/block-editor/index.min.js 151 kB +117 B (0%)
build/components/index.min.js 227 kB -691 B (0%)
build/edit-post/style-rtl.css 7.08 kB -1 B (0%)
build/edit-post/style.css 7.08 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.51 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 14.6 kB
build/block-editor/style.css 14.6 kB
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 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 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 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 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 127 B
build/block-library/blocks/comment-template/style.css 127 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/editor-rtl.css 95 B
build/block-library/blocks/comments/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.56 kB
build/block-library/blocks/cover/style.css 1.56 kB
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 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 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 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 353 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 961 B
build/block-library/blocks/gallery/editor.css 964 B
build/block-library/blocks/gallery/style-rtl.css 1.51 kB
build/block-library/blocks/gallery/style.css 1.51 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 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 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 738 B
build/block-library/blocks/image/editor.css 737 B
build/block-library/blocks/image/style-rtl.css 529 B
build/block-library/blocks/image/style.css 535 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 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 708 B
build/block-library/blocks/navigation-link/editor.css 706 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 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 375 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.95 kB
build/block-library/blocks/navigation/style.css 1.94 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 395 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 69 B
build/block-library/blocks/post-comments-form/editor.css 69 B
build/block-library/blocks/post-comments-form/style-rtl.css 495 B
build/block-library/blocks/post-comments-form/style.css 495 B
build/block-library/blocks/post-comments/editor-rtl.css 77 B
build/block-library/blocks/post-comments/editor.css 77 B
build/block-library/blocks/post-comments/style-rtl.css 628 B
build/block-library/blocks/post-comments/style.css 628 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 721 B
build/block-library/blocks/post-featured-image/editor.css 721 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 323 B
build/block-library/blocks/post-template/style.css 323 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 369 B
build/block-library/blocks/query/editor.css 369 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 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 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 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 759 B
build/block-library/blocks/site-logo/editor.css 759 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-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 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.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 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 504 B
build/block-library/blocks/table/editor.css 504 B
build/block-library/blocks/table/style-rtl.css 625 B
build/block-library/blocks/table/style.css 625 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 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 149 B
build/block-library/blocks/template-part/editor.css 149 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 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 993 B
build/block-library/common.css 990 B
build/block-library/editor-rtl.css 10.2 kB
build/block-library/editor.css 10.3 kB
build/block-library/index.min.js 181 kB
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 11.6 kB
build/block-library/style.css 11.6 kB
build/block-library/theme-rtl.css 689 B
build/block-library/theme.css 694 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 47.1 kB
build/components/style-rtl.css 13.9 kB
build/components/style.css 13.9 kB
build/compose/index.min.js 11.7 kB
build/core-data/index.min.js 14.6 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.4 kB
build/customize-widgets/style.css 1.4 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 7.98 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.69 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 4.05 kB
build/edit-navigation/style.css 4.05 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 30.3 kB
build/edit-site/index.min.js 47.9 kB
build/edit-site/style-rtl.css 7.73 kB
build/edit-site/style.css 7.71 kB
build/edit-widgets/index.min.js 16.4 kB
build/edit-widgets/style-rtl.css 4.4 kB
build/edit-widgets/style.css 4.4 kB
build/editor/index.min.js 38.5 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.7 kB
build/element/index.min.js 4.3 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 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.9 kB
build/notices/index.min.js 957 B
build/nux/index.min.js 2.07 kB
build/nux/style-rtl.css 744 B
build/nux/style.css 741 B
build/plugins/index.min.js 1.98 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.32 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 628 B
build/react-i18n/index.min.js 704 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.69 kB
build/reusable-blocks/index.min.js 2.24 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.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.99 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 280 B
build/widgets/index.min.js 7.2 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Nice work @glendaviesnz, thanks so much for honing in on this change, I think adding a separate function for generating the classnames is the right way to go — it makes it a bit cleaner than trying to do everything in the gutenberg_get_layout_style function 👍

I noticed that the e2es are failing due to the changed markup with the additional classes. In case it helps, in the other PR, I ran the following locally to update the snapshot:

npm run test-e2e:playwright -- -u test/e2e/specs/editor/various/post-editor-template-mode.spec.js

One thing to watch out for when updating the snapshot, though, is that the site title is different in CI than locally, so I had to manually change restore it in the txt file. Separately to this PR, we might be able to improve that test so that it's a little more resilient to layout markup changes 🙂

lib/block-supports/layout.php Outdated Show resolved Hide resolved
lib/block-supports/layout.php Outdated Show resolved Hide resolved
@@ -190,12 +223,12 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
// If a block's block.json skips serialization for spacing or spacing.blockGap,
// don't apply the user-defined value to the styles.
$should_skip_gap_serialization = gutenberg_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
$style = gutenberg_get_layout_style( ".$class_name", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization, $fallback_gap_value );
$style = gutenberg_get_layout_style( ".$block_classname.$container_class", $used_layout, $has_block_gap_support, $gap_value, $should_skip_gap_serialization, $fallback_gap_value );
Copy link
Contributor

Choose a reason for hiding this comment

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

As in the other comment, for this PR, we might not need to increase the specificity by prepending $block_classname (we could leave it for #40875)

lib/block-supports/layout.php Outdated Show resolved Hide resolved
}

if ( attributes?.layout?.orientation ) {
layoutClassnames.push( `is-${ attributes.layout.orientation }` );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewserong is there a js equivalent of sanitize_title that we should use here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Other comparable files in this package use lodash's kebabCase. I usually try to avoid adding in lodash, but since this function is already used in the package and it seems like a straightforward way to do it, personally, I'd use that 🙂

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/hooks/font-family.js#L76

@glendaviesnz
Copy link
Contributor Author

I have updated the doc comment on the method to make it clear that this is an interim step to add back removed classes, rather than a place to start adding any new utility classes

lib/block-supports/layout.php Outdated Show resolved Hide resolved
lib/block-supports/layout.php Outdated Show resolved Hide resolved
glendaviesnz and others added 2 commits June 2, 2022 14:27
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
@glendaviesnz
Copy link
Contributor Author

I noticed that the e2es are failing due to the changed markup with the additional classes

Strange, I didn't change these and now they are passing 🤔

@glendaviesnz
Copy link
Contributor Author

Strange, I didn't change these and now they are passing 🤔

ah, of course, removed $block_classname which will have resolved the test issue

@andrewserong
Copy link
Contributor

ah, of course, removed $block_classname which will have resolved the test issue

Ah, yes, that makes sense now. Thanks for confirming!

{
[ `wp-container-${ id }` ]: shouldRenderLayoutStyles,
},
getLayoutClasses( attributes )
Copy link
Contributor

@andrewserong andrewserong Jun 2, 2022

Choose a reason for hiding this comment

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

This might be slightly nit-picky, but in the PHP implementation, the classnames will only be added if the block has opted-in to the layout support. Theoretically in this JS version, it looks like if the attributes have a layout property (with the appropriate sub-properties), it'll output the classnames even if the block hasn't opted in to the layout support. I can only imagine this happening in an unfortunate edge case of a custom block in a plugin that happens to use a layout attribute.

Do you think it's worth adding a shouldRenderLayoutStyles check before calling getLayoutClasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks, will sort that out in the morning

Copy link
Contributor

@andrewserong andrewserong 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 this one @glendaviesnz, this is testing nicely for me:

✅ The specified classes based on layout attributes are output within the editor
✅ The specified classes based on layout attributes are output on the site frontend
✅ None of the added classes are serialised to post content

This LGTM, it adds back the classnames, which appears to be safe, while not making any changes to the layout support logic, which we'll be addressing in separate changes. Also, since the classnames aren't serialized, it should be pretty straightforward to make tweaks in follow-ups if need be. 🎉

packages/block-editor/src/hooks/layout.js Show resolved Hide resolved
@glendaviesnz glendaviesnz added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Jun 3, 2022
@glendaviesnz
Copy link
Contributor Author

This was seen as a regression by a number of people in 5.9, but not looked at in time for 6.0, so probably worth getting into 6.0.1 if we can.

@glendaviesnz
Copy link
Contributor Author

@mtias picking up on your comment here, Restore previously semantic classes that were removed., this PR adds back these classnames.

The general view is that the style engine is a better place to handle the addition of these classes, but we are probably still a little way off getting everything in a place to make this possible. This PR handles the addition of the classes without serialising them back into the static block content, so migration from this temporary approach to the style engine when ready should be straightforward. Does this seem like a reasonable approach?

cc/ @youknowriad

adamziel pushed a commit that referenced this pull request Jun 21, 2022
…cified (#41487)

Co-authored-by: Glen Davies <glen.davies@a8c.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Cory Birdsong @cbirdsong
@adamziel
Copy link
Contributor

I just cherry-picked this PR to the wp/6.0 branch to get it included in the next release: f253a84

@adamziel adamziel removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Jun 21, 2022
@adamziel
Copy link
Contributor

adamziel commented Jun 21, 2022

@glendaviesnz this PR contains PHP changes that need a matching PR in the https://github.com/WordPress/wordpress-develop repository to be included in WordPress 6.0.1. Would you please create such a PR? CC @SergeyBiryukov

@glendaviesnz
Copy link
Contributor Author

@glendaviesnz
Copy link
Contributor Author

@adamziel WordPress/wordpress-develop#2840 is approved - do you need me to do anything else? I don't have any permissions on the wordpress-develop repo.

@adamziel
Copy link
Contributor

Fantastic @glendaviesnz, thank you so much! We're good – I don't have these permissions either :-) But @SergeyBiryukov does – would you please merge that PR?

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Jun 23, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
See #56058.

git-svn-id: https://develop.svn.wordpress.org/trunk@53568 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jun 23, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
See #56058.
Built from https://develop.svn.wordpress.org/trunk@53568


git-svn-id: http://core.svn.wordpress.org/trunk@53157 1a063a9b-81f0-0310-95a4-ce76da25c4cd
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Jun 23, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
Merges [53568] to the 6.0 branch.
See #56058.

git-svn-id: https://develop.svn.wordpress.org/branches/6.0@53569 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jun 23, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
Merges [53568] to the 6.0 branch.
See #56058.
Built from https://develop.svn.wordpress.org/branches/6.0@53569


git-svn-id: http://core.svn.wordpress.org/branches/6.0@53158 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this pull request Jun 23, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
Merges [53568] to the 6.0 branch.
See #56058.
Built from https://develop.svn.wordpress.org/branches/6.0@53569


git-svn-id: https://core.svn.wordpress.org/branches/6.0@53158 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this pull request Jun 23, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
See #56058.
Built from https://develop.svn.wordpress.org/trunk@53568


git-svn-id: https://core.svn.wordpress.org/trunk@53157 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@adamziel adamziel removed the Needs PHP backport Needs PHP backport to Core label Jun 30, 2022
@simom
Copy link

simom commented Jul 14, 2022

In the 6.0.1 it seems that the alignment utility classes works only with the "wp_render_layout_support_flag" filter enabled, am I missing something?
These classes should not be enabled also with the filter disabled for everyone that needs to customize the layout logic?

@andrewserong
Copy link
Contributor

@simom as of 6.0.1 that's correct — the Layout styles and classnames are tied together. One of the tasks in the Layout tracking issue (#39336) is to look at separating out the opt-in / opt-out behaviour in the Layout support so that a theme could opt-in to the classnames without the styles.

@simom
Copy link

simom commented Jul 15, 2022

Hi @andrewserong and thanks for the clarification, I have just a couple of thoughts concerning this topic.

The opt-out mechanism for custom a project has always be to dequeue the Block editor stylesheet, this way the logical classes are still applied and you can build your custom style based on these.

This choice to remove them when you are still not ready to bring back a fallback is systematically breaking the style of all the installations that rely on this basic concept.

I understand that this task is not easy and quick to implement, so for this reason all these experiments (like
the _experimental flags pushed in the stable core release) should remain opt-in until they are not really stable enough to be pushed in the core branch, of course this is my opinion.

This new auto generation strategy for style is indeed more performant (with some drawbacks of course), as discussed in some Gutenberg threads here on Github, but should be considered in a more wide scope because for how this has been designed it will have more sense if the theme is entirely built with the Site editor, that is still a work in progress tool not suitable for clients projects.

@andrewserong
Copy link
Contributor

Thanks for the extra info @simom!

This choice to remove them when you are still not ready to bring back a fallback is systematically breaking the style of all the installations that rely on this basic concept.

The way I imagine the flag might work is that by default, the classes would still be generated, and instead of dequeuing / overriding wp_render_layout_support_flag, we'd have a filter or other mechanism to switch off only the style generation. That way, you'd still get the classnames output for the use case you've described, where your theme is providing styles based on those classnames.

I'd be curious to hear if you have an idea in mind about how it should ideally work — because individual blocks (both in blocks-based and classic themes) require layout styles in order to be rendered correctly, I imagine both features (classes and styles) will be opt-out rather than opt-in. Feel free to comment here (or in a separate issue if you think it's a more unique case) if there's a specific way you think themes can ideally opt-in / opt-out. I'm following a few different discussions on the topic, and am keen to understand the use cases 🙂

@simom
Copy link

simom commented Jul 18, 2022

Hi @andrewserong , thanks for your time, we can continue the discussion in this issue.

As previously said this kind of behavior makes more sense in a broader context like a theme designed to fully embrace the site editor so should be enabled if the theme define a theme-json file.

The layout fallback strategy should always be the block editor css file that still contains all the layouts logic.

If we assume that this functionality should be turned on by default, an idea could be to have a filter to turned off globally or individually the style generation (bringing back the logical classes of course), something like:
add_filter( ‘wp_disable_render_layout_support’, ‘__return_true’ ) for globally disable the styles
or:
add_filter( ‘wp_disable_render_layout_support’, ‘__return_true’, $block ) for a specific block, where in $block you should have all the block information, like also the name.

I don’t know if somebody else raised this topic but the main issue with this approach is that the styles defined by the blocks are questionable and subjective, some more, some less, and the most difficult to be used is the columns block (I’ve opened a discussion about it here #41984), and this approach is a little more “strong” than a classic stylesheet in my opinion.

@andrewserong
Copy link
Contributor

Excellent, thanks for the extra context @simom! I like the filter idea for disabling output, I'll play around with a couple of ideas and link a PR to this thread once I've got something working.

And thanks for opening up the separate discussion for Columns — there are lots of issues to tease apart when it comes to layout, so good idea ensuring we've got that captured separately 👍

@andrewserong
Copy link
Contributor

andrewserong commented Jul 21, 2022

I've opened up a PR to explore a theme support feature to opt-out of all generated Layout styles in #42544 (the goal is to effectively do the same thing as the current approach that some folks use of overriding the Layout block support callback, which as of #40875 will no longer work to completely remove layout styles). Hopefully having it as a documented theme support will make it a bit clearer that base flex Layout styles are an opt-out feature, along with documenting that themes that do that will be responsible for providing structural layout styles for the blocks that depend on it. Happy for feedback over on the PR!

@simom
Copy link

simom commented Jul 21, 2022

Hi @andrewserong and thanks for your feedback!

What will be the role of the block editor stylesheet in the future? If I add the theme support 'disable-layout-styles' the layout technically shouldn't still work because there is still the layout style in the main block-editor stylesheet?

Obviously this is not something really useful because the stylesheet layout style should be the same of the auto generated one, but I'm just curious.

@mburridge mburridge added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Sep 13, 2022
@mburridge
Copy link
Contributor

Added the Needs Dev Note label in case this needs a dev note (either individual or as part of a "misc" dev note) for WP 6.1 release.

whereiscodedude pushed a commit to whereiscodedude/wpss that referenced this pull request Sep 18, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
Merges [53568] to the 6.0 branch.
See #56058.
Built from https://develop.svn.wordpress.org/branches/6.0@53569
whereiscodedude pushed a commit to whereiscodedude/wpss that referenced this pull request Sep 18, 2022
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
See #56058.
Built from https://develop.svn.wordpress.org/trunk@53568
@bph bph mentioned this pull request Oct 3, 2022
89 tasks
VenusPR added a commit to VenusPR/Wordpress_Richard that referenced this pull request Mar 9, 2023
…utes specified.

[WordPress/gutenberg#38719 In 5.9 these utility classnames were removed], which removed the ability for theme/plugin authors to assign their own custom CSS related to specific layout selections. This was mostly related to the Button block.

This commit adds these classes dynamically based on attributes, rather than saving them to the serialized content.

Original PR from Gutenberg repository:
* [WordPress/gutenberg#41487 #41487 Add utility classnames back to blocks that have layout attributes specified]

Props glendaviesnz, peterwilsoncc, andrewserong, zieladam, matveb, samikeijonen.
Merges [53568] to the 6.0 branch.
See #56058.
Built from https://develop.svn.wordpress.org/branches/6.0@53569


git-svn-id: http://core.svn.wordpress.org/branches/6.0@53158 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Regression Related to a regression in the latest release
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants