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

Try reducing specificity of global styles block selector. #57841

Closed
wants to merge 22 commits into from

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Jan 15, 2024

What?

Tries to address specificity issues in #56540 (comment) by wrapping the block global styles root selector, global element selectors, global feature selectors and global layout selectors in :where().

For this to work it was also necessary to lower the specificity of some block-library styles, especially ones from the optionally enqueued "theme" files.

This should get some pretty thorough testing with themes, all sorts of blocks with global styles and variations thereof.

Testing Instructions

  1. Test global styles on all blocks and their style variations and check they still work as expected.
  2. Test global and local layout styles and check that blocks with global margins set don't override the layout margins.
  3. Test block themes with theme support for wp-block-styles (only early block themes such as TT2 have this) and check global styles override block-library styles correctly.

Testing Instructions for Keyboard

Screenshots or screencast

@tellthemachines tellthemachines added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json CSS Styling Related to editor and front end styles, CSS-specific issues. labels Jan 15, 2024
@tellthemachines tellthemachines self-assigned this Jan 15, 2024
Copy link

github-actions bot commented Jan 15, 2024

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/block-supports/layout.php
❔ lib/class-wp-theme-json-gutenberg.php
❔ phpunit/block-supports/layout-test.php
❔ phpunit/class-wp-theme-json-test.php

@@ -991,7 +991,7 @@ protected static function get_blocks_metadata() {
}

foreach ( $blocks as $block_name => $block_type ) {
$root_selector = wp_get_block_css_selector( $block_type );
$root_selector = ':where(' . wp_get_block_css_selector( $block_type ) . ')';
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach would need to be extended to where all the feature selectors are generated e.g. an image block's border styles.

Copy link

github-actions bot commented Jan 15, 2024

Size Change: -1.7 kB (0%)

Total Size: 1.7 MB

Filename Size Change
build/block-editor/content-rtl.css 4.35 kB -3 B (0%)
build/block-editor/content.css 4.35 kB -2 B (0%)
build/block-editor/index.min.js 249 kB -1.61 kB (-1%)
build/block-editor/style-rtl.css 15.3 kB -89 B (-1%)
build/block-editor/style.css 15.3 kB -89 B (-1%)
build/block-library/blocks/audio/theme-rtl.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/audio/theme.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/cover/style-rtl.css 1.7 kB +6 B (0%)
build/block-library/blocks/cover/style.css 1.69 kB +7 B (0%)
build/block-library/blocks/embed/theme-rtl.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/embed/theme.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/image/editor-rtl.css 878 B +15 B (+2%)
build/block-library/blocks/image/editor.css 878 B +16 B (+2%)
build/block-library/blocks/image/theme-rtl.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/image/theme.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB +3 B (0%)
build/block-library/blocks/navigation/editor.css 2.26 kB +4 B (0%)
build/block-library/blocks/navigation/style-rtl.css 2.26 kB +25 B (+1%)
build/block-library/blocks/navigation/style.css 2.25 kB +26 B (+1%)
build/block-library/blocks/navigation/view.min.js 1.02 kB -87 B (-8%)
build/block-library/blocks/pullquote/theme-rtl.css 174 B +6 B (+4%)
build/block-library/blocks/pullquote/theme.css 174 B +6 B (+4%)
build/block-library/blocks/quote/theme-rtl.css 233 B +10 B (+4%)
build/block-library/blocks/quote/theme.css 235 B +9 B (+4%)
build/block-library/blocks/social-links/editor-rtl.css 678 B -4 B (-1%)
build/block-library/blocks/social-links/editor.css 678 B -3 B (0%)
build/block-library/blocks/table/theme-rtl.css 152 B +6 B (+4%)
build/block-library/blocks/table/theme.css 152 B +6 B (+4%)
build/block-library/blocks/template-part/theme-rtl.css 107 B +6 B (+6%) 🔍
build/block-library/blocks/template-part/theme.css 107 B +6 B (+6%) 🔍
build/block-library/blocks/video/theme-rtl.css 133 B +7 B (+6%) 🔍
build/block-library/blocks/video/theme.css 133 B +7 B (+6%) 🔍
build/block-library/editor-rtl.css 12.3 kB -2 B (0%)
build/block-library/editor.css 12.3 kB -2 B (0%)
build/block-library/index.min.js 216 kB +236 B (0%)
build/block-library/style-rtl.css 14.8 kB +27 B (0%)
build/block-library/style.css 14.8 kB +22 B (0%)
build/block-library/theme-rtl.css 707 B +19 B (+3%)
build/block-library/theme.css 713 B +20 B (+3%)
build/blocks/index.min.js 51.6 kB -4 B (0%)
build/components/index.min.js 223 kB -2.4 kB (-1%)
build/components/style-rtl.css 11.8 kB +1 B (0%)
build/components/style.css 11.8 kB +1 B (0%)
build/core-data/index.min.js 72.7 kB -8 B (0%)
build/edit-post/index.min.js 23.8 kB -1.27 kB (-5%)
build/edit-post/style-rtl.css 5.64 kB +11 B (0%)
build/edit-post/style.css 5.63 kB +10 B (0%)
build/edit-site/index.min.js 214 kB +1.75 kB (+1%)
build/edit-site/style-rtl.css 15.3 kB -24 B (0%)
build/edit-site/style.css 15.3 kB -21 B (0%)
build/edit-widgets/index.min.js 17.3 kB +3 B (0%)
build/edit-widgets/style-rtl.css 4.22 kB +9 B (0%)
build/edit-widgets/style.css 4.22 kB +8 B (0%)
build/editor/index.min.js 63.7 kB +1.91 kB (+3%)
build/editor/style-rtl.css 5.31 kB -121 B (-2%)
build/editor/style.css 5.31 kB -120 B (-2%)
build/interactivity/navigation.min.js 1.15 kB -86 B (-7%)
build/patterns/index.min.js 5.79 kB +7 B (0%)
ℹ️ 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.32 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 578 B
build/block-directory/index.min.js 7.22 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 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/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 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 647 B
build/block-library/blocks/cover/editor.css 650 B
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 322 B
build/block-library/blocks/embed/editor.css 322 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 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 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 947 B
build/block-library/blocks/gallery/editor.css 952 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 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 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/style-rtl.css 1.6 kB
build/block-library/blocks/image/style.css 1.59 kB
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 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 259 B
build/block-library/blocks/navigation-link/style.css 257 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/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 666 B
build/block-library/blocks/post-featured-image/editor.css 662 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 409 B
build/block-library/blocks/post-template/style.css 408 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 354 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/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 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 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 614 B
build/block-library/blocks/search/style.css 614 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 229 B
build/block-library/blocks/separator/style.css 229 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/style-rtl.css 1.49 kB
build/block-library/blocks/social-links/style.css 1.48 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/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/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/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/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-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/commands/index.min.js 15.6 kB
build/commands/style-rtl.css 921 B
build/commands/style.css 918 B
build/compose/index.min.js 12.6 kB
build/core-commands/index.min.js 2.77 kB
build/customize-widgets/index.min.js 12.1 kB
build/customize-widgets/style-rtl.css 1.32 kB
build/customize-widgets/style.css 1.32 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 8.93 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 544 B
build/edit-post/classic.css 545 B
build/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.89 kB
build/format-library/style-rtl.css 478 B
build/format-library/style.css 477 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/file.min.js 447 B
build/interactivity/image.min.js 1.67 kB
build/interactivity/index.min.js 12.7 kB
build/interactivity/query.min.js 740 B
build/interactivity/router.min.js 1.29 kB
build/interactivity/search.min.js 618 B
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.74 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 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 2 kB
build/nux/style-rtl.css 735 B
build/nux/style.css 732 B
build/patterns/style-rtl.css 540 B
build/patterns/style.css 539 B
build/plugins/index.min.js 1.8 kB
build/preferences-persistence/index.min.js 2.05 kB
build/preferences/index.min.js 2.82 kB
build/preferences/style-rtl.css 698 B
build/preferences/style.css 700 B
build/primitives/index.min.js 975 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.72 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 10.4 kB
build/router/index.min.js 1.79 kB
build/server-side-render/index.min.js 1.95 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 2.08 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.72 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 957 B
build/warning/index.min.js 249 B
build/widgets/index.min.js 7.21 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

@tellthemachines
Copy link
Contributor Author

Update: reducing the specificity of global styles is contingent on changing the order the stylesheets are loaded in. I have a PR in core for that: WordPress/wordpress-develop#5892 which fixes that problem but it needs a bit of work as it's currently breaking editor chrome styles 😬

Copy link

github-actions bot commented Jan 19, 2024

Flaky tests detected in 2fd08c2.
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/7969647568
📝 Reported issues:

@tellthemachines tellthemachines marked this pull request as ready for review January 19, 2024 05:13
@tellthemachines
Copy link
Contributor Author

OK marking this ready for review as I think the changes are pretty stable right now. Any and all feedback and testing is immensely appreciated! Especially from @WordPress/theme-team but everyone else too ❤️

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.

Great work on this @tellthemachines 👍

I'll give this a proper test on Monday. In the meantime, I tried cherry picking these updates into an alternate approach on the extended block style variations and noticed root layout styles were overriding layout styles on individual block instances. I can replicate the same behaviour on this branch.

Screenshot 2024-01-19 at 5 13 07 pm

This seems to affect the frontend worse as in the editor the .editor-styles-wrapper on the block instance styles bumps its specificity enough to take precedence and look correct.

Editor Frontend
Screenshot 2024-01-19 at 5 22 06 pm Screenshot 2024-01-19 at 5 21 52 pm

The above issue is related to this change. I didn't get a chance to dig into where the root body .is-layout-flex selector is added to see if that can be lowered as well but I'll take a look next week and I can help out more.

Also, I think the feature level selectors defined by the block selectors API still need a reduction as noted earlier. I guess we could wrap them when generating feature level declarations or they could be done on bulk in get_block_selectors.

FWIW this overall reduction really does seem promising and unlocks #57908. After a quick test it allows nested applications of block style variations which would be a big win!

@tellthemachines
Copy link
Contributor Author

Ok I've bumped the specificity of all base layout rules down to zero. This may need a little fine tuning if we think we should ensure that properties such as display: flex get applied. Instead of :where(body .is-layout-flex) we could perhaps have body :where(.is-layout-flex).

@carolinan
Copy link
Contributor

PInging @ddryo, @cbirdsong and @eric-michel, based on previous discussions I wanted to alert you of this change.

@aaronrobertshaw
Copy link
Contributor

aaronrobertshaw commented Jan 22, 2024

Ok I've bumped the specificity of all base layout rules down to zero.

Nice. I can confirm this solves the layout issue I noted in my last review 👍

I'm still working through testing all the edge cases and seeing how this plays with the extension of block style variations but have noticed at least one issue with the zero specificity rules.

Using TT3 I'm seeing a different order of styles between the editor and frontend. In the editor, the correct general link color is being applied, as defined for the post content block. On the frontend though it's being overridden.

Editor:
Screenshot 2024-01-22 at 8 06 02 pm

Frontend:
Screenshot 2024-01-22 at 8 02 14 pm

I'll try and dig into this tomorrow. On the surface it looks as though the element style node is being processed after block type elements.

If it is related how the theme.json stylesheet is generated, I wonder if it would be beneficial to sort of collect the different nodes into categories and then generate style declarations in a more deliberate and clear order. Maybe even following the order of specificity defined in some form of documentation as proposed in this comment.

@carolinan
Copy link
Contributor

Theme: Negai.

On theme activation:
On the front, the theme.json elements styles overrides the theme.json block styles, and the result is an unexpected font size and font weight for the site title which is an H1.

CSS on the front:

:where(h1) {
	font-size: var(--wp--preset--font-size--xx-large);
}

:where(h1, h2, h3, h4, h5, h6) {
	font-weight: 500;
	line-height: calc(1em + 0.5rem);
}
:where(.wp-block-site-title) {
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
	line-height: calc(1em + 0.5rem);
}

CSS in the editor.

:where(.wp-block-site-title) {
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
	line-height: calc(1em + 0.5rem);
}
<style>
:where(h1) {
	font-size: var(--wp--preset--font-size--xx-large);
}
<style>
:where(h1, h2, h3, h4, h5, h6) {
	font-weight: 500;
	line-height: calc(1em + 0.5rem);
}

When changing the font size of the site title in the Site Editor > Styles sidebar > Blocks > Site Title
The size is correct in the Site Editor but not the front.

Front:

:where(h1) {
	font-size: var(--wp--preset--font-size--xx-large);
}

:where(h1, h2, h3, h4, h5, h6) {
	font-weight: 500;
	line-height: calc(1em + 0.5rem);
}
:where(.wp-block-site-title) {
	font-size: var(--wp--preset--font-size--huge);
	font-weight: 600;
	line-height: calc(1em + 0.5rem);
}

Editor:

:where(.wp-block-site-title) {
	font-size: var(--wp--preset--font-size--huge);
	font-weight: 600;
	line-height: calc(1em + 0.5rem);
}

<style>
:where(h1) {
	font-size: var(--wp--preset--font-size--xx-large);
}
<style>
:where(h1, h2, h3, h4, h5, h6) {
	font-weight: 500;
	line-height: calc(1em + 0.5rem);
}

When changing the size on the individual site title block, using the option in the block sidebar.
The size is correct in the editor and front, wether a preset or custom size is chosen. ( On the front, clamp is used, but that is a separate issue).

@tellthemachines
Copy link
Contributor Author

Thanks for testing this folks!

Using TT3 I'm seeing a different order of styles between the editor and frontend. In the editor, the correct general link color is being applied, as defined for the post content block. On the frontend though it's being overridden.

I'll try and dig into this tomorrow. On the surface it looks as though the element style node is being processed after block type elements.

No, this is the issue that prompted reordering the styles in core. There's nothing wrong with the style generation itself; the problem is that element styles are part of base global styles (because they're not block-specific), and the order of style enqueuing in core is currently wrong because base global styles are being added to the document after block-specific global styles, when it should be the other way around.

On the front, the theme.json elements styles overrides the theme.json block styles, and the result is an unexpected font size and font weight for the site title which is an H1.

When changing the font size of the site title in the Site Editor > Styles sidebar > Blocks > Site Title
The size is correct in the Site Editor but not the front.

These issues are also a result of the incorrect stylesheet order in core. Note that a global block style declared in theme.json and one added through the global styles sidebar have the same specificity, so essentially it's the same issue. What is happening is that, because element styles are loaded after block-specific global styles, they're taking precedence now that both have the same (zero) specificity.

If these are the only issues with this PR 🤞 then things are looking pretty good! Because they will be fixed by the core PR linked above.

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.

Very cool exploration!

What will this mean for the CSS that's included with the blocks themselves? I haven't looked through in any exhaustive way, but I see the Cover block has a default padding of 1em which gets overridden by global styles on trunk, but with this PR applied, the global styles' padding for the Cover block now has a lower specificity that the CSS rules for that block:

Trunk

The global styles padding for the Cover block overrides the block's CSS that ships alongside the block.

image

This PR

The block's own CSS wins.

image

Will blocks' CSS rules need to be lowered? And for 3rd party blocks that might use existing block supports like padding, margin, etc, would they also need to know to reduce specificity in any of their own stylesheets in order to support global styles 🤔

One thing on the back of mind while reading through is thinking through the min-height: unset rule I'm exploring adding as part of the aspect ratio support PR over in #56897. For that PR to work in conjunction with this one, I think I'd need to reduce the specificity of the Cover block's min-height rule here:

I think that'd probably be fine (and would be a simple code change as part of #56897), but just wondered if it's the kind of thing that could affect more blocks or potential future block supports?

@aaronrobertshaw
Copy link
Contributor

Cover block has a default padding of 1em which gets overridden by global styles on trunk, but with this PR applied, the global styles' padding for the Cover block now has a lower specificity

I can confirm this one also.

No, this is the issue that prompted WordPress/wordpress-develop#5892.

So if these changes require an update in core that would mean they need to be reflected in Gutenberg as well or is this blocked on BC grounds until those core updates are in the minimum version of WP supported by Gutenberg?

I might be missing something but it appears like the core patch could be brought into Gutenberg.

  • Theme.json class changes are a given
  • Some of cores default filters are replaced in Gutenberg with its own e.g. wp_enqueue_global_styles action
  • Gutenberg would probably need to be updated anyway to replace the new actions added in the core patch
  • New functions in global-styles-and-settings.php can also be add if not defined
  • Updates to wp_add_global_styles_for_blocks need to go into gutenberg_add_global_styles_for_blocks
  • Similar for wp_enqueue_global_styles_custom_css etc

@tellthemachines
Copy link
Contributor Author

Thanks for the feedback folks!

Will blocks' CSS rules need to be lowered? And for 3rd party blocks that might use existing block supports like padding, margin, etc, would they also need to know to reduce specificity in any of their own stylesheets in order to support global styles

Yes and probably also yes 😄 . The block-library styles have been progressively losing specificity, and I think that trend should continue as they are essentially core block global styles declared in a legacy manner. Third party block developers may need to reduce specificity in their styles if they're counting on global styles overriding their block ones (not sure how common that scenario is? But yeah this will have to be advertised as a potentially breaking change)

So if these changes require an update in core that would mean they need to be reflected in Gutenberg as well or is this blocked on BC grounds until those core updates are in the minimum version of WP supported by Gutenberg?

I might be missing something but it appears like the core patch could be brought into Gutenberg.

I was planning to do a similar PR for Gutenberg, but I can try adding the changes to this branch instead if it helps for testing purposes!

In terms of priority, I believe the work should be done core-first because it affects the order styles are loaded in core so its effects might not be fully reproducible in Gutenberg. Another consideration is that this PR shouldn't land in core before that core PR is committed, or we'll see breakage along the lines of those issues already noted above. Given that we're close to Beta and package updates are starting to happen, I'd like to be 100% sure the change in core is viable before going ahead with this one.

@aaronrobertshaw
Copy link
Contributor

aaronrobertshaw commented Jan 23, 2024

I can try adding the changes to this branch instead if it helps for testing purposes!

That'd be great thanks. It should also help with testing the extended block style variations and getting more eyes on this PR.

It could still be a separate PR if you'd prefer to just make this one based on it.

In terms of priority, I believe the work should be done core-first

No arguments here. I agree also with wanting to make sure the approach is viable in core before landing this.

Another consideration is that this PR shouldn't land in core before that core PR is committed

This shouldn't land at all until the changes to the order styles are loaded are also reflected in Gutenberg. Perhaps that's another reason to bring the changes into this PR to make sure of that?

@aaronrobertshaw aaronrobertshaw force-pushed the try/reduce-global-styles-specificity branch from 122fd65 to 026da63 Compare January 24, 2024 00:14
@tellthemachines
Copy link
Contributor Author

Thanks for fixing the tests @aaronrobertshaw ! I've updated with the style loading changes from the core PR so this should be a bit easier to test now.

@tellthemachines
Copy link
Contributor Author

Thanks for testing @carolinan!

What is that status of this PR and its inclusion in 6.5?

This PR is not aiming for 6.5, but for 6.6. The goal is to merge early in the cycle, so we have plenty of time to detect and address any resulting breakage before the next release.

The shortcode block before and after this PR has different widths. I used the built in WordPress audio shortcode.

This is an interesting one. It happens because the core layout styles in this PR are no longer specific enough to override the max-width defined for the shortcode in core.

The shortcode block just renders whatever is passed into it, with no wrapper, so there's no way of forcing its contents to adjust to content width. The only solution I can see to this is bumping the specificity of that layout rule up again. I think that could be done for the single rule without having to adjust specificity for any other rules, so it's worth a try.

I did wonder how prevalent use of the core audio shortcode might be in the block editor when there's also an Audio block available, but the Audio block has no styling options (due to using the HTML <audio> element), and it doesn't always look great:

Screenshot 2024-02-20 at 1 24 10 pm

(core shortcode on top, Audio block below)

so I imagine there are still legitimate reasons to use the shortcode 😂

@carolinan
Copy link
Contributor

It would have been helpful for contributors to know it was no longer planned for 6.5, as we have been asked to continue testing it, for 6.5, and it affects what we spend time on.

@tellthemachines
Copy link
Contributor Author

It would have been helpful for contributors to know it was no longer planned for 6.5, as we have been asked to continue testing it, for 6.5, and it affects what we spend time on.

I'm sorry about the miscommunication. When the PR was opened, the hope was to get it into 6.5, but as the feature cutoff approached it became clear that it wouldn't make it. I should have made it clear here that this is no longer being considered for 6.5.

@carolinan
Copy link
Contributor

How does this affect https://core.trac.wordpress.org/ticket/60280

@tellthemachines
Copy link
Contributor Author

How does this affect https://core.trac.wordpress.org/ticket/60280

This PR depends on that ticket. Because reordering the style output was a pretty small and self-contained change, it could safely be included in 6.5. It probably won't have much of an effect without this PR, but it's good to have it done already.

@@ -541,7 +541,7 @@ class WP_Theme_JSON_Gutenberg {
* @var string[]
*/
const ELEMENTS = array(
'link' => 'a:where(:not(.wp-element-button))', // The `where` is needed to lower the specificity.
'link' => 'a:not(.wp-element-button)',
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few other places the elements selectors might need updating as well as here if we are actually wanting to increase this selectors specificity from 0-0-1 to 0-1-1 e.g. the elements block support and the global styles output constant.

Given the spirit of this PR is to reduce specificity can we omit this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be a bit turned around jumping between PRs, I take it this change was because at least in the theme.json class element selectors are getting wrapped in :where?

As these selectors may be referenced elsewhere, is there a benefit to keeping the a:where(:not(.wp-element-button)) selector for links so it is consistent with the elements block support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure! Theoretically it would be nice if the element selectors didn't make any specificity assumptions, and we just manipulated the specificity as needed when using them in different contexts.

Relatedly, I think I found a bug in the link selector on this branch: the blocks-specific link selector no longer has the :not bit attached. Looking into it now!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh turns out that's only recently been fixed on trunk, so rebasing should fix it. Might not be worth it if I'm going to split this into multiple PRs though.

Copy link
Contributor

Choose a reason for hiding this comment

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

For posterity, the PR fixing it on trunk was #59114.

Agreed, it's probably not work worrying about. On the splitting up front, I have a few other PRs based on this branch so my only question is do you see the different split parts as being pretty stable at this stage?

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 hope so, but this PR isn't getting a huge amount of feedback or testing so far, so part of my reason to split it up is hope that smaller PRs might be shippable faster. Stability is hard to predict without feedback! It works fine according to my testing, but I'm likely overlooking something 😅

Refactored out the common base styles for tests that don't need to target them explicitly to make maintaining these tests easier.
@aaronrobertshaw
Copy link
Contributor

I've pushed a few fixes for the theme.json and global styles tests which now include a small refactor to make it easier to keep them up-to-date with our changes here.

@@ -2,6 +2,6 @@
@include caption-style-theme();
}

.wp-block-audio {
:where(.wp-block-audio) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why these particular changes are necessary (block styles classnames)? I admit it's a bit hard to follow the reasoning of the whole 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.

Yes! So this PR reduces the specificity of block global styles by wrapping their selectors in :where(). With that change, the margins set in these block-library files now have higher specificity than the global styles, so it would appear that the global styles margins have no effect.

That made it necessary to reduce the specificity of these styles, as they shouldn't be allowed to override anything theme- or user-defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this impact third-party blocks using this kind of styles as well?

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 not sure I understand. Would third party blocks use core block-library styles at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean some third-party blocks might be using .my-block { margin: something } and with the changes being done to theme.json style generation, the styles of block will be more specific and taking over (even if the users changes the margin in global styles for instance)

Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible to do this @import url('example.css') layer(<layer-name>); to layer an entire stylesheet. So worth exploring whether we can update the "link" of the stylesheets that we want to auto-later with that. There's a proposal to add layer directly to <link but it's not finalized yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I mentioned in my comment above, I think an initial implementation of layers could include only core CSS (such as the block library styles) and generated CSS that's meant to be low specificity (such as global styles and block supports).

User-defined styles on specific blocks should be excluded from this as we always want them to override anything else, and theme/plugin enqueued stylesheets should almost always override core styles. I guess an exception here might be third party block stylesheets: should they be treated like core block stylesheets?

I'm not sure we should be using @import for stylesheets at all because it forces stylesheets to be loaded sequentially, which can have quite an impact on performance. There are some workarounds but I'm not sure any of them are 100% safe 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

It does seem like regardless of the outcome of the current PR, we should be exploring CSS layers. That said, it's clear that it's a big undertaking, so if you all think we should move forward with the current PR, I'm fine with that.

Let's make sure we keep an eye on the feedback and the impact though.

Copy link
Member

Choose a reason for hiding this comment

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

I also agree that we should definitly investigate CSS Layers. The thing I want to call out though that has always prevented me from persuing it further is that fudamentally there is no great fallback for browsers that don't support layers.

We do have pretty decent browser supoport these days. But I think there is a big difference between features that fall back easily such as for example text-wrap: balance. If the brower doesn't support that, it just falls back to use another value.

If the browser doesn't support layers or container queries etc it cannot fallback to anything really and so the outcome is a very bad one.

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 do think we should move forward with the current PR regardless of any investigation into layers (which is fine to do in principle - we should try new stuff out - but I suspect the fact that at some point we'll have to rely on @importing third party stylesheets will prove a blocker to actually shipping it)

The potential breaking changes will be similar whether we use layers or not, so I think it would be good to come to an agreement on style hierarchy regardless of the approach. Most changes in this PR have so far been uncontroversial; the one unresolved issue is how to manage third party block styles vs global styles.

As I said above, I'm not sure this will be a major issue because the only conflict we've found so far is with blocks that:

  • provide their own styles and simultaneously offer global styles support AND
  • provide default styles in the block stylesheet for the same properties that can be changed in global styles

In my testing, I couldn't find any blocks that did both these things.

In any case, this will have to be clearly announced as a breaking change so block devs have the chance to make any necessary tweaks to their plugins in advance.

@tellthemachines
Copy link
Contributor Author

Thanks for all the feedback so far folks! This PR has become a bit of a monster so I'm starting to think it might be better to split it into multiple, more easy to review PRs. I'm thinking something like:

  • changes to block-library files (this one should go first as the rest of the changes need it)
  • changes to global styles specificity
  • changes to layout specificity

@aaronrobertshaw
Copy link
Contributor

It might be good to add this PR's efforts to the discussion over on #55829.

@fabiankaegy
Copy link
Member

Just tested this on a large custom build project and it doesn't break as much as I had imagined 🎉

One thing I noticed is this:

The Global styles generated by the Group block flex layout controls no longer override the base flex styles.

Before After
CleanShot 2024-02-28 at 08 18 22@2x CleanShot 2024-02-28 at 08 20 05@2x

(The class .wp-container-core-group-is-layout-4 looses again the body .is-layout-flex. Before the update this was tackled by duplicating the gobal styles selector .wp-container-core-group-is-layout-4.wp-container-core-group-is-layout-4)

@fabiankaegy
Copy link
Member

Also pinging the @WordPress/outreach group here to see if anyone else is able to provide some more real world testing :)

@tellthemachines
Copy link
Contributor Author

The Global styles generated by the Group block flex layout controls no longer override the base flex styles.

Oh well spotted @fabiankaegy! I'm thinking that could be fixed by removing body from the root layout selector. I'll give that a try when I split out this PR into smaller ones, which I'm getting started on today!

@tellthemachines
Copy link
Contributor Author

#59457 and #60106 are merged, and I've now opened #60228 for the final part of the changes, so am going to close this PR.

Thanks everyone for the feedback, and any testing on #60228 is appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Testing Needs further testing to be confirmed. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants