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

Always pass layout to inner blocks #47477

Merged
merged 7 commits into from
Jan 31, 2023

Conversation

tellthemachines
Copy link
Contributor

What?

This enables the layout config of a parent block to always be passed to its inner blocks by default. It's one of the remaining steps towards the stabilisation of layout support 🙂

Why?

Addresses this comment, as well as miscellaneous unexpected behaviour around the ability to set wide/full alignments on child blocks.

It also removes a bunch of logic that wasn't actually doing anything from some of the core block edit functions 😅

How?

Main Features

  • Makes layout available as context from the BlockEdit function;
  • Retrieves layout from block edit context in useInnerBlocksProps;

Cleanup

Testing Instructions

  1. Test Buttons, Comments Pagination, Gallery, Group, Navigation, Post Content, Query, Query Pagination and Social Links blocks layout controls and make sure they still work as expected.
  2. In the Group block, check that wide/full alignment appears for a child Image block by default;
  3. In the same Group block, toggle "Inner blocks use content width" off. Check that wide/full controls no longer appear for the child Image block.
  4. Check that the scenario described in Layout: Re-instate alignwide and alignfull in flow layout get alignments #43502 is fixed.
  5. In a Column block, toggle "Inner blocks use content width" on. A child Image block should now display wide/full alignment controls.
  6. Check that children of Row block still show a "Width" control under dimensions and it still works as expected.

Testing Instructions for Keyboard

Screenshots or screencast

@tellthemachines tellthemachines self-assigned this Jan 27, 2023
@tellthemachines tellthemachines added the [Feature] Layout Layout block support, its UI controls, and style output. label Jan 27, 2023
@github-actions
Copy link

github-actions bot commented Jan 27, 2023

Size Change: -679 B (0%)

Total Size: 1.31 MB

Filename Size Change
build/block-editor/content-rtl.css 3.62 kB -41 B (-1%)
build/block-editor/content.css 3.62 kB -41 B (-1%)
build/block-editor/index.min.js 192 kB +1.01 kB (+1%)
build/block-editor/style-rtl.css 14.3 kB -1 B (0%)
build/block-editor/style.css 14.3 kB +2 B (0%)
build/block-library/blocks/video/editor-rtl.css 552 B -139 B (-20%) 🎉
build/block-library/blocks/video/editor.css 555 B -139 B (-20%) 🎉
build/block-library/editor-rtl.css 11.5 kB -111 B (-1%)
build/block-library/editor.css 11.5 kB -109 B (-1%)
build/block-library/index.min.js 199 kB -182 B (0%)
build/components/index.min.js 203 kB +12 B (0%)
build/customize-widgets/index.min.js 11.8 kB -10 B (0%)
build/edit-post/index.min.js 34.5 kB -6 B (0%)
build/edit-site/index.min.js 63.1 kB -402 B (-1%)
build/edit-site/style-rtl.css 9.44 kB -84 B (-1%)
build/edit-site/style.css 9.44 kB -84 B (-1%)
build/edit-widgets/index.min.js 16.9 kB -3 B (0%)
build/editor/index.min.js 45 kB -373 B (-1%)
build/experiments/index.min.js 905 B +1 B (0%)
build/format-library/index.min.js 7.23 kB +35 B (0%)
build/reusable-blocks/index.min.js 2.26 kB -10 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.78 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 483 B
build/block-directory/index.min.js 7.16 kB
build/block-directory/style-rtl.css 1.04 kB
build/block-directory/style.css 1.04 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 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 90 B
build/block-library/blocks/archives/style.css 90 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 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 138 B
build/block-library/blocks/audio/theme.css 138 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 84 B
build/block-library/blocks/avatar/style.css 84 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 485 B
build/block-library/blocks/button/editor.css 485 B
build/block-library/blocks/button/style-rtl.css 532 B
build/block-library/blocks/button/style.css 532 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 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 100 B
build/block-library/blocks/categories/style.css 100 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 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 199 B
build/block-library/blocks/comment-template/style.css 198 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 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 612 B
build/block-library/blocks/cover/editor.css 613 B
build/block-library/blocks/cover/style-rtl.css 1.57 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 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 138 B
build/block-library/blocks/embed/theme.css 138 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 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 984 B
build/block-library/blocks/gallery/editor.css 988 B
build/block-library/blocks/gallery/style-rtl.css 1.55 kB
build/block-library/blocks/gallery/style.css 1.55 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 654 B
build/block-library/blocks/group/editor.css 654 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 829 B
build/block-library/blocks/image/editor.css 828 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 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/latest-comments/style-rtl.css 298 B
build/block-library/blocks/latest-comments/style.css 298 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 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 507 B
build/block-library/blocks/media-text/style.css 505 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 716 B
build/block-library/blocks/navigation-link/editor.css 715 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/editor-rtl.css 2.13 kB
build/block-library/blocks/navigation/editor.css 2.14 kB
build/block-library/blocks/navigation/style-rtl.css 2.22 kB
build/block-library/blocks/navigation/style.css 2.2 kB
build/block-library/blocks/navigation/view-modal.min.js 2.81 kB
build/block-library/blocks/navigation/view.min.js 447 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 376 B
build/block-library/blocks/page-list/editor.css 376 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 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 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 501 B
build/block-library/blocks/post-comments-form/style.css 501 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 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 586 B
build/block-library/blocks/post-featured-image/editor.css 584 B
build/block-library/blocks/post-featured-image/style-rtl.css 318 B
build/block-library/blocks/post-featured-image/style.css 318 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/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 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 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 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 326 B
build/block-library/blocks/pullquote/style.css 325 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 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 440 B
build/block-library/blocks/query/editor.css 440 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 149 B
build/block-library/blocks/rss/editor.css 149 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 409 B
build/block-library/blocks/search/style.css 406 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 234 B
build/block-library/blocks/separator/style.css 234 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 490 B
build/block-library/blocks/site-logo/editor.css 490 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 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 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 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.4 kB
build/block-library/blocks/social-links/style.css 1.39 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 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 651 B
build/block-library/blocks/table/style.css 650 B
build/block-library/blocks/table/theme-rtl.css 157 B
build/block-library/blocks/table/theme.css 157 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 404 B
build/block-library/blocks/template-part/editor.css 404 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 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/style-rtl.css 179 B
build/block-library/blocks/video/style.css 179 B
build/block-library/blocks/video/theme-rtl.css 139 B
build/block-library/blocks/video/theme.css 139 B
build/block-library/classic-rtl.css 162 B
build/block-library/classic.css 162 B
build/block-library/common-rtl.css 1.05 kB
build/block-library/common.css 1.05 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/style-rtl.css 12.4 kB
build/block-library/style.css 12.4 kB
build/block-library/theme-rtl.css 698 B
build/block-library/theme.css 703 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 50.4 kB
build/components/style-rtl.css 11.6 kB
build/components/style.css 11.7 kB
build/compose/index.min.js 12.3 kB
build/core-data/index.min.js 15.9 kB
build/customize-widgets/style-rtl.css 1.41 kB
build/customize-widgets/style.css 1.41 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.06 kB
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.71 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/style-rtl.css 7.46 kB
build/edit-post/style.css 7.45 kB
build/edit-widgets/style-rtl.css 4.49 kB
build/edit-widgets/style.css 4.49 kB
build/editor/style-rtl.css 3.68 kB
build/editor/style.css 3.67 kB
build/element/index.min.js 4.93 kB
build/escape-html/index.min.js 548 B
build/format-library/style-rtl.css 598 B
build/format-library/style.css 597 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.79 kB
build/keycodes/index.min.js 1.88 kB
build/list-reusable-blocks/index.min.js 2.14 kB
build/list-reusable-blocks/style-rtl.css 865 B
build/list-reusable-blocks/style.css 865 B
build/media-utils/index.min.js 2.99 kB
build/notices/index.min.js 977 B
build/plugins/index.min.js 1.95 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.35 kB
build/primitives/index.min.js 960 B
build/priority-queue/index.min.js 1.52 kB
build/react-i18n/index.min.js 702 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.75 kB
build/reusable-blocks/style-rtl.css 265 B
build/reusable-blocks/style.css 265 B
build/rich-text/index.min.js 10.8 kB
build/server-side-render/index.min.js 2.09 kB
build/shortcode/index.min.js 1.52 kB
build/style-engine/index.min.js 1.53 kB
build/token-list/index.min.js 650 B
build/url/index.min.js 3.69 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.31 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.06 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.

Yay, this is exciting, great to see this tidy up! I probably won't get a chance to give this a detailed look before I wrap up for the day, so just added a couple of drive-by comments about the query deprecation that stood out to me while skim-reading. Apologies if I've missed details / context there, as I was only looking quite quickly! 🙂

@@ -296,6 +296,80 @@ const v3 = {
},
};

const deprecated = [ v3, v2, v1 ];
const v4 = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a fixture to match this added deprecation? (e.g. core__query__deprecated-4.html etc)
It might be a little tricky if the deprecation depends on an earlier version of useInnerBlocksProps.save() to make sure that we test the deprecation is being run correctly 🤔

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, I always forget about the fixtures 😅

Comment on lines 354 to 355
isEligible: ( { layout } ) =>
! layout || layout.inherit || layout.contentSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

By including layout.contentSize in the eligibility list, what happens if a user sets a content size after it's migrated to a constrained layout? Will this match happen another time?

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 re-used the same logic from the Group block deprecation which seems to be working fine, but will double-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, turns out it does run so I added an extra check to only run it if content size is set without constrained layout.

@github-actions
Copy link

github-actions bot commented Jan 27, 2023

Flaky tests detected in f1acfb5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4050529877
📝 Reported issues:

@tellthemachines
Copy link
Contributor Author

tellthemachines commented Jan 30, 2023

Thanks for reviewing, folks! I've addressed the feedback so far and added a deprecation fixture so I think this is ready for another round.

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 all the follow-up here @tellthemachines! I haven't finished working through testing all the blocks, but just thought I'd leave the review now as I think the change to the full/wide alignments for flow layout appears to reintroduce the issue that was resolved by #43502. Let me know if you need any other info there!

Otherwise, I like the logic change here, and it feels like it's honing in on a good structure for passing down layout in an intuitive way that results in blocks needing to do less work — it seems like this is nearly there!

attributes = {},
__unstableLayoutClassNames,
} = props;
const { layout = null } = attributes;
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be super edge-casey, but I was wondering if we should check whether or not the block has opted-in to the layout support before passing down its layout attribute in the context? Because this will apply to all blocks, if a 3rd party block happens to use an attribute also named layout, then it will be passed down here, too, without a check for the layout block support.

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 idea, let's do that!

@@ -67,22 +67,13 @@ export default {
info: alignmentInfo[ alignment ],
} ) );
}
const { contentSize, wideSize } = layout;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double-checking — is the idea that this can be removed now because of the layout object being passed down? From testing, the issue of the wide width post template showing up using content size appears to have returned in this PR. I think the flow layout might still need the logic here (or elsewhere), so that the alignwide and alignfull classnames can be injected.

With TwentyTwentyTwo theme applied, it looks like the post template is being rendered as wide width on the site frontend, but content width in the site editor:

Editor (note 650px) Site frontend (note 1000px)
image image

It looks like on the site frontend the post template block's output has both is-layout-flow and alignwide classes as expected, however in the site editor the alignwide class is not present.

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 code needs to be removed because it's causing align wide and full controls to always show, even if the parent block doesn't have a content width. The problem is that the layout we're extracting content and wide size from there is the full theme layout, not the block one, so it always includes those properties if they're set by the theme.

The specific problem those lines were fixing should now be fixed by the Query block deprecation. I only checked with the test markup from your PR, but will have a look at TT2 now.

@@ -1,3 +1,3 @@
<!-- wp:query -->
<!-- wp:query {"query":{"perPage":null,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null,"parents":[]},"displayLayout":{"type":"list"}} -->
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't quite work out why this change to serialized markup for the block with empty attributes is required. Is it because of the deprecation updating the attributes? In practice I don't think it really matters that this serializes the default values of the empty state of the block, but was just curious as to why that's happening now 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh that's weird, not sure why it's happening 🤔

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 simplified the fixture a bit and removed some values I'd incorrectly copied from the previous deprecation, but no changes to this file. I guess it should be fine? 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea simplifying the fixtures. For this one, I think it's just that what gets serialized for the block's default state has changed — I don't think it's really an issue though since it's just the block attribute's metadata for when it's in the placeholder state. I'll just CC @ntsekouras for visibility, but I don't think it'd be a blocker.

@tellthemachines
Copy link
Contributor Author

tellthemachines commented Jan 31, 2023

I think the change to the full/wide alignments for flow layout appears to reintroduce the issue that was resolved by #43502. Let me know if you need any other info there

Funny, it's working for me. What happens when you paste the test markup into the code editor? Doesn't the Query block layout attribute get auto-updated with "type":"constrained"?

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.

Oh, interesting, yes if I cut the markup from TT2's home template so that there's a change to the site's markup and then paste it back in within the code editor view then the deprecation runs. However, for the template that ships with the theme, when opening the site editor, it doesn't look like the query block is updated immediately 🤔

This is the test markup from TT2:

Test markup from TT2's home template
<!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"tagName":"main","displayLayout":{"type":"list"},"layout":{"inherit":true}} -->
<main class="wp-block-query"><!-- wp:post-template {"align":"wide"} -->
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:post-title {"isLink":true,"align":"wide","fontSize":"var(\u002d\u002dwp\u002d\u002dcustom\u002d\u002dtypography\u002d\u002dfont-size\u002d\u002dhuge, clamp(2.25rem, 4vw, 2.75rem))"} /-->

<!-- wp:post-featured-image {"isLink":true,"align":"wide","style":{"spacing":{"margin":{"top":"calc(1.75 * var(\u002d\u002dwp\u002d\u002dstyle\u002d\u002dblock-gap))"}}}} /-->

<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"650px"} -->
<div class="wp-block-column" style="flex-basis:650px"><!-- wp:post-excerpt /-->

<!-- wp:post-date {"format":"F j, Y","isLink":true,"style":{"typography":{"fontStyle":"italic","fontWeight":"400"}},"fontSize":"small"} /--></div>
<!-- /wp:column -->

<!-- wp:column {"width":""} -->
<div class="wp-block-column"></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->

<!-- wp:spacer {"height":"112px"} -->
<div style="height:112px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:group -->
<!-- /wp:post-template -->

<!-- wp:query-pagination {"paginationArrow":"arrow","align":"wide","layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous {"fontSize":"small"} /-->

<!-- wp:query-pagination-numbers /-->

<!-- wp:query-pagination-next {"fontSize":"small"} /-->
<!-- /wp:query-pagination --></main>
<!-- /wp:query -->

So what I'm wondering:

  • Is there some reason why the deprecation isn't initially running when the site editor opens the template, either in the deprecation, or in the site editor?
  • If it's tricky to figure out, would it be worth retaining the wide / full alignment logic in the layouts/flow.js file for backwards compatibility, or does it cause other issues keeping it in place? 🤔

return {
...attributes,
layout: {
...layout,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed that if layout.inherit is true, then this still gets included in the object here. Should we add a inherit: undefined line here after ...layout?

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 don't think there's any harm in keeping it. We've been keeping it for the Group block deprecation, and on the whole I think the less we change the less scope there is for things to go wrong 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

The main reason I thought of removing it is that a truthy check for layout.inherit is included in the isEligible callbacks, so I was wondering if it'd be possible for a migrated block to be treated as though it hasn't been migrated if the inherit value sticks around 🤔

Totally agree with trying to change fewer things, though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also change the check to not run at all if type: "contstrained" is present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why other blocks don't have a deprecation except for Query? It's weird to have an empty Query Loop with all the attributes set.. Also the migrate function should run only to this deprecation? Usually it's needed to also run for other migrations..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Query deprecation doesn't address this change, it should have been added as part of #42763. I added it here in an attempt to fix the issue reported in #43502, as the solution from that PR was causing other breakage.

Also the migrate function should run only to this deprecation? Usually it's needed to also run for other migrations...

I'm not sure I understand. Is there anything I should change here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't tested, but this is from the docs:

It is important to note that if a deprecation’s save method does not produce a valid block then it is skipped completely, including its migrate method, even if isEligible would return true for the given attributes. This means that if you have several deprecations for a block and want to perform a new migration, like moving content to InnerBlocks, you may need to update the migrate methods in multiple deprecations in order for the required changes to be applied to all previous versions of the block.

You could test by copy/paste the other deprecated versions and see if there are errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, got it, thanks! I'll have a look.

@tellthemachines
Copy link
Contributor Author

Is there some reason why the deprecation isn't initially running when the site editor opens the template, either in the deprecation, or in the site editor?

Yeah, that's a very good question 😅

I'm noticing further that the deprecation only doesn't run if the template has no customizations, so there must be some check that skips brand new templates. That means we can solve the problem by updating the theme markup in Core, because any instance of the template already in use is likely to have some customization to it so should work.

We should get to the bottom of the deprecation issue, but I'm hesitant to block this change for its sake, so suggest we do it as a follow-up task.

If it's tricky to figure out, would it be worth retaining the wide / full alignment logic in the layouts/flow.js file for backwards compatibility, or does it cause other issues keeping it in place?

It does cause other issues - currently we have children of Group blocks with flow layout showing wide/full controls, which feels broken because those controls don't do anything if the parent is a flow block.

@andrewserong
Copy link
Contributor

We should get to the bottom of the deprecation issue, but I'm hesitant to block this change for its sake, so suggest we do it as a follow-up task.

Sounds good — if I go in to the template and make a change, e.g. adding a paragraph and then save and reload the site editor, then the migration happens. So it's fairly easy for a template to get to the correct state, it's just unfortunate that that isn't happening earlier 🤔

It does cause other issues - currently we have children of Group blocks with flow layout showing wide/full controls, which feels broken because those controls don't do anything if the parent is a flow block.

I always find these ones tricky where we need to choose between two things that might feel broken, and determine which is the less broken-feeling one. But in this case, and with the timeline on feature freeze for 6.2, I think I agree with the logic here 👍

I'll continue working through the other tests cases!

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.

Alrighty, this is testing well for me, the only issues I ran into are the ones we've already discussed, and it seems to me that the trade-offs favour merging in the current state, as it's a big improvement to consolidate the logic surrounding passing down layout, and it's a great idea getting this in for 6.2.

I tested the following:

  • The following blocks behave correctly in the editor and render correctly on the site frontend as far as I can tell:
    • ✅ Buttons
    • ✅ Comments Pagination
    • ✅ Group
    • ✅ Navigation
    • ✅ Post Content
    • ✅ Query
    • ✅ Query Pagination
    • ✅ Social Links
  • ✅ Tested group block as wrapper for image block, and that wide/full alignement controls only appear for constrained layout type
  • ❓ Checked that the scenario described in Layout: Re-instate alignwide and alignfull in flow layout get alignments #43502 is fixed — it is fixed once the deprecation is run, but in TT2 where the template does not have the latest markup, the deprecation only appears to run when the template is altered. I agree that it's not a blocker for this PR to land, but it'd be a good follow up bug to look into.
  • ✅ Column block child image only has wide/full controls when constrained layout is set
  • ✅ Row children width controls are working correctly

Nice work, LGTM! ✨

@tellthemachines
Copy link
Contributor Author

Thanks for the reviews and extensive testing @andrewserong 🎉 I'm going to merge this as is to unblock #47584 and hopefully also #45326, and start looking into the follow-ups.

@tellthemachines tellthemachines merged commit fff6d81 into trunk Jan 31, 2023
@tellthemachines tellthemachines deleted the try/passing-layout-to-inner-blocks branch January 31, 2023 04:46
@github-actions github-actions bot added this to the Gutenberg 15.1 milestone Jan 31, 2023
@corentin-gautier
Copy link
Contributor

Hi @tellthemachines I no longer have wide/full alignment options on first level blocks since this has been merged, they do appear on child blocks though

@juanmaguitar juanmaguitar added the [Type] Enhancement A suggestion for improvement. label Jan 31, 2023
@tellthemachines
Copy link
Contributor Author

Hi @corentin-gautier, could you provide some more details to help debug?

  • Is the issue occurring in the Post editor, the Site editor or both?
  • Which theme are you using?
  • Can you reproduce the issue with a default theme (Twenty Twenty Three or Twenty Twenty Two)?

Thanks!

@corentin-gautier
Copy link
Contributor

corentin-gautier commented Feb 2, 2023

Hi @tellthemachines

I'm using a custom theme which doesn't use the site editor so I only experienced this issue in the post editor, the issue doesn't happen in twenty twenty three

EDIT: It does happen in twenty twenty three, but after a few seconds it goes back to normal

Screen.Recording.2023-02-02.at.10.34.20.mov

@gyurmey2
Copy link

gyurmey2 commented Feb 9, 2023

Hi @tellthemachines, @corentin-gautier, I am facing a similar problem. For some reason, it's only found in some themes, e.g. Upsidedown & Disco By Automatic, but there are more of these themes. You can test at this link.

video.mp4

@tellthemachines
Copy link
Contributor Author

Hi @gyurmey2 , thanks for the report! I can confirm that on that test site, with Upsidedown theme, the wide/full controls don't appear for root blocks in the post editor. This happens because the Post Content block in the Single template doesn't have content width enabled:

Screenshot 2023-02-10 at 9 36 36 am

You'll notice that if you disable the Gutenberg plugin, root blocks in the post editor now show the wide/full controls:

Screenshot 2023-02-10 at 9 34 36 am

However, on the front end, those blocks set to wide/full are the same width as regular blocks:

Screenshot 2023-02-10 at 9 33 10 am

So the change that this PR introduced brings consistency between editor and front end, in that if the Post Content doesn't set a content width for its children, they will always take up the full width of their container (which in this case is the Post Content block), so wide/full controls aren't available because they won't have any effect.

@corentin-gautier I suspect something similar might be happening with your custom theme. The issue that your video captures in Twenty Twenty Three is slightly different, as that theme does have content width in its Post Content block. That layout change we can see in the video is due to a performance issue with loading post content styles in the post editor, which #45299 should fix.

@Mamaduka
Copy link
Member

Mamaduka commented Feb 10, 2023

@tellthemachines, I think this report is also related to changes here - #47857.

Edit: Confirmed by using git bisect that the Hybrid theme regression commit is fff6d81.

@gyurmey2
Copy link

@tellthemachines, thank you very much for the detailed explanation (now I understand why this is happening).

Another problem I've been struggling with for a long time is the differences between the editor and the frontend. Could you help please? Same test link.

@corentin-gautier
Copy link
Contributor

corentin-gautier commented Feb 10, 2023

@tellthemachines Thing is : I'm not using the template editor in my theme (I use classic php > twig files) which means I don't have a post content block because I don't have a Single Template. Which means this PR breaks the alignment on root blocks for classic themes ...

It's exactly what's described in #47857

EDIT: Oh I see there's a PR for this already : #47961

@tellthemachines
Copy link
Contributor Author

@corentin-gautier I see, thanks for flagging this! It should be fixed with #47961.

@tellthemachines
Copy link
Contributor Author

Another problem I've been struggling with for a long time is the differences between the editor and the frontend. Could you help please? Same test link.

@gyurmey2 that is an actual bug! Looks like it has already been reported in #46724. I'll leave a comment over there to keep everything in the same place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Layout Layout block support, its UI controls, and style output. Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants