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

Patterns: Add wrapper to synced patterns and adopt widest alignment of children #54289

Closed
wants to merge 13 commits into from

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Sep 8, 2023

Fixes:

Related:

What?

  • Adds a wrapping element to synced patterns on the front end to match the editor.
  • Adopts full alignment for the pattern, if any of its immediate children have wide/full alignments, to preserve visual appearance

Why?

It's important to provide a smooth editing experience around patterns. Creating a pattern from wide, full, left, or right-aligned blocks, only to see them move and get squashed into a pattern block wrapper in the editor is unexpected.

How?

  • Adopts layout support on the pattern block (core/block)
  • Leverages a pre_render_block filter to short circuit block rendering when an old pattern doesn't have a wrapper so that layout support styles aren't injected into the first child of the pattern incorrectly
  • Now saves a block wrapper element to post content. This is used to distinguish between existing pattern instances that shouldn't have the wrapper added on the frontend and new blocks
  • Deprecation added to migrate pattern instances and prevent block invalidation
  • The pattern block's edit component infers its alignment from its children and adds the appropriate CSS class to its markup
  • The render block callback for the pattern block now temporarily adds a new render_block_data filter to determine the widest alignment of its immediate children while they are processed via do_blocks
  • The WP_HTML_Tag_Processor is used to wrap the pattern's entity content with the wrapping element and apply the alignment

Notes

It was raised in #54170 (comment) whether we could move the logic to detect the widest alignment to the point where we create the pattern.

From my explorations, it doesn't look like that or solely relying on updating the pattern's edit component will work. There is a use case where the pattern is created via the block editor and then later edited directly in the wp_block post type editor.

An alternative to the filter approach I've taken here might be to save the alignment to the entity's post meta. I opted against this, as we're already parsing the blocks for the pattern via do_blocks in its render callback, so the filters seemed more straightforward for the moment.

Testing Instructions

Backwards Compatibility

  1. On trunk, create a synced pattern via the post editor with at least one block with a wide alignment
  2. Save the post and inspect on the frontend to confirm no wrapper is applied to the pattern
  3. Switch to this PR branch
  4. Refresh the frontend page and confirm there is still no wrapper around the pattern content

Wrapped Patterns

  1. Edit a post, add a series of blocks with varying alignments
  2. Select the blocks and via the block toolbar more menu, choose to create a pattern
  3. The layout of the blocks should be maintained
  4. Save the post and view on the frontend checking that is consistent
  5. Repeat the process where the pattern's immediate children have alignment of wide, full, left, or right
  6. Within a pattern that has any of the alignments from the previous step, remove all such alignments from the pattern's immediate child blocks, then confirm you still have the option to reapply any wide, full, left, or right alignment.

Screenshots or screencast

Screen.Recording.2023-09-08.at.7.16.04.pm.mp4

@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Sep 8, 2023
@aaronrobertshaw aaronrobertshaw self-assigned this Sep 8, 2023
@aaronrobertshaw
Copy link
Contributor Author

This isn't quite ready for a proper review yet, I've run out of time but will pick it back up Monday.

@github-actions
Copy link

github-actions bot commented Sep 8, 2023

Size Change: +1.69 kB (0%)

Total Size: 1.52 MB

Filename Size Change
build/block-editor/index.min.js 216 kB +68 B (0%)
build/block-editor/style-rtl.css 15.1 kB -229 B (-1%)
build/block-editor/style.css 15 kB -227 B (-1%)
build/block-library/blocks/query/view.min.js 555 B -4 B (-1%)
build/block-library/index.min.js 204 kB +187 B (0%)
build/components/index.min.js 255 kB -215 B (0%)
build/core-data/index.min.js 16.8 kB +35 B (0%)
build/edit-post/index.min.js 35.5 kB +66 B (0%)
build/edit-post/style-rtl.css 7.84 kB +195 B (+3%)
build/edit-post/style.css 7.83 kB +192 B (+3%)
build/edit-site/index.min.js 91.8 kB +653 B (+1%)
build/edit-site/style-rtl.css 13.5 kB +247 B (+2%)
build/edit-site/style.css 13.5 kB +255 B (+2%)
build/edit-widgets/index.min.js 16.9 kB +25 B (0%)
build/edit-widgets/style-rtl.css 4.8 kB +223 B (+5%) 🔍
build/edit-widgets/style.css 4.79 kB +217 B (+5%) 🔍
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.69 kB
build/api-fetch/index.min.js 2.28 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 451 B
build/block-directory/index.min.js 7.01 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/content-rtl.css 4.25 kB
build/block-editor/content.css 4.24 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 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 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 104 B
build/block-library/blocks/avatar/style.css 104 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 584 B
build/block-library/blocks/button/editor.css 582 B
build/block-library/blocks/button/style-rtl.css 629 B
build/block-library/blocks/button/style.css 628 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 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 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 421 B
build/block-library/blocks/columns/style.css 421 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 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.69 kB
build/block-library/blocks/cover/style.css 1.68 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 311 B
build/block-library/blocks/file/style.css 312 B
build/block-library/blocks/file/view.min.js 318 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 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 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 1.42 kB
build/block-library/blocks/image/style.css 1.41 kB
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/image/view-interactivity.min.js 1.83 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 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 505 B
build/block-library/blocks/media-text/style.css 503 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 668 B
build/block-library/blocks/navigation-link/editor.css 669 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/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.23 kB
build/block-library/blocks/navigation/style.css 2.22 kB
build/block-library/blocks/navigation/view.min.js 984 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 401 B
build/block-library/blocks/page-list/editor.css 401 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 235 B
build/block-library/blocks/paragraph/editor.css 235 B
build/block-library/blocks/paragraph/style-rtl.css 335 B
build/block-library/blocks/paragraph/style.css 335 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 508 B
build/block-library/blocks/post-comments-form/style.css 508 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 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 319 B
build/block-library/blocks/post-featured-image/style.css 319 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 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 314 B
build/block-library/blocks/post-template/style.css 314 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-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 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 125 B
build/block-library/blocks/preformatted/style.css 125 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 335 B
build/block-library/blocks/pullquote/style.css 335 B
build/block-library/blocks/pullquote/theme-rtl.css 168 B
build/block-library/blocks/pullquote/theme.css 168 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 302 B
build/block-library/blocks/query-pagination/style.css 299 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 450 B
build/block-library/blocks/query/editor.css 449 B
build/block-library/blocks/query/style-rtl.css 370 B
build/block-library/blocks/query/style.css 368 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 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 178 B
build/block-library/blocks/search/editor.css 178 B
build/block-library/blocks/search/style-rtl.css 607 B
build/block-library/blocks/search/style.css 607 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 468 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 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 204 B
build/block-library/blocks/site-logo/style.css 204 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 682 B
build/block-library/blocks/social-links/editor.css 681 B
build/block-library/blocks/social-links/style-rtl.css 1.44 kB
build/block-library/blocks/social-links/style.css 1.43 kB
build/block-library/blocks/spacer/editor-rtl.css 348 B
build/block-library/blocks/spacer/editor.css 348 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 432 B
build/block-library/blocks/table/editor.css 432 B
build/block-library/blocks/table/style-rtl.css 639 B
build/block-library/blocks/table/style.css 639 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 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 403 B
build/block-library/blocks/template-part/editor.css 403 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/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 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/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 185 B
build/block-library/blocks/video/style.css 185 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 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.1 kB
build/block-library/editor.css 12.1 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/style-rtl.css 13.9 kB
build/block-library/style.css 13.9 kB
build/block-library/theme-rtl.css 688 B
build/block-library/theme.css 693 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51.4 kB
build/commands/index.min.js 15.5 kB
build/commands/style-rtl.css 921 B
build/commands/style.css 918 B
build/components/style-rtl.css 11.7 kB
build/components/style.css 11.7 kB
build/compose/index.min.js 12.1 kB
build/core-commands/index.min.js 2.6 kB
build/customize-widgets/index.min.js 12 kB
build/customize-widgets/style-rtl.css 1.48 kB
build/customize-widgets/style.css 1.48 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 8.84 kB
build/date/index.min.js 17.8 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.64 kB
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/editor/index.min.js 45.5 kB
build/editor/style-rtl.css 3.53 kB
build/editor/style.css 3.52 kB
build/element/index.min.js 4.82 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.71 kB
build/format-library/style-rtl.css 554 B
build/format-library/style.css 553 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/index.min.js 11.3 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.87 kB
build/list-reusable-blocks/index.min.js 2.2 kB
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 1.99 kB
build/nux/style-rtl.css 735 B
build/nux/style.css 732 B
build/patterns/index.min.js 2.7 kB
build/patterns/style-rtl.css 240 B
build/patterns/style.css 240 B
build/plugins/index.min.js 1.79 kB
build/preferences-persistence/index.min.js 1.84 kB
build/preferences/index.min.js 1.24 kB
build/primitives/index.min.js 943 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 958 B
build/react-i18n/index.min.js 615 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.7 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 10.2 kB
build/router/index.min.js 1.78 kB
build/server-side-render/index.min.js 1.94 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 1.97 kB
build/sync/index.min.js 53.8 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.73 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 958 B
build/warning/index.min.js 249 B
build/widgets/index.min.js 7.16 kB
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@github-actions
Copy link

github-actions bot commented Sep 8, 2023

Flaky tests detected in e3af74e.
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/6154972354
📝 Reported issues:

@richtabor
Copy link
Member

Gave it an early look; feels promising :)

Before

CleanShot.2023-09-08.at.20.32.13.mp4

After

CleanShot.2023-09-08.at.20.31.10.mp4

@aaronrobertshaw aaronrobertshaw marked this pull request as ready for review September 12, 2023 03:08
@aaronrobertshaw aaronrobertshaw changed the title [WIP] Patterns: Add wrapper to synced patterns and adopt widest alignment of children Patterns: Add wrapper to synced patterns and adopt widest alignment of children Sep 12, 2023
@aaronrobertshaw
Copy link
Contributor Author

Most of the layout/alignment quirks have been ironed out I think. So now might be a good time to get a general sanity check on the approach and if there are any obvious issues.

I'll sort out the failing pattern tests shortly.

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 testing very nicely for me:

✅ Existing unaltered patterns appear to still render correctly without a wrapper introduced on the site frontend, so a pattern inserted into a Row block still renders correctly, for example
✅ Block markup is updated as expected in the editor when making a change
✅ Alignment controls can be adjusted within the editor within the pattern, and setting to None still allows you to set back to Wide / Full

Just left a couple of tiny questions, but overall the direction seems promising to me, and I didn't run into any issues with it!

I see that the tests for the mobile app had to be updated — will this change cause any issues for older versions of the mobile app accessing newer updated markup?

Edit: as discussed separately this PR still has the issue of layout support classnames being injected into the markup when no wrapper is in use. E.g. for legacy markup in a synced pattern that begins with a heading block, layout classnames get injected into that heading block when they shouldn't be:

image

packages/block-library/src/block/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/block/index.php Show resolved Hide resolved
aaronrobertshaw and others added 2 commits September 12, 2023 17:41
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
@aaronrobertshaw
Copy link
Contributor Author

Thanks for the review, testing, and discussion on this one @andrewserong! It has definitely proven a little tricky to iron out all the edge cases.

I see that the tests for the mobile app had to be updated — will this change cause any issues for older versions of the mobile app accessing newer updated markup?

That's a good question and one that I need to find the answer to. Unfortunately, I went down a rabbit hole on the other issue you noted and have run out of time today. I'll follow-up on this tomorrow.

as discussed separately this PR still has the issue of layout support classnames being injected into the markup when no wrapper is in use. E.g. for legacy markup in a synced pattern that begins with a heading block, layout classnames get injected into that heading block when they shouldn't be:

I believe I have something that addresses this issue. In d598873, I've added a pre_render_block filter that will short-circuit rendering the pattern block when it doesn't have the saved wrapper. This short-circuiting means the block never gets to the render_block filter for the layout supports and as such we don't get the layout styles injected into the first of the pattern's inner blocks.

As the core/block type only opts into layout support as of this PR, I don't think we are missing anything. The normal render_callback is still in place so the block should also retain its "dynamic" status.

One question/concern I have with this latest approach is whether it is acceptable that any render_block filters applied by third parties to this block would now also be skipped for old pattern instances without a wrapper. Perhaps a dev note would suffice?

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 like the pre_render_block filter approach @aaronrobertshaw, that seems the neatest so far while maintaining behaviour in the two different states of the block, without introducing a new API for this one block's requirements.

It's testing nicely for me, with layout block support no longer being applied to legacy markup 👍

One question/concern I have with this latest approach is whether it is acceptable that any render_block filters applied by third parties to this block would now also be skipped for old pattern instances without a wrapper. Perhaps a dev note would suffice?

From my perspective, I think of the core/block as being kind of a special kind of block — it uses the block API, but isn't really a block that's intended for styling over overriding in a typical way, so short-circuiting for this use case feels appropriate to me. A dev note sounds like a good idea.

That said, I don't have a full understanding of what the potential implications might be, so it'd be well worth getting more folks' perspectives on this one.

To me, though, this seems like a very promising direction and looks good to me!

packages/block-library/src/block/index.php Outdated Show resolved Hide resolved
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Just gave this a quick round of testing before looking through the code in depth. A couple of things:

  • Is it intended that any change to a template that has an existing pattern in it will cause a wrapper to go around that pattern? This is a bit unexpected.
  • I don't think we want to always apply constrained layout to the wrapper. For instance, if I add a Row to a template (not a post) at root level it's full width by default. Say I add a Site Title and a Navigation to it and set the Row to space between, so now I have a block at each end of the row, which is a pretty common header/footer pattern. If I create a pattern from that Row, its contents jump into the middle of the page. Not only is the Row not full width any longer, I am unable to set it to it full width because the pattern wrapper doesn't support alignments for its children. To make things worse, this is not an editor-only problem: the same happens on the front end.

I'm sorry I don't have any ready solutions for these problems. My feeling is that it might be better to avoid making changes to the front end for something that is purely an editor view problem, but I'm also very aware of the extensive discussions around this issue and the fact that so far, no good solution has been found 😬

@tellthemachines
Copy link
Contributor

I just remembered I had a thought when looking at Glen's PR: would the skipping serialization route mentioned in that comment be viable at all? We'd probably still need to set layout dynamically depending on the block context but at least we wouldn't have to change anything on the front end

@aaronrobertshaw
Copy link
Contributor Author

Thanks @andrewserong and @tellthemachines for taking this for a spin.

Is it intended that any change to a template that has an existing pattern in it will cause a wrapper to go around that pattern? This is a bit unexpected.

I'm open to ideas to avoid it if you have any.

I don't think we want to always apply constrained layout to the wrapper.

Can you provide a video or some example block markup?

would the skipping serialization route mentioned in that comment be viable at all?

We would need to conditionally skip serialization and only on the frontend, which would not match other block supports. Could it be done yes but only in just as hacky a way as anything proposed here. Implementing that whole new API for only this special case doesn't seem ideal.

but at least we wouldn't have to change anything on the front end

The desire is to change things on the frontend though as suggested on the original PR. So we are moving towards a consistent display between both front and backends.

@aaronrobertshaw
Copy link
Contributor Author

@youknowriad if you have the time, I'd love to get your thoughts on this PR or whether we should pivot back to pushing #54170 across the line with some of the lesson's and fixes learnt through exploring this approach.

Trying to force a wrapper for only new pattern instances on the frontend while maintaining layout is proving rather difficult. Short of creating a core/block-v2 things seem to be getting hackier and hackier, which was why we shelved #54170 in the first place.

Would you be open to revisiting the earlier approach that does not introduce a wrapper on the frontend, as an interim step? This would provide a smoother pattern creation experience in the editor and buy us time to find a clean solution to introducing the frontend wrapper.

I'm conscious of the fact we need to sort out the pattern editing experience for 6.4 and are running out of time. If there is a better option we can do in a few days, I'm open to new ideas.

@youknowriad
Copy link
Contributor

youknowriad commented Sep 13, 2023

First, I don't think 6.4 pressure should force us to make any quick decision that we might regret later, this issue for reusable blocks have been around for a long time and one release more or less is not going to change a lot. So let's make sure we make the right decision here regardless of any deadline.

1- #54170 is not that impactful (aside some hacks in the editor), If I'm not wrong it has no impact on the frontend and just "tries" to set the right width of the reusable block wrapper properly. So if we want to merge it, let's make sure that we can revert it without issues/breaking changes... That said, it's very hacky and a bit incomplete. Here are some flows where it fails:
- I create a reusable block with two blocks (wide and normal), then I change one of the block's width to "full", the reusable block doesn't update its width in this case, it keeps the old "wide" value.
- What happens when the "layout" definition of the parent of the reusable block changes. Say, we remove the wide width or change the widths. I believe the reusable block will keep the old layout and not reflect that in its children.
- What happens if the layout type changes (say from "flow" to "flex")
- Did we address the use-case (less common) where we use "justify-self" on the children of "flex" layouts. There maybe another logic to apply there than just copying the layout from parent to reusable block.

2- Maybe we should create a core/block-2? It obviously requires a lot of thinking, but if we think it's the right solution, why not go for it?

@aaronrobertshaw
Copy link
Contributor Author

Thank you for the feedback @youknowriad 🙇

First, I don't think 6.4 pressure should force us to make any quick decision that we might regret later

No arguments here!

#54170 is not that impactful (aside some hacks in the editor)

That is correct.

There were a number of use cases it didn't factor in, that were addressed in this PR. I have created a new PR (#54416) to apply some of these fixes back onto #54170

Among others, these include:

  • Allowing temporary removal of alignments, and not updating the pattern block's layout so alignments can be reapplied
  • Adopting the parent layout when the pattern block requires a layout
  • Covering left/right alignments etc. Now the pattern block will apply the parent layout if it is constrained and the pattern's inner blocks are any of full, wide, left, or right.

So if we want to merge it, let's make sure that we can revert it without issues/breaking changes

Using the simple filter to add editor-only layout support and the hook to infer alignment and layout in the block's edit component, is about as low impact as we can make it. Nothing is being persisted with this approach, so reverting it would only bring back the current issue where the pattern contents appear to be constrained when they shouldn't be.

That visual regression can be mitigated if it's done while applying whatever long-term fix we settle on.

After several long discussions with @glendaviesnz, @tellthemachines, and @andrewserong, my preference would be to proceed with #54170 once the fixes from #54416 and any others required have been applied.

That improves the editing experience around patterns and buys us time to think through the best long term option, including whether that is a v2 of the core/block.

That said, it's very hacky and a bit incomplete. Here are some flows where it fails

I'll give #54416 some further testing tomorrow, working through the flows identified.

Very much appreciate the advice shared, thank you 👍

@youknowriad
Copy link
Contributor

Ok sounds good to me. Thanks for considering the alternative, I appreciate it. It does make sense to try the non-impactful approach first. I left a small comment here #54416 (comment) that could improve things too.

@aaronrobertshaw
Copy link
Contributor Author

Closing this PR in favour of #54416 and #54170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants