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 layout styles from Post Content block to post editor #44258

Merged
merged 14 commits into from
Sep 27, 2022

Conversation

tellthemachines
Copy link
Contributor

Why?

Fixes #42911, #44110, #44208.

How?

Gets layout classnames and styles from Post Content block so post editor layout can match the front end in all respects.

WIP

Todo:

  • remove hardcoded layout styles from post editor (custom content widths aren't working yet because they're being overridden by those)
  • make sure child block alignments are correct per Post Content layout type
  • useLayoutClasses, useLayoutStyles should probably be experimental or unstable?
  • add tests

Testing Instructions

  1. In site editor, change layout settings of Post Content block
  2. Check that new layout is reflected in the front end

Screenshots or screencast

@tellthemachines tellthemachines added [Type] Bug An existing feature does not function as intended [Package] Edit Post /packages/edit-post [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Block] Post Content Affects the Post Content Block labels Sep 19, 2022
@github-actions
Copy link

github-actions bot commented Sep 19, 2022

Size Change: +5.78 kB (0%)

Total Size: 1.26 MB

Filename Size Change
build/block-directory/index.min.js 7.09 kB +6 B (0%)
build/block-editor/index.min.js 166 kB +3.21 kB (+2%)
build/block-editor/style-rtl.css 15.4 kB +14 B (0%)
build/block-editor/style.css 15.4 kB +10 B (0%)
build/block-library/blocks/group/editor-rtl.css 384 B +47 B (+14%) ⚠️
build/block-library/blocks/group/editor.css 384 B +47 B (+14%) ⚠️
build/block-library/blocks/image/editor-rtl.css 884 B +8 B (+1%)
build/block-library/blocks/image/editor.css 882 B +9 B (+1%)
build/block-library/blocks/navigation/editor-rtl.css 2 kB +11 B (+1%)
build/block-library/blocks/navigation/editor.css 2.01 kB +11 B (+1%)
build/block-library/blocks/paragraph/editor-rtl.css 317 B +143 B (+82%) 🆘
build/block-library/blocks/paragraph/editor.css 317 B +143 B (+82%) 🆘
build/block-library/editor-rtl.css 11.1 kB +84 B (+1%)
build/block-library/editor.css 11.1 kB +85 B (+1%)
build/block-library/index.min.js 191 kB +835 B (0%)
build/block-serialization-spec-parser/index.min.js 2.83 kB +2 B (0%)
build/blocks/index.min.js 49.8 kB +36 B (0%)
build/components/index.min.js 198 kB +669 B (0%)
build/components/style-rtl.css 11.5 kB +14 B (0%)
build/components/style.css 11.5 kB +15 B (0%)
build/compose/index.min.js 12.5 kB +21 B (0%)
build/core-data/index.min.js 15.5 kB +3 B (0%)
build/customize-widgets/index.min.js 11.3 kB +2 B (0%)
build/data/index.min.js 8.08 kB -4 B (0%)
build/edit-navigation/index.min.js 16 kB +5 B (0%)
build/edit-post/index.min.js 31.1 kB +284 B (+1%)
build/edit-site/index.min.js 57.6 kB +14 B (0%)
build/edit-widgets/index.min.js 16.5 kB -1 B (0%)
build/editor/index.min.js 41.6 kB +3 B (0%)
build/element/index.min.js 4.68 kB +1 B (0%)
build/format-library/index.min.js 6.77 kB +3 B (0%)
build/keyboard-shortcuts/index.min.js 1.78 kB +1 B (0%)
build/keycodes/index.min.js 1.83 kB -1 B (0%)
build/notices/index.min.js 963 B +10 B (+1%)
build/nux/index.min.js 2.06 kB +10 B (0%)
build/preferences-persistence/index.min.js 2.22 kB +2 B (0%)
build/rich-text/index.min.js 10.6 kB +55 B (+1%)
build/style-engine/index.min.js 1.45 kB +6 B (0%)
build/vendors/react-dom.min.js 38.5 kB -23 B (0%)
build/viewport/index.min.js 1.08 kB -9 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/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 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 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 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 482 B
build/block-library/blocks/button/editor.css 482 B
build/block-library/blocks/button/style-rtl.css 523 B
build/block-library/blocks/button/style.css 523 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 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/editor-rtl.css 834 B
build/block-library/blocks/comments/editor.css 832 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 605 B
build/block-library/blocks/cover/editor.css 607 B
build/block-library/blocks/cover/style-rtl.css 1.57 kB
build/block-library/blocks/cover/style.css 1.55 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 126 B
build/block-library/blocks/embed/theme.css 126 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/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/style-rtl.css 627 B
build/block-library/blocks/image/style.css 630 B
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 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 213 B
build/block-library/blocks/latest-posts/editor.css 212 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 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 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/style-rtl.css 2.17 kB
build/block-library/blocks/navigation/style.css 2.16 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/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-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 547 B
build/block-library/blocks/post-featured-image/editor.css 545 B
build/block-library/blocks/post-featured-image/style-rtl.css 315 B
build/block-library/blocks/post-featured-image/style.css 315 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 73 B
build/block-library/blocks/post-terms/style.css 73 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 282 B
build/block-library/blocks/query-pagination/style.css 278 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 439 B
build/block-library/blocks/query/editor.css 439 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 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 464 B
build/block-library/blocks/shortcode/editor.css 464 B
build/block-library/blocks/site-logo/editor-rtl.css 488 B
build/block-library/blocks/site-logo/editor.css 488 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 84 B
build/block-library/blocks/site-title/editor.css 84 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 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 190 B
build/block-library/blocks/table/theme.css 190 B
build/block-library/blocks/tag-cloud/style-rtl.css 239 B
build/block-library/blocks/tag-cloud/style.css 239 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 174 B
build/block-library/blocks/video/style.css 174 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 162 B
build/block-library/classic.css 162 B
build/block-library/common-rtl.css 1.02 kB
build/block-library/common.css 1.02 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.2 kB
build/block-library/style.css 12.2 kB
build/block-library/theme-rtl.css 719 B
build/block-library/theme.css 722 B
build/block-serialization-default-parser/index.min.js 1.1 kB
build/customize-widgets/style-rtl.css 1.38 kB
build/customize-widgets/style.css 1.38 kB
build/data-controls/index.min.js 653 B
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 507 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.7 kB
build/edit-navigation/style-rtl.css 3.99 kB
build/edit-navigation/style.css 4 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/style-rtl.css 6.94 kB
build/edit-post/style.css 6.94 kB
build/edit-site/style-rtl.css 8.36 kB
build/edit-site/style.css 8.34 kB
build/edit-widgets/style-rtl.css 4.34 kB
build/edit-widgets/style.css 4.34 kB
build/editor/style-rtl.css 3.62 kB
build/editor/style.css 3.61 kB
build/escape-html/index.min.js 537 B
build/experiments/index.min.js 868 B
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/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/nux/style-rtl.css 732 B
build/nux/style.css 728 B
build/plugins/index.min.js 1.94 kB
build/preferences/index.min.js 1.3 kB
build/primitives/index.min.js 933 B
build/priority-queue/index.min.js 1.58 kB
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.74 kB
build/reusable-blocks/index.min.js 2.21 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
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.min.js 4.34 kB
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.18 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.19 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.

I love the direction here @tellthemachines, this looks very promising!

When testing manually in my local environment, it looks like it wasn't able to find a post content block, even though templateBlocks contains a nested one:

image

I've left a comment on findPostContent — I'm pretty sure it might be a fairly simple change in that function to get it working.

Happy to do further testing!

Comment on lines 771 to 776
Generates the utility classnames for the given blocks layout attributes.
This method was primarily added to reintroduce classnames that were removed
in the 5.9 release (<https://github.com/WordPress/gutenberg/issues/38719>), rather
than providing an extensive list of all possible layout classes. The plan is to
have the style engine generate a more extensive list of utility classnames which
will then replace this method.
Copy link
Contributor

Choose a reason for hiding this comment

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

This feedback is probably low priority, but just jotting down some thoughts:

When this function was originally written, I believe we were thinking that the style engine might be responsible for more of the layout support that we do now (I think this function was written prior to the layout refactor landing). It might be worth us updating the description here, as I believe it probably makes sense for useLayoutClasses to be the entry point for getting layout classnames — if in some point in the future we do use the style engine for constructing the classnames, we might wind up doing it as an internal implementation detail, so we'd still probably want this as the main function for getting those classnames?

In terms of stability / API signature, the function currently accepts the layout object, and a layoutDefinitions object. However, in useLayoutStyles the signature is a bit different in that it accepts a block object and a selector. Would it be worth coming up with a signature for both of these hooks that is pretty much the same, to create some consistency there? I like the use of the block object in the latter — we might wind up needing to access other aspects of the block object in useLayoutClasses in the future, too, so it could be worth making some changes there?

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 thinking this through! I'll update the description to remove references to hypothetical future style engine work 😅

Would it be worth coming up with a signature for both of these hooks that is pretty much the same, to create some consistency there?

We wouldn't need the selector for useLayoutClasses though, would we? Other than that I'm happy to change it to take the block object.

Copy link
Contributor

Choose a reason for hiding this comment

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

We wouldn't need the selector for useLayoutClasses though, would we?

Ah, good point. Yeah, I can't think of a circumstance where we'd need the selector for getting the classnames. We might have use for it eventually for where we output the classnames, but not for retrieving them in the first place?

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 I don't think we'd ever need the selector in useLayoutClasses.

I'm also struggling to think of a use for the whole block in this function; we only really need the layout object. We could potentially change it to get the layout definitions from useSetting( 'layout' ) instead of passing them as a parameter. Would that work everywhere?

In useLayoutStyles we need both layout and styles from attributes, as well as the block name to pass to the layout type's useLayoutStyles function, so it can work out whether the block skips serialisation or not.

It's not looking like we can make the signatures very consistent here 😅

Regarding the doc comment for useLayoutClasses, could we simply shorten it to "Generates the utility classnames for the given blocks layout attributes.", or is there any additional info that might be useful here?

Also, I'm thinking we should make these experimental given Layout itself has that status.

Copy link
Contributor

Choose a reason for hiding this comment

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

we only really need the layout object

Right now that's definitely the case. My only thought was if we wind up eventually needing to use parts of the spacing object for potential future classnames (e.g. if we needed to add a has-gap classname further down the track, which I think was discussed a little in the spacing presets discussions), then it'd be easier if we already had the object there.

We could potentially change it to get the layout definitions from useSetting( 'layout' ) instead of passing them as a parameter. Would that work everywhere?

That very well could. I think passing it around is probably a result of some of these functions originally being pure functions instead of React hooks? Now that they're hooks, it's probably better to keep the API signature simpler instead of passing stuff around 🤔

"Generates the utility classnames for the given blocks layout attributes."

Sounds good to me!

Also, I'm thinking we should make these experimental given Layout itself has that status.

Good idea, there's still plenty that we're moving around, so would be good to maintain that flexibility 👍

@@ -89,6 +89,24 @@ function useLayoutClasses( layout, layoutDefinitions ) {
return layoutClassnames;
}

export function useLayoutStyles( block = {}, selector ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice abstraction here!

Comment on lines 209 to 241
const templateBlocks = parse( templateContent );
const postContentBlock = findPostContent( templateBlocks );
const postContentLayoutClasses = useLayoutClasses(
postContentBlock?.attributes?.layout,
defaultLayout?.definitions
);

const blockListLayoutClass = classnames(
{
'is-layout-flow': ! themeSupportsLayout,
'wp-container-visual-editor': themeSupportsLayout,
},
postContentLayoutClasses
);

const postContentLayoutStyles = useLayoutStyles(
postContentBlock,
'.wp-container-visual-editor'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we ultimately want to wrap this in a useMemo so that we only run it when templateContent changes?

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 question! I never know when it's best to useMemo or not 😅 Another option would be to return null from useLayoutStyles if there's no block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option would be to return null from useLayoutStyles if there's no block.

Actually I don't think we can do that because it's using hooks underneath 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

I never know when it's best to useMemo or not 😅

Me either, it's often a bit tricky to work out when they're useful. In principle if we're doing potentially expensive things like block parsing on a component that might get rendered multiple times, I think it makes sense to add a useMemo. If I add a wrapper findPostContentWrapper function that calls findPostContent and log out the number of times it's called, in my local environment it looks like we call it 9 times (not sure how valid that is, since there's only 5 log lines there, but it at least suggests we might benefit from the useMemo caching 🤔):

image

From memory we can't call a hook from within another hook, so the optimisation might only be to wrap the block containing the two lines parse and findPostContent in a useMemo, so that we only parse / find blocks when the template content changes?

But this can totally be something to look at in the final stages of the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I tried what you recommended and it seems to be working well! We can still see a jump in layout when the page first loads, I think because the initial data from useSelect takes a while to appear, but I don't think there's much to be done about that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think because the initial data from useSelect takes a while to appear, but I don't think there's much to be done about that.

Probably outside the scope of this PR, but I wonder if there's a way to preload the data for this selector? I see that the Navigation block has a preloading function here and sets apiFetch to use it here. There's similar logic in gutenberg_initialise_editor here, so I wonder if there's a PHP filter of some kind to add in a desired API endpoint to pre-fetch or something? Might be a bit of a rabbithole 😅

I don't at all understand the logic there, but just in case something along those lines sparks any ideas 🙂

return blocks[ i ];
}
if ( blocks[ i ].innerBlocks.length ) {
return findPostContent( blocks[ i ].innerBlocks );
Copy link
Contributor

@andrewserong andrewserong Sep 20, 2022

Choose a reason for hiding this comment

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

I think we only want to return here if we've found a post content block? Otherwise it looks like findPostContent bails early without having found something if the first depth-first discovery does not match a post content block.

In my current template, it bails after examining the deepest separator block, rather than moving up a level to eventually find the post content block.

In the below screenshot, I logged out looking at for each instance of the for loop, and it appears to stop at the core/separator, where it should have moved up a level and found core/spacer and then moved down one to core/post-content.

image

So, maybe something like the following might work?

let foundPostContent;

...

foundPostContent = findPostContent( blocks[ i ].innerBlocks );
if ( foundPostContent ) {
    return foundPostContent;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhh well spotted! Yeah it'll have to be something along those lines.

@andrewserong
Copy link
Contributor

Nice one, that's fixed up locating the postContentBlock 👍

I noticed that if I go to make a change in the post content block of the current template it crashes the editor. Not too sure why, though!

2022-09-20 14 58 38

@andrewserong
Copy link
Contributor

I think I found another instance of templateContent oddly being not-a-string. If I go to update the Post Content block in the currently selected template in the template editor, and then close out of the template editor instead of saving, then the editor also crashes with the following error: (looks like it's returning a callback function instead of a string?)

Error message Clicking back from template editor
image 2022-09-21 13 25 25

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.

This is working pretty well so far, I'm really excited about the progress here!

I was wondering if it's also worth us hooking in the style engine to gather CSS for the other block supports that might be in use in the Post Content block instance in the current template. I'm mostly thinking of Typography supports like font-size, font family, and the like. It'd be cool if we could output those styles in addition to the layout styles (but I also totally understand if you think that's better for a separate PR). We might be able to get away with passing the block instance's style object to this function to get the CSS we need:

export function compileCSS( style: Style, options: StyleOptions = {} ): string {

Aside from the other couple of comments, I ran into another issue with TwentyTwentyTwo which is that it looks like its editor styles appear to override the layout content justification rules (it renders correctly on the site frontend). If I set the Post Content block in my current template to left content justification with custom content and wide sizes, here's how the Cover block looks in the editor:

image

// if it doesn't have one. If no Post Content this must be a classic theme,
// in which case we use the fallback layout.
const postContentLayout = postContentBlock
? postContentBlock?.attributes?.layout || { type: 'default' }
Copy link
Contributor

Choose a reason for hiding this comment

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

For this one, do we need the fallback logic for legacy markup (e.g. inherit) here, too? I noticed in TwentyTwentyTwo, the single template appears to still be using inherit so the view in the post editor for me was full width because it was assuming default (flow) layout instead of constrained:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooooh good point! On it.

@@ -286,9 +356,9 @@ export default function VisualEditor( { styles } ) {
className={
isTemplateMode
? 'wp-site-blocks'
: `${ blockListLayoutClass } wp-block-post-content` // Ensure root level blocks receive default/flow blockGap styling rules.
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if we might still need the wp-block-post-content classname to be added, so that we can hook into styles that are set at the core/post-content block in global styles? (It looks like the layout classnames don't output the block classname, so I think we might still need to add it in manually 🤔)

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'm a bit hazy on how the global styles stuff works in the post editor, so if you think it's needed I'll just add it back. Won't do any harm to have the class there 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit hazy on how the global styles stuff works in the post editor

I was looking at this the other day while reviewing other PRs, so in case the breadcrumbs here are helpful: it's pretty naive when it comes to global styles. The server-rendered global styles are added to the block editor settings in PHP here, and then the post editor figures out whether or not to use them here. The styles are then passed down to the post editor's Layout component on this line. That component then passes the styles to VisualEditor here. And in VisualEditor, the styles are passed to MaybeIframe which finally passes it along to EditorStyles, which ultimately outputs styles in a style tag on this line: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/editor-styles/index.js#L81

The TL;DR is that it's nearly as if the global styles stylesheet had been enqueued, only those styles get transformed a bit by the EditorStyles component to play nicely in the editor.

I mostly just wanted to write that out somewhere because it finally clicked for me how it's hooked together 😀

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, that's really helpful!

@tellthemachines
Copy link
Contributor Author

Thanks for the continued feedback @andrewserong! I think I've addressed everything so far; the only remaining todoes are adding tests for the experimental functions we're exposing and working out why e2e are failing on this branch 🤔

I was wondering if it's also worth us hooking in the style engine to gather CSS for the other block supports that might be in use in the Post Content block instance in the current template. I'm mostly thinking of Typography supports like font-size, font family, and the like.

Definitely let's do that, but I'd rather it be a separate PR to keep things simple for this one. I'm also unsure of the urgency of that work 6.1-wise, as so far we've only had reports about the missing layout styles.

@tellthemachines tellthemachines marked this pull request as ready for review September 21, 2022 06:25
@andrewserong
Copy link
Contributor

Sounds good 👍

I'm also unsure of the urgency of that work 6.1-wise, as so far we've only had reports about the missing layout styles.

I imagine it's most likely lower priority because themes can target core/post-content in global styles, so it's probably much rarer to need to set Typography rules at the individual block level. I think it'd only really make sense if your theme had one set of Typography styles for one template, and another for another template. E.g. if a site decided that their blog was in a mono-spaced typewriter-like font, but they wanted their About pages in a serif-font, that kinda thing.

@tellthemachines
Copy link
Contributor Author

Looking into adding tests for useLayoutClasses and useLayoutStyles, both of these use hooks internally that will have to be mocked. I wonder how useful it is to add these tests right now 🤔 as I suspect most of the bugs will come from wrong assumptions regarding what we pass into them, or what we retrieve with the hooks, rather than the actual logic in the functions which is pretty straightforward.

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 updates again @tellthemachines, this feels much closer. I left a comment where I think we might be able to fix up the styling issue with the Cover block in TwentyTwentyTwo.

It looks like there's still an issue with going to the template editor and then exiting out after making an unsaved change. While the editor no longer crashes, it looks like only dealing with a string value results in the editor forgetting which layout type to render. In my local env, after making a change and exiting out, the layout defaults to flow again stretching everything full width:

2022-09-21 16 49 26


const postContentLayoutStyles = useLayoutStyles(
postContentBlock,
'.wp-container-visual-editor'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this selector needs to be a higher specificity selector such as .block-editor-block-list__layout.is-root-container, which I think was used prior to this PR? If I use that one on this line, the layout styles appear to win out over the TwentyTwentyTwo styles as expected. But I wasn't sure if you changed this selector for another reason?

Current PR (TwentyTwentyTwo's margins override the left content justification) When updating to the higher specificity selector
image image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really! Must be my subconscious drive to lower specificity everywhere 😅
It's a good idea to use the selector we had before though.

Comment on lines 116 to 123
const usedLayout =
layout &&
( layout?.type === 'constrained' ||
layout?.inherit ||
layout?.contentSize ||
layout?.wideSize )
? { ...layout, type: 'constrained' }
: { ...layout, type: 'default' };
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we ever need to use this hook for flex layouts? With the current version, it looks like layout.type set to flex would result in output for the default 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.

Ooooooh right, that needs to change

@andrewserong
Copy link
Contributor

Looking into adding tests for useLayoutClasses and useLayoutStyles, both of these use hooks internally that will have to be mocked. I wonder how useful it is to add these tests right now

I agree, so long as we're manually testing each of the cases we're dealing with in these hooks, I think we can leave writing tests for them to a follow-up if need be 👍

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

A bit of a fly-by review, sorry! I don't have a lot of context, but the code reads well and changes I make to the post content block in the singular template are reflect in the post editor. 👍

Not sure what's going on with the inline template editing errors yet... 🤔

@@ -82,20 +85,40 @@ function MaybeIframe( {
);
}

function findPostContent( blocks ) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we help our future selves here and add a JS doc comment?

const postContentBlock = useMemo( () => {
// When in template editing mode, we can access the blocks directly.
if ( editedPostTemplate?.blocks ) {
return findPostContent( editedPostTemplate?.blocks );
Copy link
Member

Choose a reason for hiding this comment

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

I can reproduce error that @andrewserong noticed but only sometimes.

Most of the times it works for me.

When it does fail I suspect it's because postContentBlock is undefined (and therefore trying to access the attributes below fails).

Replacing with return findPostContent( editedPostTemplate?.blocks ) || {}; seems to get around that,

2022-09-26 12 39 39

But it exposes another error triggered by the component 🤣

Uncaught TypeError: Cannot read properties of null (reading 'removeEventListener')

previousElement.ownerDocument.defaultView.removeEventListener(

Not sure why yet. I can't reproduce either error in trunk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I've only managed to repro the error once on TT2, and not at all on Empty theme. But I think something's messed up because previous customisations are now appearing as the default template state 😅
Will continue investigating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I fixed the failure if Post Content block is removed from the template by accessing layout from attributes via optional chaining instead of destructuring. The reason returning empty object from findPostContent won't work correctly is some logic further down is dependent on checking if postContentBlock exists, and empty object will always be true 😅

@tellthemachines
Copy link
Contributor Author

I think I found another editor fatal. Using a template that has customizations made to it, if I go to open the template editor and then clear the customizations, this appears to throw a fatal, but doesn't on trunk:

I managed to reproduce the issue on trunk with Empty theme. Steps to reproduce:

  1. Create a new post and add some content but don't save or publish yet;
  2. Go into post template editing mode and make a change to the template;
  3. Save and publish both the template changes and the post;
  4. Click "Clear customizations" in the top area.

I'm not yet sure what's behind it; the error is due to something null being passed to either BlockParentSelector or BlockPopoverInbetween (in my testing errors alternate between the two 🤔)
In any case it seems unlikely to be related to this PR.

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.

I'm not yet sure what's behind it; the error is due to something null being passed to either BlockParentSelector or BlockPopoverInbetween (in my testing errors alternate between the two 🤔)
In any case it seems unlikely to be related to this PR.

Thanks for looking into that! One of the usages of BlockPopoverInbetween is in the ZoomOutModeInserters — I noticed that if I switch off that experimental feature, I can't seem to replicate the issue immediately, so perhaps it's related to that implementation? In any case, I agree, it sounds like it's unrelated to this change, maybe we just noticed it here.

Separately, I think I found another styling rule issue with the middle content justification, so I've added another comment. Not too sure if it's the right place?

Comment on lines +261 to +264
const postContentLayoutStyles = useLayoutStyles(
postContentBlock,
'.block-editor-block-list__layout.is-root-container'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there appears to be a difference in the rules that are being output here versus trunk 🤔 I noticed that there's an issue with the middle content justification with the Cover block set to wide alignment in TwentyTwentyTwo:

Trunk This PR
image image

This appears to be the rule that isn't present / winning out:

image

Copy link
Contributor

@andrewserong andrewserong Sep 26, 2022

Choose a reason for hiding this comment

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

I wonder if the issue is that useLayoutStyles generates the layout styles for the individual post content block, but not the base layout styles that need to be attached to this more specific selector in order for it to win out? Or to put it differently, prior to this PR, it looks like we might have depended on the output of base layout rules with this more specific selector for this middle content justification. Apologies if I'm way off!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those styles that are overriding the middle justification are the TT2 root padding logic that I thought were going to be removed after the Core root padding styles became available.

I'm reluctant to either increase specificity of the default layout styles or add wp-container rules for the default justification state, because any theme can conceivably still override them with higher specificity rules 😅

This should probably be fixed in TT2 instead cc @carolinan @scruffian

Copy link
Contributor

@andrewserong andrewserong Sep 26, 2022

Choose a reason for hiding this comment

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

I'm reluctant to either increase specificity of the default layout styles or add wp-container rules for the default justification state

Agreed, it'd be better not to have to add container rules, or explicit rules for the default justification state 🤔

This should probably be fixed in TT2 instead

It's a tricky one... because TT2 has been used as a base for many other themes, it might not just TT2 out in the wild that has this issue. (E.g. the rule appears to be part of BlockBase https://github.com/Automattic/themes/blob/23b9090090279c95788357bb634fd2e57c3973db/blockbase/sass/base/_alignment.scss#L58 which many themes have been built on top of, too).

Just trying to think of other options... would it work to update the change to this line in this PR

selector=".edit-post-visual-editor__post-title-wrapper"
to include .block-editor-block-list__layout.is-root-container as well (as on trunk)? Or did we we need to remove it for the postContentLayoutStyles to work? Since they already have the selector attached, I was wondering if they can coexist. From quickly adding it back in in my local environment, it appears to get all three content justifications working in TT2 for me, but it's highly likely I'm missing some context 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just trying to think of other options... would it work to update the change to this line in this PR to include .block-editor-block-list__layout.is-root-container as well (as on trunk)? Or did we we need to remove it for the postContentLayoutStyles to work?

I did remove it initially so that custom content widths would work, but because we since increased the specificity of the default rules it seems to be working ok. I just tried pushing that change now, hopefully it doesn't break anything else 😅

It's a tricky one... because TT2 has been used as a base for many other themes, it might not just TT2 out in the wild that has this issue.

I'm not sure how much of a concern that should be to us, because the temporary status of these rules is explicitly called out in the TT2 stylesheet.

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 one @tellthemachines, I think adding that rule back in did the trick. This is all testing nicely for me now. Also, adding back that rule seems to have fixed a flash of full width alignment on blocks when using the centre content justification in the post editor, so the UI feels a little more stable on a full page reload to me, now 👍

Tested with the following:

✅ TwentyTwentyTwo with left, center, right alignments, with a variety of content and wide size widths
✅ Tove blocks-based theme
✅ Emptytheme with the above, and useRootPaddingAwareAlignments to check that the new global padding settings still work correctly
✅ Classic themes TT1, TT, TwentyNineteen

I just left a comment where I think we can now remove the <LayoutStyle> component for classic themes since it'll already be covered in the earlier instance. But otherwise, this LGTM! ✨

Comment on lines 355 to 366
{
// For classic themes using theme.json we want a default content width in the editor.
! postContentBlock && (
<LayoutStyle
selector=".block-editor-block-list__layout.is-root-container"
layout={ fallbackLayout }
layoutDefinitions={
globalLayoutSettings?.definitions
}
/>
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that the above <LayoutStyle> also includes .block-editor-block-list__layout.is-root-container, it looks like we no longer need this conditional for classic themes, because it'll already be covered by the one above?

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 yes, well spotted!

@tellthemachines tellthemachines merged commit cf0b87a into trunk Sep 27, 2022
@tellthemachines tellthemachines deleted the fix/post-editor-layout branch September 27, 2022 03:22
@github-actions github-actions bot added this to the Gutenberg 14.3 milestone Sep 27, 2022
@tellthemachines tellthemachines added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Sep 27, 2022
@tyxla
Copy link
Member

tyxla commented Sep 28, 2022

Just closing the loop that in #44506 we addressed a performance regression introduced by this PR.

@andrewserong andrewserong added the [Feature] Layout Layout block support, its UI controls, and style output. label Sep 29, 2022
michalczaplinski pushed a commit that referenced this pull request Oct 3, 2022
* Add layout styles from Post Content block to post editor

* Fix post content finding logic.

* Remove extra styles when Post Content block exists.

* templateContent should always be a string

* Memoise post content block.

* Change function signature and mark experimental

* _Really_ make sure templateContent is a string

* Update layout type for legacy layouts.

* Fix selector specificity and legacy layout logic.

* Fix 404s on fetch and only parse content if needed

* Fix acces to layout when no Post Content block

* Add doc comment to findPostContent

* Increase specificity

* Remove unneeded LayoutStyle
@michalczaplinski michalczaplinski removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 3, 2022
@michalczaplinski
Copy link
Contributor

Cherry-picked for the 6.1 release in #44656

ockham pushed a commit that referenced this pull request Oct 4, 2022
* Add layout styles from Post Content block to post editor

* Fix post content finding logic.

* Remove extra styles when Post Content block exists.

* templateContent should always be a string

* Memoise post content block.

* Change function signature and mark experimental

* _Really_ make sure templateContent is a string

* Update layout type for legacy layouts.

* Fix selector specificity and legacy layout logic.

* Fix 404s on fetch and only parse content if needed

* Fix acces to layout when no Post Content block

* Add doc comment to findPostContent

* Increase specificity

* Remove unneeded LayoutStyle
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Oct 4, 2022
Package updates for bug and regression fixes:

* @wordpress/annotations: 2.17.3
* @wordpress/block-directory: 3.15.4
* @wordpress/block-editor: 10.0.4
* @wordpress/block-library: 7.14.4
* @wordpress/blocks: 11.16.4
* @wordpress/components: 21.0.4
* @wordpress/core-data: 5.0.4
* @wordpress/customize-widgets: 3.14.4
* @wordpress/data: 7.1.3
* @wordpress/data-controls: 2.17.3
* @wordpress/edit-post: 6.14.4
* @wordpress/edit-site: 4.14.5
* @wordpress/edit-widgets: 4.14.4
* @wordpress/editor: 12.16.4
* @wordpress/format-library: 3.15.4
* @wordpress/interface: 4.16.3
* @wordpress/keyboard-shortcuts: 3.15.3
* @wordpress/list-reusable-blocks: 3.15.4
* @wordpress/notices: 3.17.3
* @wordpress/nux: 5.15.4
* @wordpress/preferences: 2.9.4
* @wordpress/reusable-blocks: 3.15.4
* @wordpress/rich-text: 5.15.3
* @wordpress/server-side-render: 3.15.4
* @wordpress/style-engine: 1.0.3
* @wordpress/viewport: 4.15.3
* @wordpress/widgets: 2.15.4

References:
* [WordPress/gutenberg#44634 Gutenberg PR 44634] – Quote block: stop slash inserter popup showing in citation
* [WordPress/gutenberg#44630 Gutenberg PR 44630] – Query Loop: Fix condition for displaying 'parents' control
* [WordPress/gutenberg#44554 Gutenberg PR 44554] – Hide the Classic block in the Site Editor
* [WordPress/gutenberg#44594 Gutenberg PR 44594] – Fix navigation block console error
* [WordPress/gutenberg#44555 Gutenberg PR 44555] – Theme export: Fix broken spacingScale export
* [WordPress/gutenberg#44580 Gutenberg PR 44580] – Code Block: Add box-sizing to fix inconsistent layout
* [WordPress/gutenberg#44556 Gutenberg PR 44556] – Remove border from Global Styles previews
* [WordPress/gutenberg#44141 Gutenberg PR 44141] – Spacing presets: Modify the styling of the input controls when in unlinked mode in order to better differentiate sides
* [WordPress/gutenberg#44453 Gutenberg PR 44453] – Preserve the generic signature of getEntityRecord and getEntityRecords through currying
* [WordPress/gutenberg#44504 Gutenberg PR 44504] – Theme.json: fix some outline properties doesn't work properly on the editor
* [WordPress/gutenberg#44516 Gutenberg PR 44516] – Add style engine to editor tsconfig references
* [WordPress/gutenberg#44523 Gutenberg PR 44523] – Query Loop Block: Rename Query Loop variations allowControls to allowedControls
* [WordPress/gutenberg#44520 Gutenberg PR 44520] – Post Featured Image: Fix application of default border style in editor
* [WordPress/gutenberg#44286 Gutenberg PR 44286] – Post Featured Image: Fix borders after addition of overlay feature
* [WordPress/gutenberg#44482 Gutenberg PR 44482] – Template Editor: Fix crashes due to undefined variables
* [WordPress/gutenberg#44480 Gutenberg PR 44480] – Template Parts: Prevent adding block in post editor or inside post template or content blocks
* [WordPress/gutenberg#44425 Gutenberg PR 44425] – Fix rotated image crop area aspect ratio
* [WordPress/gutenberg#44485 Gutenberg PR 44485] – Fix padding/margin visualizer accuracy
* [WordPress/gutenberg#44569 Gutenberg PR 44569] – Theme.json: Fix some shadow properties that do not work properly in the site editor
* [WordPress/gutenberg#44575 Gutenberg PR 44575] – ToggleGroupControl: Fix unselected icon color
* [WordPress/gutenberg#44526 Gutenberg PR 44526] – TokenInput Field: Try alternative approach to fix screen reader focus issue
* [WordPress/gutenberg#44506 Gutenberg PR 44506] – Edit Post: Optimize legacy post content layout
* [WordPress/gutenberg#44258 Gutenberg PR 44258] – Add layout styles from Post Content block to post editor

Follow-up to [54257] and [54335].

Props czapla, isabel_brison, wildworks, bernhard-reiter, hellofromTonya.
See #56467.

git-svn-id: https://develop.svn.wordpress.org/trunk@54383 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Oct 4, 2022
Package updates for bug and regression fixes:

* @wordpress/annotations: 2.17.3
* @wordpress/block-directory: 3.15.4
* @wordpress/block-editor: 10.0.4
* @wordpress/block-library: 7.14.4
* @wordpress/blocks: 11.16.4
* @wordpress/components: 21.0.4
* @wordpress/core-data: 5.0.4
* @wordpress/customize-widgets: 3.14.4
* @wordpress/data: 7.1.3
* @wordpress/data-controls: 2.17.3
* @wordpress/edit-post: 6.14.4
* @wordpress/edit-site: 4.14.5
* @wordpress/edit-widgets: 4.14.4
* @wordpress/editor: 12.16.4
* @wordpress/format-library: 3.15.4
* @wordpress/interface: 4.16.3
* @wordpress/keyboard-shortcuts: 3.15.3
* @wordpress/list-reusable-blocks: 3.15.4
* @wordpress/notices: 3.17.3
* @wordpress/nux: 5.15.4
* @wordpress/preferences: 2.9.4
* @wordpress/reusable-blocks: 3.15.4
* @wordpress/rich-text: 5.15.3
* @wordpress/server-side-render: 3.15.4
* @wordpress/style-engine: 1.0.3
* @wordpress/viewport: 4.15.3
* @wordpress/widgets: 2.15.4

References:
* [WordPress/gutenberg#44634 Gutenberg PR 44634] – Quote block: stop slash inserter popup showing in citation
* [WordPress/gutenberg#44630 Gutenberg PR 44630] – Query Loop: Fix condition for displaying 'parents' control
* [WordPress/gutenberg#44554 Gutenberg PR 44554] – Hide the Classic block in the Site Editor
* [WordPress/gutenberg#44594 Gutenberg PR 44594] – Fix navigation block console error
* [WordPress/gutenberg#44555 Gutenberg PR 44555] – Theme export: Fix broken spacingScale export
* [WordPress/gutenberg#44580 Gutenberg PR 44580] – Code Block: Add box-sizing to fix inconsistent layout
* [WordPress/gutenberg#44556 Gutenberg PR 44556] – Remove border from Global Styles previews
* [WordPress/gutenberg#44141 Gutenberg PR 44141] – Spacing presets: Modify the styling of the input controls when in unlinked mode in order to better differentiate sides
* [WordPress/gutenberg#44453 Gutenberg PR 44453] – Preserve the generic signature of getEntityRecord and getEntityRecords through currying
* [WordPress/gutenberg#44504 Gutenberg PR 44504] – Theme.json: fix some outline properties doesn't work properly on the editor
* [WordPress/gutenberg#44516 Gutenberg PR 44516] – Add style engine to editor tsconfig references
* [WordPress/gutenberg#44523 Gutenberg PR 44523] – Query Loop Block: Rename Query Loop variations allowControls to allowedControls
* [WordPress/gutenberg#44520 Gutenberg PR 44520] – Post Featured Image: Fix application of default border style in editor
* [WordPress/gutenberg#44286 Gutenberg PR 44286] – Post Featured Image: Fix borders after addition of overlay feature
* [WordPress/gutenberg#44482 Gutenberg PR 44482] – Template Editor: Fix crashes due to undefined variables
* [WordPress/gutenberg#44480 Gutenberg PR 44480] – Template Parts: Prevent adding block in post editor or inside post template or content blocks
* [WordPress/gutenberg#44425 Gutenberg PR 44425] – Fix rotated image crop area aspect ratio
* [WordPress/gutenberg#44485 Gutenberg PR 44485] – Fix padding/margin visualizer accuracy
* [WordPress/gutenberg#44569 Gutenberg PR 44569] – Theme.json: Fix some shadow properties that do not work properly in the site editor
* [WordPress/gutenberg#44575 Gutenberg PR 44575] – ToggleGroupControl: Fix unselected icon color
* [WordPress/gutenberg#44526 Gutenberg PR 44526] – TokenInput Field: Try alternative approach to fix screen reader focus issue
* [WordPress/gutenberg#44506 Gutenberg PR 44506] – Edit Post: Optimize legacy post content layout
* [WordPress/gutenberg#44258 Gutenberg PR 44258] – Add layout styles from Post Content block to post editor

Follow-up to [54257] and [54335].

Props czapla, isabel_brison, wildworks, bernhard-reiter, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54383


git-svn-id: http://core.svn.wordpress.org/trunk@53942 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Oct 4, 2022
Package updates for bug and regression fixes:

* @wordpress/annotations: 2.17.3
* @wordpress/block-directory: 3.15.4
* @wordpress/block-editor: 10.0.4
* @wordpress/block-library: 7.14.4
* @wordpress/blocks: 11.16.4
* @wordpress/components: 21.0.4
* @wordpress/core-data: 5.0.4
* @wordpress/customize-widgets: 3.14.4
* @wordpress/data: 7.1.3
* @wordpress/data-controls: 2.17.3
* @wordpress/edit-post: 6.14.4
* @wordpress/edit-site: 4.14.5
* @wordpress/edit-widgets: 4.14.4
* @wordpress/editor: 12.16.4
* @wordpress/format-library: 3.15.4
* @wordpress/interface: 4.16.3
* @wordpress/keyboard-shortcuts: 3.15.3
* @wordpress/list-reusable-blocks: 3.15.4
* @wordpress/notices: 3.17.3
* @wordpress/nux: 5.15.4
* @wordpress/preferences: 2.9.4
* @wordpress/reusable-blocks: 3.15.4
* @wordpress/rich-text: 5.15.3
* @wordpress/server-side-render: 3.15.4
* @wordpress/style-engine: 1.0.3
* @wordpress/viewport: 4.15.3
* @wordpress/widgets: 2.15.4

References:
* [WordPress/gutenberg#44634 Gutenberg PR 44634] – Quote block: stop slash inserter popup showing in citation
* [WordPress/gutenberg#44630 Gutenberg PR 44630] – Query Loop: Fix condition for displaying 'parents' control
* [WordPress/gutenberg#44554 Gutenberg PR 44554] – Hide the Classic block in the Site Editor
* [WordPress/gutenberg#44594 Gutenberg PR 44594] – Fix navigation block console error
* [WordPress/gutenberg#44555 Gutenberg PR 44555] – Theme export: Fix broken spacingScale export
* [WordPress/gutenberg#44580 Gutenberg PR 44580] – Code Block: Add box-sizing to fix inconsistent layout
* [WordPress/gutenberg#44556 Gutenberg PR 44556] – Remove border from Global Styles previews
* [WordPress/gutenberg#44141 Gutenberg PR 44141] – Spacing presets: Modify the styling of the input controls when in unlinked mode in order to better differentiate sides
* [WordPress/gutenberg#44453 Gutenberg PR 44453] – Preserve the generic signature of getEntityRecord and getEntityRecords through currying
* [WordPress/gutenberg#44504 Gutenberg PR 44504] – Theme.json: fix some outline properties doesn't work properly on the editor
* [WordPress/gutenberg#44516 Gutenberg PR 44516] – Add style engine to editor tsconfig references
* [WordPress/gutenberg#44523 Gutenberg PR 44523] – Query Loop Block: Rename Query Loop variations allowControls to allowedControls
* [WordPress/gutenberg#44520 Gutenberg PR 44520] – Post Featured Image: Fix application of default border style in editor
* [WordPress/gutenberg#44286 Gutenberg PR 44286] – Post Featured Image: Fix borders after addition of overlay feature
* [WordPress/gutenberg#44482 Gutenberg PR 44482] – Template Editor: Fix crashes due to undefined variables
* [WordPress/gutenberg#44480 Gutenberg PR 44480] – Template Parts: Prevent adding block in post editor or inside post template or content blocks
* [WordPress/gutenberg#44425 Gutenberg PR 44425] – Fix rotated image crop area aspect ratio
* [WordPress/gutenberg#44485 Gutenberg PR 44485] – Fix padding/margin visualizer accuracy
* [WordPress/gutenberg#44569 Gutenberg PR 44569] – Theme.json: Fix some shadow properties that do not work properly in the site editor
* [WordPress/gutenberg#44575 Gutenberg PR 44575] – ToggleGroupControl: Fix unselected icon color
* [WordPress/gutenberg#44526 Gutenberg PR 44526] – TokenInput Field: Try alternative approach to fix screen reader focus issue
* [WordPress/gutenberg#44506 Gutenberg PR 44506] – Edit Post: Optimize legacy post content layout
* [WordPress/gutenberg#44258 Gutenberg PR 44258] – Add layout styles from Post Content block to post editor

Follow-up to [54257] and [54335].

Props czapla, isabel_brison, wildworks, bernhard-reiter, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54383


git-svn-id: https://core.svn.wordpress.org/trunk@53942 1a063a9b-81f0-0310-95a4-ce76da25c4cd
// if not, this must be a classic theme, in which case we use the fallback layout.
const blockListLayout = postContentBlock
? postContentLayout
: fallbackLayout;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi there! I stumbled on this code while doing some performance debugging. While right now, it's not clear to me that this code (I mean all the figuring out of the layout) is introducing performance regression (specially loading) but I noticed that the value of the layout changes three times for a regular post loaded in the post editor.

Screen Shot 2022-10-24 at 11 08 48 PM

  • A few things stand out to me here. Can we just compute the right layout only once to avoid unnecessary re-renders?
  • Why does the layout object contains this "definitions" key? Seems weird? (probably unrelated to this PR but maybe you have an idea)
  • Also the logic here is over-complexifying this component. Is there a possibility of some kind of cleanup like a dedicated hook useBlockEditorLayout or something (I have no idea, just wild suggesting)?

Thanks

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 don't have access to the post template straightaway on load, so we need to do a little checking to see when it becomes available. But we should probably be checking whether postContentBlock is an empty object rather than just checking whether it exists, as then blockListLayout would only change once.

The definitions object appeared in #40875; it's where we store base styles for each layout type. When we get the layout settings with useSetting the definitions will always be included.

Is there a possibility of some kind of cleanup like a dedicated hook useBlockEditorLayout or something

That's a good point, I can't say offhand but it's worth looking into!

Copy link
Contributor

Choose a reason for hiding this comment

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

The definitions object appeared in #40875; it's where we store base styles for each layout type. When we get the layout settings with useSetting the definitions will always be included.

What's seems not correct here is that the "definition" are included in the "default layout" object. I'm fine having "definitions" but I don't they should be part of the default layout object.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably be checking whether postContentBlock is an empty object rather than just checking whether it exists, as then blockListLayout would only change once.

Yeah, is there a way to have no changes at all, this is to avoid rendering anything if the correct layout object is not available yet. As I guess otherwise, we'd just be doing unnecessary computation and potentially causing layout shifts in the UI.

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'm fine having "definitions" but I don't they should be part of the default layout object.

I'm not sure I understand. The default layout type has default styles too, so we need to access those definitions sometimes. Do you mean we shouldn't be returning the definitions from useSetting( 'layout' ) or am I missing your point altogether? 😅

Yeah, is there a way to have no changes at all, this is to avoid rendering anything if the correct layout object is not available yet. As I guess otherwise, we'd just be doing unnecessary computation and potentially causing layout shifts in the UI.

Yeah, there will be a layout shift if the layout is anything other than center-aligned and constrained to default theme width. The problem is, if we wait for the post template data to be available before rendering the post content, users will be looking at a white screen for a little bit, which seems to me a worse experience than the layout shift. Unless we can find a faster way to access the Post Content block layout? The thing is we need the Post Content block from the specific template being used with the post, because it might have custom settings. It's not enough to get the data from global styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking through this a bit, also in light of #45262, would it be terrible to get the Post Content layout and add it to the block editor settings here? I haven't tried it out yet but happy to do so as I think we're going to need a solution that renders the correct layout for all types of users, not just the ones with the right permissions 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in general we're trying to move away from server-side provided settings in order to make the editor more portable (outside wordpress, other contexts...) but in this case, I wouldn't mind it. The original idea of the "layout" properly in theme.json was to avoid this problem exactly: the layout in theme.json would always correspond (as a convention) to the post content block one and we'd avoid any complex computations. (statically defined)

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 the context! Yeah, the issue is precisely that folks wanted to customize the Post Content layout, and with features such as #44065 it makes sense for the post editor to reflect whatever layout is set.

ootwch pushed a commit to ootwch/wordpress-develop that referenced this pull request Nov 4, 2022
Package updates for bug and regression fixes:

* @wordpress/annotations: 2.17.3
* @wordpress/block-directory: 3.15.4
* @wordpress/block-editor: 10.0.4
* @wordpress/block-library: 7.14.4
* @wordpress/blocks: 11.16.4
* @wordpress/components: 21.0.4
* @wordpress/core-data: 5.0.4
* @wordpress/customize-widgets: 3.14.4
* @wordpress/data: 7.1.3
* @wordpress/data-controls: 2.17.3
* @wordpress/edit-post: 6.14.4
* @wordpress/edit-site: 4.14.5
* @wordpress/edit-widgets: 4.14.4
* @wordpress/editor: 12.16.4
* @wordpress/format-library: 3.15.4
* @wordpress/interface: 4.16.3
* @wordpress/keyboard-shortcuts: 3.15.3
* @wordpress/list-reusable-blocks: 3.15.4
* @wordpress/notices: 3.17.3
* @wordpress/nux: 5.15.4
* @wordpress/preferences: 2.9.4
* @wordpress/reusable-blocks: 3.15.4
* @wordpress/rich-text: 5.15.3
* @wordpress/server-side-render: 3.15.4
* @wordpress/style-engine: 1.0.3
* @wordpress/viewport: 4.15.3
* @wordpress/widgets: 2.15.4

References:
* [WordPress/gutenberg#44634 Gutenberg PR 44634] – Quote block: stop slash inserter popup showing in citation
* [WordPress/gutenberg#44630 Gutenberg PR 44630] – Query Loop: Fix condition for displaying 'parents' control
* [WordPress/gutenberg#44554 Gutenberg PR 44554] – Hide the Classic block in the Site Editor
* [WordPress/gutenberg#44594 Gutenberg PR 44594] – Fix navigation block console error
* [WordPress/gutenberg#44555 Gutenberg PR 44555] – Theme export: Fix broken spacingScale export
* [WordPress/gutenberg#44580 Gutenberg PR 44580] – Code Block: Add box-sizing to fix inconsistent layout
* [WordPress/gutenberg#44556 Gutenberg PR 44556] – Remove border from Global Styles previews
* [WordPress/gutenberg#44141 Gutenberg PR 44141] – Spacing presets: Modify the styling of the input controls when in unlinked mode in order to better differentiate sides
* [WordPress/gutenberg#44453 Gutenberg PR 44453] – Preserve the generic signature of getEntityRecord and getEntityRecords through currying
* [WordPress/gutenberg#44504 Gutenberg PR 44504] – Theme.json: fix some outline properties doesn't work properly on the editor
* [WordPress/gutenberg#44516 Gutenberg PR 44516] – Add style engine to editor tsconfig references
* [WordPress/gutenberg#44523 Gutenberg PR 44523] – Query Loop Block: Rename Query Loop variations allowControls to allowedControls
* [WordPress/gutenberg#44520 Gutenberg PR 44520] – Post Featured Image: Fix application of default border style in editor
* [WordPress/gutenberg#44286 Gutenberg PR 44286] – Post Featured Image: Fix borders after addition of overlay feature
* [WordPress/gutenberg#44482 Gutenberg PR 44482] – Template Editor: Fix crashes due to undefined variables
* [WordPress/gutenberg#44480 Gutenberg PR 44480] – Template Parts: Prevent adding block in post editor or inside post template or content blocks
* [WordPress/gutenberg#44425 Gutenberg PR 44425] – Fix rotated image crop area aspect ratio
* [WordPress/gutenberg#44485 Gutenberg PR 44485] – Fix padding/margin visualizer accuracy
* [WordPress/gutenberg#44569 Gutenberg PR 44569] – Theme.json: Fix some shadow properties that do not work properly in the site editor
* [WordPress/gutenberg#44575 Gutenberg PR 44575] – ToggleGroupControl: Fix unselected icon color
* [WordPress/gutenberg#44526 Gutenberg PR 44526] – TokenInput Field: Try alternative approach to fix screen reader focus issue
* [WordPress/gutenberg#44506 Gutenberg PR 44506] – Edit Post: Optimize legacy post content layout
* [WordPress/gutenberg#44258 Gutenberg PR 44258] – Add layout styles from Post Content block to post editor

Follow-up to [54257] and [54335].

Props czapla, isabel_brison, wildworks, bernhard-reiter, hellofromTonya.
See #56467.

git-svn-id: https://develop.svn.wordpress.org/trunk@54383 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Content Affects the Post Content Block [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. [Package] Edit Post /packages/edit-post [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wide/full alignment controls always show in post editor even if Post Content block has no content width
6 participants