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

Properly apply styles and classes to the experimental form block #55755

Open
wants to merge 21 commits into
base: trunk
Choose a base branch
from

Conversation

aristath
Copy link
Member

@aristath aristath commented Nov 1, 2023

What?

Properly applies styles and classes to the experimental form block. In #44214 (comment) it shows that styles don't get properly applied to the core/form block. This PR fixes that issue.

Why?

Because it's a bug - or rather something that wasn't properly implemented in the initial PR introducing the experiment.

How?

  • Removes the default style and classes attributes from the <form> element, and then adds them using get_block_wrapper_attributes().

Testing Instructions

  • Enable the forms-blocks experiment, create a post and add a form in there.
  • Change the background colors, padding, margin, typography... whatever you want.
  • Save the post and visit it on the front (in the editor it was working properly, but not when viewing the post)
  • Confirm that your styles were properly applied.

Testing Instructions for Keyboard

Not applicable

@aristath aristath added [Type] Bug An existing feature does not function as intended [Block] Form (experimental) Affects the form block labels Nov 1, 2023
Copy link

github-actions bot commented Nov 1, 2023

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

Copy link
Contributor

@carolinan carolinan 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 an improvement. The style-related class names are now added to the <form tag. Spacing, color, and typography settings work on the front.
The way the attributes are removed is unconventional but it is working.
I can see that the order of the style and class attributes is not the same as in other blocks. On the front, the style is before the class. This is unexpected but I am not sure it matters.

In the editor, the typography > font family setting is not working, hence the request for changes.
When I change the font family setting, the inner blocks still use the body font family
(The font family is correct on the front).

@aristath
Copy link
Member Author

aristath commented Nov 2, 2023

Thank you for the thorough check @carolinan!
I pushed an additional commit, fixing the issue 👍

Copy link

github-actions bot commented Nov 2, 2023

Size Change: +93 B (+0.01%)

Total Size: 1.75 MB

Filename Size Change
build/block-editor/index.min.js 259 kB +34 B (+0.01%)
build/block-library/index.min.js 218 kB +85 B (+0.04%)
build/editor/index.min.js 91.3 kB -26 B (-0.03%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.27 kB
build/api-fetch/index.min.js 2.32 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 578 B
build/block-directory/index.min.js 7.26 kB
build/block-directory/style-rtl.css 1.03 kB
build/block-directory/style.css 1.03 kB
build/block-editor/content-rtl.css 4.57 kB
build/block-editor/content.css 4.57 kB
build/block-editor/default-editor-styles-rtl.css 395 B
build/block-editor/default-editor-styles.css 395 B
build/block-editor/style-rtl.css 15.5 kB
build/block-editor/style.css 15.5 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 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 133 B
build/block-library/blocks/audio/theme.css 133 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 277 B
build/block-library/blocks/block/editor.css 277 B
build/block-library/blocks/button/editor-rtl.css 415 B
build/block-library/blocks/button/editor.css 414 B
build/block-library/blocks/button/style-rtl.css 627 B
build/block-library/blocks/button/style.css 626 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 671 B
build/block-library/blocks/cover/editor.css 674 B
build/block-library/blocks/cover/style-rtl.css 1.7 kB
build/block-library/blocks/cover/style.css 1.69 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 86 B
build/block-library/blocks/details/style.css 86 B
build/block-library/blocks/embed/editor-rtl.css 312 B
build/block-library/blocks/embed/editor.css 312 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 133 B
build/block-library/blocks/embed/theme.css 133 B
build/block-library/blocks/file/editor-rtl.css 326 B
build/block-library/blocks/file/editor.css 327 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view.min.js 324 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/form-input/editor-rtl.css 227 B
build/block-library/blocks/form-input/editor.css 227 B
build/block-library/blocks/form-input/style-rtl.css 343 B
build/block-library/blocks/form-input/style.css 343 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 340 B
build/block-library/blocks/form-submission-notification/editor.css 340 B
build/block-library/blocks/form-submit-button/style-rtl.css 69 B
build/block-library/blocks/form-submit-button/style.css 69 B
build/block-library/blocks/form/view.min.js 471 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 956 B
build/block-library/blocks/gallery/editor.css 960 B
build/block-library/blocks/gallery/style-rtl.css 1.72 kB
build/block-library/blocks/gallery/style.css 1.72 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 403 B
build/block-library/blocks/group/editor.css 403 B
build/block-library/blocks/group/style-rtl.css 103 B
build/block-library/blocks/group/style.css 103 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 189 B
build/block-library/blocks/heading/style.css 189 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 891 B
build/block-library/blocks/image/editor.css 891 B
build/block-library/blocks/image/style-rtl.css 1.6 kB
build/block-library/blocks/image/style.css 1.59 kB
build/block-library/blocks/image/theme-rtl.css 133 B
build/block-library/blocks/image/theme.css 133 B
build/block-library/blocks/image/view.min.js 1.54 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 494 B
build/block-library/blocks/latest-posts/style.css 494 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 306 B
build/block-library/blocks/media-text/editor.css 305 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 193 B
build/block-library/blocks/navigation-link/style.css 192 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.26 kB
build/block-library/blocks/navigation/style.css 2.25 kB
build/block-library/blocks/navigation/view.min.js 1.03 kB
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 377 B
build/block-library/blocks/page-list/editor.css 377 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-content/editor-rtl.css 74 B
build/block-library/blocks/post-content/editor.css 74 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 734 B
build/block-library/blocks/post-featured-image/editor.css 732 B
build/block-library/blocks/post-featured-image/style-rtl.css 342 B
build/block-library/blocks/post-featured-image/style.css 342 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 397 B
build/block-library/blocks/post-template/style.css 396 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 354 B
build/block-library/blocks/pullquote/style.css 353 B
build/block-library/blocks/pullquote/theme-rtl.css 174 B
build/block-library/blocks/pullquote/theme.css 174 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 486 B
build/block-library/blocks/query/editor.css 486 B
build/block-library/blocks/query/view.min.js 958 B
build/block-library/blocks/quote/style-rtl.css 237 B
build/block-library/blocks/quote/style.css 237 B
build/block-library/blocks/quote/theme-rtl.css 233 B
build/block-library/blocks/quote/theme.css 235 B
build/block-library/blocks/read-more/style-rtl.css 140 B
build/block-library/blocks/read-more/style.css 140 B
build/block-library/blocks/rss/editor-rtl.css 101 B
build/block-library/blocks/rss/editor.css 101 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 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 690 B
build/block-library/blocks/search/style.css 689 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 478 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 239 B
build/block-library/blocks/separator/style.css 239 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 286 B
build/block-library/blocks/shortcode/editor.css 286 B
build/block-library/blocks/site-logo/editor-rtl.css 805 B
build/block-library/blocks/site-logo/editor.css 805 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 324 B
build/block-library/blocks/social-link/editor.css 324 B
build/block-library/blocks/social-links/editor-rtl.css 676 B
build/block-library/blocks/social-links/editor.css 675 B
build/block-library/blocks/social-links/style-rtl.css 1.5 kB
build/block-library/blocks/social-links/style.css 1.5 kB
build/block-library/blocks/spacer/editor-rtl.css 350 B
build/block-library/blocks/spacer/editor.css 350 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 395 B
build/block-library/blocks/table/editor.css 395 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 152 B
build/block-library/blocks/table/theme.css 152 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 393 B
build/block-library/blocks/template-part/editor.css 393 B
build/block-library/blocks/template-part/theme-rtl.css 107 B
build/block-library/blocks/template-part/theme.css 107 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 133 B
build/block-library/blocks/video/theme.css 133 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.11 kB
build/block-library/common.css 1.11 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.2 kB
build/block-library/editor.css 12.2 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 14.8 kB
build/block-library/style.css 14.8 kB
build/block-library/theme-rtl.css 707 B
build/block-library/theme.css 713 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.7 kB
build/commands/index.min.js 15.1 kB
build/commands/style-rtl.css 953 B
build/commands/style.css 951 B
build/components/index.min.js 222 kB
build/components/style-rtl.css 12 kB
build/components/style.css 12 kB
build/compose/index.min.js 12.8 kB
build/core-commands/index.min.js 2.73 kB
build/core-data/index.min.js 72.5 kB
build/customize-widgets/index.min.js 10.9 kB
build/customize-widgets/style-rtl.css 1.36 kB
build/customize-widgets/style.css 1.36 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 9 kB
build/date/index.min.js 17.9 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.65 kB
build/edit-post/classic-rtl.css 578 B
build/edit-post/classic.css 578 B
build/edit-post/index.min.js 14.6 kB
build/edit-post/style-rtl.css 2.68 kB
build/edit-post/style.css 2.68 kB
build/edit-site/index.min.js 219 kB
build/edit-site/style-rtl.css 12.8 kB
build/edit-site/style.css 12.8 kB
build/edit-widgets/index.min.js 17.5 kB
build/edit-widgets/style-rtl.css 4.18 kB
build/edit-widgets/style.css 4.18 kB
build/editor/style-rtl.css 8.39 kB
build/editor/style.css 8.4 kB
build/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 8.07 kB
build/format-library/style-rtl.css 493 B
build/format-library/style.css 492 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/debug.min.js 16.4 kB
build/interactivity/file.min.js 447 B
build/interactivity/image.min.js 1.67 kB
build/interactivity/index.min.js 13.2 kB
build/interactivity/navigation.min.js 1.17 kB
build/interactivity/query.min.js 740 B
build/interactivity/router.min.js 2.81 kB
build/interactivity/search.min.js 618 B
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.3 kB
build/keycodes/index.min.js 1.46 kB
build/list-reusable-blocks/index.min.js 2.11 kB
build/list-reusable-blocks/style-rtl.css 851 B
build/list-reusable-blocks/style.css 851 B
build/media-utils/index.min.js 2.92 kB
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 1.57 kB
build/nux/style-rtl.css 748 B
build/nux/style.css 744 B
build/patterns/index.min.js 6.46 kB
build/patterns/style-rtl.css 595 B
build/patterns/style.css 595 B
build/plugins/index.min.js 1.8 kB
build/preferences-persistence/index.min.js 2.06 kB
build/preferences/index.min.js 2.85 kB
build/preferences/style-rtl.css 710 B
build/preferences/style.css 712 B
build/primitives/index.min.js 809 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 1 kB
build/react-i18n/index.min.js 623 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 6.78 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 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.1 kB
build/router/index.min.js 1.93 kB
build/server-side-render/index.min.js 1.96 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 2.02 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.74 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.7 kB
build/vendors/react.min.js 4.03 kB
build/viewport/index.min.js 957 B
build/warning/index.min.js 249 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.17 kB
build/widgets/style.css 1.17 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@t-hamano
Copy link
Contributor

t-hamano commented Dec 1, 2023

What is the root cause of styles and classes not being applied on both the editor side and the front end side? My understanding is that the useblockProps hook should automatically give them those styles and classes.

Does it have something to do with this block being experimental? 🤔

@aristath
Copy link
Member Author

aristath commented Dec 1, 2023

What is the root cause of styles and classes not being applied on both the editor side and the front end side? My understanding is that the useblockProps hook should automatically give them those styles and classes.

It was an error of omission... In the initial POC implementation, I just forgot to add them. The style was missing completely, and the classname was hardcoded to wp-block-form without getting any of the other ones added from colors, borders etc

@t-hamano
Copy link
Contributor

t-hamano commented Dec 1, 2023

I understand why. Although the blockProps hook has already been introduced, the className is false and the class name wp-block-form is hard-coded.

Is there any reason to make className false? If not, I think all we need to do is make the following changes.

diff --git a/packages/block-library/src/form/block.json b/packages/block-library/src/form/block.json
index 0c6451f495..b79c9f9249 100644
--- a/packages/block-library/src/form/block.json
+++ b/packages/block-library/src/form/block.json
@@ -27,7 +27,6 @@
        },
        "supports": {
                "anchor": true,
-               "className": false,
                "color": {
                        "gradients": true,
                        "link": true,
:...skipping...
diff --git a/packages/block-library/src/form/block.json b/packages/block-library/src/form/block.json
index 0c6451f495..b79c9f9249 100644
--- a/packages/block-library/src/form/block.json
+++ b/packages/block-library/src/form/block.json
@@ -27,7 +27,6 @@
                "anchor": true,
-               "className": false,
                "color": {
                        "gradients": true,
                        "link": true,
diff --git a/packages/block-library/src/form/edit.js b/packages/block-library/src/form/edit.js
index 7fded64837..7f479a9b2c 100644
--- a/packages/block-library/src/form/edit.js
+++ b/packages/block-library/src/form/edit.js
@@ -172,7 +172,6 @@ const Edit = ( { attributes, setAttributes, clientId } ) => {
                        ) }
                        <form
                                { ...innerBlocksProps }
-                               className="wp-block-form"
                                encType={ submissionMethod === 'email' ? 'text/plain' : null }
                        />
                </>
diff --git a/packages/block-library/src/form/save.js b/packages/block-library/src/form/save.js
index a824fc076d..9d944f13ef 100644
--- a/packages/block-library/src/form/save.js
+++ b/packages/block-library/src/form/save.js
@@ -10,7 +10,6 @@ const Save = ( { attributes } ) => {
        return (
                <form
                        { ...blockProps }
-                       className="wp-block-form"
                        encType={ submissionMethod === 'email' ? 'text/plain' : null }
                >
                        <InnerBlocks.Content />
~
~

Also, this PR requires deprecation because it changes the save markup, but as reported by #56590 there is an issue with fixture tests not working correctly.

@aristath
Copy link
Member Author

aristath commented Dec 4, 2023

You're right, the className in block.json should not be false. I pushed a commit to fix that.
However, I tried your suggestion and it didn't work... It looks like all the other stuff is needed too. Upon further examination, I saw we do the same thing in the button block, the search block, as well as various others like image and so on.

@t-hamano
Copy link
Contributor

t-hamano commented Dec 4, 2023

Upon further examination, I saw we do the same thing in the button block, the search block, as well as various others like image and so on.

I think this kind of approach is mainly used when styles need to be applied to the elements inside the block rather than the wrapper. Styles and classes should be applied correctly to the block wrapper unless we are using __experimentalSkipSerialization.

I pushed f8ee53e with the changes. In my testing, both global and block-specific styles appear to be applied correctly. Could you test this commit once?

4a2d95ba8a52a7ab5ccbe866a0ea3fbf.mp4

@aristath
Copy link
Member Author

aristath commented Dec 4, 2023

Huh... Confirmed, it works ❤️
Thank you!

@t-hamano
Copy link
Contributor

I'm glad to know it worked correctly.

The code looks good, but in order to ship this PR, I think the following two actions are necessary:

  • Rebase this PR with the latest trunk branch: This is because #56590, which ensures form-related fixtures are generated correctly in the fixture test, is included.
  • Regenerate the fixture file via the npm run fixtures:regenerate command.

@aristath
Copy link
Member Author

Done.
npm run fixtures:regenerate didn't change anything so I assume we're OK 👍

@t-hamano
Copy link
Contributor

Sorry, I forgot to tell you one more thing 😅

This PR is updating the save function, so you need to add a block deprecation. This will update existing fixture files when you run npm run fixtures:regenerate. Additionally, there is a need to add a new fixture as well.

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw 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 the ping @t-hamano 👍

Under normal circumstances, the deprecation here should work. The bug this PR aims to fix though causes some serious problems though.

We're running into an issue where the deprecation doesn't work well in the form block. Ideally, we should investigate the cause, but what do you think about not adding deprecation to blocks that are marked as "experimental"?

100% we should investigate the cause. I don't think we can or should avoid that.

Regarding the experimental nature of the block to date. I agree the fact it is experimental should give us more freedoms but I still believe we owe it to early adopters to prevent breakages where possible.

In this case, adding a working deprecation is possible, so my vote is that we do so.

I've tried to fix the deprecation implementation for days but I can't figure it out.

@aristath I believe I've tracked down the root of the issue with why the current version of the deprecation isn't working. I'll try and summarize it all here clearly but it is a tricky area, so feel free to challenge anything, ask questions etc.

Deprecations only run when their old version of the block's save function generates the same content as what's saved in the block's markup.

The catch is that it does this through a series of utils: validateBlock > getSaveContent > getSaveElement.

The last of those, getSaveElement, will generate the content from the save function first, it then applies any extra props via the blocks.getSaveContent.extraProps filters. The block supports in the editor are applied via that filter.

This is why originally the block supports appeared to work in the editor and not on the frontend. It is also why then the deprecation is determined to not generate "valid" block markup and so isn't applied.

This is where the nature of the mistake in the original implementation really starts to cause some problems.

While I'm not very familiar with this area of the code, I don't think we can change the order of the application of block supports. It is likely being relied on as is and changing it to accommodate a bug fix is probably a non-starter.

There is an approach that has worked for me while hacking at this PR locally.

  1. Remove the block supports config from the deprecation (well, make it empty and comment as to why, to demonstrate this is deliberate despite the block originally having supports enabled).
  2. Manually define the block support attributes within the deprecation's attributes. This is required to maintain the data for the block support styles so they get migrated. Again, the hacked attributes should be heavily documented inline.

I'm running out of time today but in the simple testing I've done so far for a few different types of color; background, text, link etc. and the font size typography setting. It successfully migrates for me.

Proposal

  1. Update the deprecation to omit the supports config and documented why.
  2. Manually add the attribute definitions for all the block supports to the deprecation and document why again
  3. Add a fixture for the form block that covers this deprecation i.e. one that has the old markup with only the wp-block-form class despite containing block support data e.g. backgroundColor in its attributes.

* trunk: (273 commits)
  Remove preffered style variations legacy support (#58930)
  Style theme variations: add property extraction and merge utils (#58803)
  Migrate `change-detection` to Playwright (#58767)
  Update Changelog for 17.6.6
  Docs: Clarify the status of the wp-block-styles theme support, and its intent (#58915)
  Use `data_wp_context` helper in core blocks and remove `data-wp-interactive` object (#58943)
  Try double enter for details block. (#58903)
  Template revisions API: move from experimental to compat/6.4 (#58920)
  Editor: Remove inline toolbar preference (#58945)
  Clean up link control CSS. (#58934)
  Font Library: Show error message when no fonts found to install (#58914)
  Block Bindings: lock editing of blocks by default (#58787)
  Editor: Remove the 'all' rendering mode (#58935)
  Pagination Numbers: Add `data-wp-key` to pagination numbers if enhanced pagination is enabled (#58189)
  Close link preview if collapsed selection when creating link (#58896)
  Fix incorrect useAnchor positioning when switching from virtual to rich text elements (#58900)
  Upgrade Floating UI packages, fix nested iframe positioning bug (#58932)
  Site editor: fix start patterns store selector (#58813)
  Revert "Rich text: pad multiple spaces through en/em replacement (#56341)" (#58792)
  Documentation: Clarify the performance reference commit and how to pick it (#58927)
  ...
@aristath
Copy link
Member Author

Hey @aaronrobertshaw, thank you for looking into this!
I'm afraid I don't quite understand this part:

Manually define the block support attributes within the deprecation's attributes. This is required to maintain the data for the block support styles so they get migrated. Again, the hacked attributes should be heavily documented inline.

You mentioned that you got it working locally... Could you please post some code? Doesn't need to be complete, just enough for me to understand what's on your mind and what worked for you structurally.
My apologies if I'm wasting your time, but usually code makes more sense than words to me, and currently I don't understand what should go where 😅

@aaronrobertshaw
Copy link
Contributor

My apologies for not adding code snippets, I'm a bit short on time and bandwidth at the moment.

I'm afraid I don't quite understand this part:
...
Manually define the block support attributes within the deprecation's attributes. This is required to maintain the data for the block support styles so they get migrated. Again, the hacked attributes should be heavily documented inline.

What I mean, is that the deprecation defines its attributes. Those deprecation attributes could be updated to include the attributes that the block supports inject. For example, the background color support adds a number of attributes such as.

			backgroundColor: {
				type: 'string',
			},
			textColor: {
				type: 'string',
			},
			gradient: {
				type: 'string',
			},

If we only updated the deprecation's supports definition to be {} these sorts of attributes wouldn't be added to the deprecated version of the block. So they would be lost when migrating the block unless we add them to the deprecation's attributes manually.

You mentioned that you got it working locally... Could you please post some code? Doesn't need to be complete, just enough for me to understand what's on your mind and what worked for you structurally.

I didn't stash the local changes as they were so far from complete but I'll put together something quick to illustrate the thrust of what I'm proposing.

Example diff
diff --git a/packages/block-library/src/form/deprecated.js b/packages/block-library/src/form/deprecated.js
index 4109ddf442..5db53b66ec 100644
--- a/packages/block-library/src/form/deprecated.js
+++ b/packages/block-library/src/form/deprecated.js
@@ -5,37 +5,18 @@ import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
 
 const deprecated = [
 	{
-		supports: {
-			anchor: true,
-			className: false,
-			color: {
-				gradients: true,
-				link: true,
-				__experimentalDefaultControls: {
-					background: true,
-					text: true,
-					link: true,
-				},
-			},
-			spacing: {
-				margin: true,
-				padding: true,
-			},
-			typography: {
-				fontSize: true,
-				lineHeight: true,
-				__experimentalFontFamily: true,
-				__experimentalTextDecoration: true,
-				__experimentalFontStyle: true,
-				__experimentalFontWeight: true,
-				__experimentalLetterSpacing: true,
-				__experimentalTextTransform: true,
-				__experimentalDefaultControls: {
-					fontSize: true,
-				},
-			},
-			__experimentalSelector: 'form',
-		},
+		// The block supports here are deliberately empty despite this
+		// deprecated version of the block having adopted block supports.
+		// The attributes added by these supports have been manually
+		// added to this deprecated version's attributes definition so
+		// that the data isn't lost on migration. All this is so that the
+		// automatic application of block support classes doesn't occur
+		// as this version of the block had a bug that overrode those
+		// classes. If those block support classes are applied during the
+		// deprecation process, this deprecation doesn't match and won't
+		// run.
+		// @see https://github.com/WordPress/gutenberg/pull/55755
+		supports: {},
 		attributes: {
 			submissionMethod: {
 				type: 'string',
@@ -51,6 +32,12 @@ const deprecated = [
 			email: {
 				type: 'string',
 			},
+			// The following attributes have been added to match the block
+			// supports at the time of the deprecation. See above for details.
+			backgroundColor: {
+				type: 'string',
+			},
+			// ... rest of block support attributes.
 		},
 		save( { attributes } ) {
 			const blockProps = useBlockProps.save();

I hope that helps 🤞

@t-hamano
Copy link
Contributor

This PR will also fix #59045.

* trunk: (78 commits)
  Components: Use `Element.scrollIntoView()` instead of `dom-scroll-into-view` (#59085)
  DataViews: Correctly display featured image that don't have image sizes (#59111)
  Elements: Fix block instance element styles for links applying to buttons (#59114)
  Allow editing of image block alt and title attributes in content only mode (#58998)
  Add toggle for grid types and stabilise Grid block variation. (#59051)
  Global Styles: fix console error in block preview (#59112)
  Navigation: Avoid using embedded records from fallback API (#59076)
  Refactor responsive logic for grid column spans. (#59057)
  Editor: Unify Mode Switcher component between post and site editor (#59100)
  Move StopEditingAsBlocksOnOutsideSelect to Root (#58412)
  Fix logic error in #58951 (#59101)
  Block-editor: Auto-register block commands (#59079)
  Fix small typo in rich text reference guide (#59089)
  Components: Add lint rules for theme color CSS var usage (#59022)
  Enter editing mode via Enter or Spacebar (#58795)
  Updating Storybook to v7.6.15 (latest) (#59074)
  CustomSelectControl (v1 & v2): Fix errors in unit test setup (#59038)
  Add stylelint rule to prevent theme CSS vars outside of wp-components (#59020)
  ColorPicker: Style without accessing InputControl internals (#59069)
  Pattern block: batch replacing actions (#59075)
  ...
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw 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 continuing to iterate on this @aristath 👍

The deprecation looks good and the attributes contained within it match those provided by block supports currently.

I think the only thing we need now is a fixture that covers this deprecated version of the form block.

@aristath aristath dismissed carolinan’s stale review April 19, 2024 07:44

All requested changes from this review have been applied

@aristath
Copy link
Member Author

I removed the deprecation as it was not working.
Since this is an experimental block, a deprecation is not strictly required...

I don't know how to build this deprecation and make it work both in real-world use as well as in automated tests. If I make it pass the automated tests, then it doesn't work when I try to do it in the editor itself and vice-versa. 🤷

Granted, the deprecation bug in this PR is an edge-case, but it's been a blocker for this PR for months so I completely removed it, as I find no way forward if we try to enforce it.

@aaronrobertshaw
Copy link
Contributor

I removed the deprecation as it was not working.

Can you expand at all on what wasn't working with the deprecation? Some steps to replicate the problem would be helpful.

Since this is an experimental block, a deprecation is not strictly required...

I think this is a bit of a grey area. If we can sort out the deprecation and not break blocks for early adopters, that sounds like our best bet. From memory, the deprecations were pretty close last I reviewed this PR.

make it work both in real-world use as well as in automated tests

If there is a disconnect between our fixture tests and how deprecations are working in the editor, that sounds like something we should probably get to the bottom of to maintain confidence in those tests.

I'm a little tied up on other things for WP 6.6 at the moment but I'd be more than happy to help out after the 6.6 beta.

@aristath
Copy link
Member Author

Thank you for replying @aaronrobertshaw

Can you expand at all on what wasn't working with the deprecation? Some steps to replicate the problem would be helpful.

The main issue I faced is in the UI.
Steps to replicate:

  • Using trunk add a form block in the editor
  • Change background-color, text-color and play with the styles a bit
  • Switch to this branch and reload the editor

The error: Expecting the deprecation to kick-in and work, migrating the content. What actually happens: Still getting the invalid-block error. As soon as I hit the recovery button everything works, but that's not what we expect when adding migrations

@aaronrobertshaw
Copy link
Contributor

Thanks for the extra details 👍

It still sounds like an issue we should be able to fix with the deprecation. Have you by any chance done some debugging around where block deprecations are applied to see what's going on in this case?

My understanding is that the form block isn't being stabilized for WP6.6, so there is no urgency to have this sorted before the WP6.6. beta, correct? I'd be happy to dig deeper in a week or two if that's the case.

@aristath
Copy link
Member Author

Have you by any chance done some debugging around where block deprecations are applied to see what's going on in this case?

Yeah, tried to understand it for weeks and couldn't understand what goes on there... so to be honest I gave up. Deprecations make my head spin, so I moved on to other issues 😅

My understanding is that the form block isn't being stabilized for WP6.6, so there is no urgency to have this sorted before the WP6.6. beta, correct?

That is correct. this is not an urgent task 👍

@aaronrobertshaw
Copy link
Contributor

Deprecations make my head spin

Don't worry, you aren't alone there. Happens every time I have to revisit the area.

That is correct. this is not an urgent task 👍

Great, then in that case let's see what we can come up with once I can free up some bandwidth.

Appreciate your patience on this one.

@t-hamano
Copy link
Contributor

I also investigated this issue again. I tried the deprecation suggested in this comment and it seems to work in some scenarios, but not completely.

For example, this deprecation works if the original markup does not include inline styles:

image

However, if the markup contains inline styles, deprecation will cause an error.

image
It feels like one more step, but I'm pushing the deprecated code again so you can test this issue.

@t-hamano
Copy link
Contributor

Interesting #61833 submitted. It is mentioned that deprecation fails when blockProps is not used.

The Fform block has blockProps applied, but the class name is overridden. Maybe this PR is also related to #61833.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Form (experimental) Affects the form block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental Block: Form - can't add custom CSS class
5 participants