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

Editor styles: if scope is needed, don't increase specificity #56649

Closed
wants to merge 5 commits into from

Conversation

ellatrix
Copy link
Member

What?

Previously:

Currently, when the editor is iframed (most cases), we don't scope editor styles. Now the problem is that when the styles do need to be scoped in a non iframed editor, all the editor styles' specificity is bumped as well.

Why?

There's cases in block editor.css stylesheets where the extra .editor-styles-wrapper is needed to override other styles.

It's also better to keep the specificity of the editor styles css rules the same between the iframed and non iframed editor.

How?

We can use :where() to avoid adding specificity.

Testing Instructions

To trigger a non iframed editor, run this in the console:

wp.blocks.registerBlockType( 'test/v2', { apiVersion: 2, title: 'test' } );

Alternatively you could enable a plugin that adds meta boxes.

Testing Instructions for Keyboard

Screenshots or screencast

@ellatrix ellatrix added [Type] Bug An existing feature does not function as intended [Package] Block editor /packages/block-editor CSS Styling Related to editor and front end styles, CSS-specific issues. labels Nov 29, 2023
Copy link

github-actions bot commented Nov 29, 2023

Size Change: +18.2 kB (+1%)

Total Size: 1.73 MB

Filename Size Change
build/annotations/index.min.js 2.27 kB -424 B (-16%) 👏
build/block-directory/index.min.js 7.26 kB +36 B (0%)
build/block-editor/content-rtl.css 4.46 kB +55 B (+1%)
build/block-editor/content.css 4.46 kB +59 B (+1%)
build/block-editor/index.min.js 254 kB +1.78 kB (+1%)
build/block-editor/style-rtl.css 15.6 kB +2 B (0%)
build/block-editor/style.css 15.6 kB -3 B (0%)
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 +7 B (0%)
build/block-library/blocks/cover/style.css 1.69 kB +7 B (0%)
build/block-library/blocks/details/style-rtl.css 86 B -12 B (-12%) 👏
build/block-library/blocks/details/style.css 86 B -12 B (-12%) 👏
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/file/editor-rtl.css 326 B +10 B (+3%)
build/block-library/blocks/file/editor.css 327 B +11 B (+3%)
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/view.min.js 1.03 kB +14 B (+1%)
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/search/style-rtl.css 690 B +61 B (+10%) ⚠️
build/block-library/blocks/search/style.css 689 B +61 B (+10%) ⚠️
build/block-library/blocks/social-links/editor-rtl.css 676 B -6 B (-1%)
build/block-library/blocks/social-links/editor.css 675 B -6 B (-1%)
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/editor-rtl.css 431 B +28 B (+7%) 🔍
build/block-library/blocks/template-part/editor.css 431 B +28 B (+7%) 🔍
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.4 kB +31 B (0%)
build/block-library/editor.css 12.4 kB +32 B (0%)
build/block-library/index.min.js 218 kB +860 B (0%)
build/block-library/style-rtl.css 14.8 kB +31 B (0%)
build/block-library/style.css 14.8 kB +27 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.5 kB -249 B (0%)
build/commands/index.min.js 15.2 kB -405 B (-3%)
build/commands/style-rtl.css 956 B +21 B (+2%)
build/commands/style.css 953 B +23 B (+2%)
build/components/index.min.js 222 kB -1.25 kB (-1%)
build/components/style-rtl.css 11.9 kB +20 B (0%)
build/components/style.css 11.9 kB +19 B (0%)
build/core-data/index.min.js 72.5 kB -261 B (0%)
build/customize-widgets/index.min.js 11.2 kB +26 B (0%)
build/data/index.min.js 9 kB +56 B (+1%)
build/edit-post/classic-rtl.css 578 B +20 B (+4%)
build/edit-post/classic.css 579 B +21 B (+4%)
build/edit-post/index.min.js 23.2 kB -928 B (-4%)
build/edit-post/style-rtl.css 5.5 kB -72 B (-1%)
build/edit-post/style.css 5.5 kB -71 B (-1%)
build/edit-site/index.min.js 232 kB +15.2 kB (+7%) 🔍
build/edit-site/style-rtl.css 15.1 kB +123 B (+1%)
build/edit-site/style.css 15.1 kB +123 B (+1%)
build/edit-widgets/index.min.js 17.4 kB +75 B (0%)
build/edit-widgets/style-rtl.css 4.15 kB -13 B (0%)
build/edit-widgets/style.css 4.15 kB -13 B (0%)
build/editor/index.min.js 67.4 kB +3.65 kB (+6%) 🔍
build/editor/style-rtl.css 5.46 kB +105 B (+2%)
build/editor/style.css 5.46 kB +106 B (+2%)
build/format-library/index.min.js 8.11 kB +85 B (+1%)
build/interactivity/index.min.js 13 kB +6 B (0%)
build/interactivity/navigation.min.js 1.17 kB +17 B (+1%)
build/keyboard-shortcuts/index.min.js 1.3 kB -438 B (-25%) 🎉
build/media-utils/index.min.js 2.92 kB +5 B (0%)
build/nux/index.min.js 1.57 kB -429 B (-22%) 🎉
build/patterns/index.min.js 5.91 kB +192 B (+3%)
build/preferences-persistence/index.min.js 2.06 kB +6 B (0%)
build/preferences/index.min.js 2.83 kB +25 B (+1%)
build/reusable-blocks/index.min.js 2.73 kB +5 B (0%)
build/rich-text/index.min.js 10 kB -409 B (-4%)
build/router/index.min.js 1.88 kB +90 B (+5%) 🔍
build/server-side-render/index.min.js 1.96 kB +4 B (0%)
build/style-engine/index.min.js 2.03 kB -68 B (-3%)
build/url/index.min.js 3.74 kB +14 B (0%)
build/vendors/react-dom.min.js 41.7 kB -52 B (0%)
build/widgets/index.min.js 7.23 kB +22 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
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/style-rtl.css 1.03 kB
build/block-directory/style.css 1.03 kB
build/block-editor/default-editor-styles-rtl.css 394 B
build/block-editor/default-editor-styles.css 394 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/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/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 647 B
build/block-library/blocks/group/editor.css 647 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/editor-rtl.css 878 B
build/block-library/blocks/image/editor.css 878 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 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 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/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/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/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.48 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/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.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/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/compose/index.min.js 12.6 kB
build/core-commands/index.min.js 2.77 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/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/element/index.min.js 4.83 kB
build/escape-html/index.min.js 537 B
build/format-library/style-rtl.css 492 B
build/format-library/style.css 490 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/query.min.js 740 B
build/interactivity/router.min.js 1.36 kB
build/interactivity/search.min.js 618 B
build/is-shallow-equal/index.min.js 527 B
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 849 B
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 948 B
build/nux/style-rtl.css 747 B
build/nux/style.css 742 B
build/patterns/style-rtl.css 553 B
build/patterns/style.css 552 B
build/plugins/index.min.js 1.8 kB
build/preferences/style-rtl.css 710 B
build/preferences/style.css 712 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/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/shortcode/index.min.js 1.39 kB
build/token-list/index.min.js 582 B
build/vendors/inert-polyfill.min.js 2.48 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/style-rtl.css 1.17 kB
build/widgets/style.css 1.17 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

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.

The code change looks good although I have one quick question.

Should we also be wrapping the .editor-styles-wrapper class in :where for the Additional CSS control in the Advanced panel?

Also, following the test instructions and registering a v2 block via the console didn't seem to result in a non-iframed editor for me. I ended up testing by enabling custom fields through the post editor's preferences.

Once I got a non-iframed editor, the .editor-styles-wrapper class was wrapped in a :where.

Screenshot 2023-11-30 at 11 28 50 am

It might pay to get a second set of eyes on this in case I've missed testing something.

When this lands, I take it the next steps will be to cull the uses of .editor-styles-wrapper from places like block editor.scss stylesheets? Do we plan to do that on a block-by-block basis?

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

This seems to be working well for me, too!

One potential concern — while this reduces the specificity of when .editor-styles-wrapper is injected, what happens for rules that were originally against body, but now have the reduced specificity of :where(.editor-styles-wrapper)?

For example, in the iframed editor, the following rules are output for TT4 via body (0,0,1) specificity:

image

When not iframed, these rules now have specificity of (0,0,0):

image

In practice this doesn't appear to cause issues with the core themes I've tested with (TT4, TT3), but could it potentially cause issues for themes out in the wild that have rules that were expected to be overwritten by rules attached to body, but might no longer be if the scoped styles are reduced in specificity?

Or to put it differently, the idea of this PR sounds good to me, but how do we determine whether it could be a breaking change for folks? 🤔

@@ -88,7 +88,7 @@ export default function EditorStyles( { styles, scope } ) {
return [
transformStyles(
_styles.filter( ( style ) => style?.css ),
scope
scope ? `:where(${ scope })` : undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a non-blocking question: is it better to do this internally within EditorStyles or would there be any benefit of having the consumer pass in :where(.editor-styles-wrapper) explicitly for the scope?

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the intention behind scope is to make sure there's no bleed of content styles into the editor chrome, I think it makes sense for the scoping selector to always have 0 specificity. This also helps ensure the specificity will always be the same between editor and front end.

@carolinan carolinan requested a review from cbirdsong November 30, 2023 07:27
@cbirdsong
Copy link

Personally I can't imagine what theme would've been built expecting .editor-styles-wrapper to win out over body, but if we really want it to remain the same it could be div:where(.editor-styles-wrapper)?

However, there are also far more specific ones than simply replacing body. Something like .editor-styles-wrapper .wp-site-blocks > .alignleft would go from 0,3,0 to 0,0,0 if the whole thing was wrapped in :where(). Does that happen now?

@sabernhardt
Copy link
Contributor

Related: #57176

Copy link

github-actions bot commented Mar 15, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: iansvo <iansvo@git.wordpress.org>
Co-authored-by: cbirdsong <cbirdsong@git.wordpress.org>
Co-authored-by: sabernhardt <sabernhardt@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@tellthemachines tellthemachines force-pushed the try/editor-style-scope-without-specificity branch from caa0c53 to ee81eff Compare March 15, 2024 05:57
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

This PR solves https://core.trac.wordpress.org/ticket/60614 and seems like a good idea in principle, so giving it a round of testing! I rebased the branch because the node version was updated since this PR was made, and also to test with other recent changes.

I've found a couple of issues with block layout styles in the non-iframed post editor.

  • The gallery block has an overly specific fallback display style which isn't playing well with this specificity reduction (I think ideally we'd reduce the specificity for that selector too)
  • The .wp-container- layout styles aren't being output at all. Not sure why this change would cause that to happen, but testing with a Row or Stack block, any non-default styles aren't being applied.

non-iframed post editor on trunk:
Screenshot 2024-03-15 at 5 08 42 PM

non-iframed post editor on this branch:

Screenshot 2024-03-15 at 5 14 35 PM

(the two images are a Gallery block)

@tellthemachines
Copy link
Contributor

Oh, I see what the problem is: layout styles are still manually adding .editor-styles-wrapper, and when we change the selector passed to transformStyles to :where(.editor-styles-wrapper) it's no longer recognised as the same, so it's not deduped, so effectively the selector becomes :where(.editor-styles-wrapper) .editor-styles-wrapper .wp-container-core-group-is-layout-1.wp-container-core-group-is-layout-1 and it doesn't apply.

Unfortunately, even though the reset styles that selector was originally added to override now have minimal specificity, it's still enough to override the default layout styles if .editor-styles-wrapper is wrapped in :where():

Screenshot 2024-03-25 at 2 40 48 PM

so I think we might still need this selector to deliver a small specificity bump.

My suggestion would be to do something like div:where(.editor-styles-wrapper), but in that case it's probably better to make it editor-specific as per @andrewserong's suggestion above, to avoid breaking other possible instances of EditorStyles. In order for this to work, we'd also need to remove the selector from the layout styles. I'm happy to update this PR myself if that solution sounds good!

@tellthemachines
Copy link
Contributor

Ok I've updated the PR with the solution outlined above so we can test it more easily.

@andrewserong
Copy link
Contributor

Thanks for updating @tellthemachines! While testing, I thought at first that this PR lowered the specificity too much and could potentially cause TT1 to not display the layout rules correctly, but after testing on trunk, I think that's a theme issue specific to TT1 as a result of it including a rule to set the Group block to display: flow-root, so is likely unrelated to this PR? Here's a quick screenshot — the Row block doesn't display in a row for that classic theme:

image

Overall, I like the idea of passing in the desired scope for the editor styles in BlockCanvas, specific to the writing flow's classname attached on a div. I'm not noticing any visual issues compared with trunk so far in my testing 👍. It'd be good to double-check with @ellatrix about the direction, though.

It looks like some of the layout logic's unit tests are failing, I think the expected styling just needs updating from this line onwards, for getBlockGapCSS and appendSelectors.

@tellthemachines
Copy link
Contributor

tellthemachines commented Mar 26, 2024

Thanks for reviewing and testing, @andrewserong!

I think that's a theme issue specific to TT1 as a result of it including a rule to set the Group block to display: flow-root, so is likely unrelated to this PR?

Hmm, are you on an older version of WP? I remember that being an issue on TT1 a while ago but it has since been fixed (I don't see the rule containing display: flow-root at all in the editor, only on the front end). For reference my local env is 6.5-alpha-57203 and my version of TT1 is 2.0.

I'll leave test updating until we're reasonably sure this is the way forward to avoid unnecessary work 😅

@andrewserong
Copy link
Contributor

Hmm, are you on an older version of WP?

Ah, yes, of course! My bad. I run a few different local environments and I was on 6.4.3 with TT1 2.0. In my 6.5-RC3 + TT1 2.1 environment, this works fine 👍

@tellthemachines
Copy link
Contributor

OK @ellatrix told me she's fine with my hijacking of her PR 😄 and there don't seem to be any further objections, so I'll go ahead with updating the tests now!

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 pushing this one forward @tellthemachines 👍

It's looking pretty close to me.

Button outline issue is resolved on this branch
✅ Gallery block displays correctly
div:where(.editor-styles-wrapper) selector is used in generated styles (with one exception)
✅ Unit tests are passing
✅ Could not see any differences for blocks between iframed and non-iframed editors

As noted earlier, there's one more place I think that needs the switch from .editor-styles-wrapper to div:where(.editor-styles-wrapper).

The custom CSS feature wraps raw CSS, e.g. background: blue, in .editor-styles-wrapper. If I understand how this all fits together we just need to tweak the on change and blur handlers.

@tellthemachines
Copy link
Contributor

As noted earlier, there's one more place I think that needs the switch from .editor-styles-wrapper to div:where(.editor-styles-wrapper).

The custom CSS feature wraps raw CSS, e.g. background: blue, in .editor-styles-wrapper. If I understand how this all fits together we just need to tweak the on change and blur handlers.

Hmm, adding custom CSS both in the top-level "Additional CSS" field in global styles and in the block-specific ones generates correctly scoped selectors in the non-iframed editor:

Screenshot 2024-03-28 at 11 54 07 AM

Am I missing something here?

@aaronrobertshaw
Copy link
Contributor

Am I missing something here?

Try without a selector in the top-level Additional CSS e.g. styles for whatever the root selector should be. You can use exactly the CSS quoted, background: blue.

@tellthemachines
Copy link
Contributor

Try without a selector in the top-level Additional CSS e.g. styles for whatever the root selector should be. You can use exactly the CSS quoted, background: blue.

I definitely must be missing something 😅

Adding just styles without a selector in the top level Additional CSS produces no output for me. I'm trying on trunk too, with the same result. Testing with TT4, both with a style variation and the default, neither of which have top-level CSS declared in theme.json.

@andrewserong
Copy link
Contributor

andrewserong commented Mar 28, 2024

My testing resulted in the same as @tellthemachines (root Additional CSS in global styles appears to require selectors, block-level in global styles does not). Output and scoping of root Additional CSS using body { background: blue; } seems to work as expected, and simple background: blue; added at the Group block in global styles is also working for me, with the appropriate selectors being automatically added.

The custom CSS feature wraps raw CSS, e.g. background: blue, in .editor-styles-wrapper. If I understand how this all fits together we just need to tweak the on change and blur handlers.

From a little digging, I think what's happening with these blur and change handlers is a little deceptive. These handlers aren't adding any scoping to the output of the CSS rules, but rather the .editor-styles-wrapper classname is used for CSS validation. When a user goes to add a simple rule without a selector, like background: blue;, the blur and change handlers call transformStyles, passing in .editor-styles-wrapper, however the returned value is only used to determine whether or not to show a warning about the CSS structure, to check if what's been entered is valid CSS. The value is otherwise not used anywhere. From looking at the transformStyle function, I believe the wrapper selector is only passed in so that the function will execute with wrapped CSS rules.

So, I think the confusion here is that the .editor-styles-wrapper that gets passed in to transformStyles could be any classname in order for the validation to occur, that just happens to be the one that's used. Perhaps a clearer string to pass would be something like .test-class-name-for-validation or something like that, but we likely don't need to worry about changing that in this PR?

From manual testing, I can see that root Additional CSS rules are output on the site frontend with no additional scoping (so the rules don't apply anywhere), so it looks like there isn't (yet) a feature for automatically wrapping root CSS rules:

image

In PHP, the output in get_base_custom_css doesn't add any wrapping selectors, but the processing in get_block_custom_css_nodes does for block-level-in-global-styles custom css.


Apologies that was all a bit densely worded! In case that doesn't make sense reading it in long-form, the TL;DR:

  • I think the Additional CSS change and blur handlers are only using the wrapping selector for CSS validation and not output — they can use any selector so it doesn't appear to affect anything in this PR.
  • Root Additional CSS doesn't appear to get any magically wrapped selectors, so the CSS entered there is output as-is.
  • Separately to this PR, it could be good to clarify the selectors in the Additional CSS code so that our future selves don't get confused when we encounter this selector again.

There is every chance I might have missed some details in my reading there (or be way off in my understanding), so please double-check my findings 🙂

I'm at the end of my week now, but happy to give this PR another test next week. For now, it sounds like it might not need any further changes?

@tellthemachines
Copy link
Contributor

From a little digging, I think what's happening with these blur and change handlers is a little deceptive. These handlers aren't adding any scoping to the output of the CSS rules, but rather the .editor-styles-wrapper classname is used for CSS validation.

Yes, I was just having a closer look at that code and your assessment matches mine! I don't think further action is needed here. Thanks for looking into it!

@aaronrobertshaw
Copy link
Contributor

aaronrobertshaw commented Mar 28, 2024

Thanks for digging deeper and clarifying what is happening there 👍

I've had another quick look to see where some of the .editor-styles-wrapper selectors I was seeing were coming from. It looks like they're from the elements block support here.

Screenshot 2024-03-28 at 3 23 06 PM

@@ -38,7 +38,7 @@ export function ExperimentalBlockCanvas( {
>
<EditorStyles
styles={ styles }
scope=".editor-styles-wrapper"
scope="div:where(.editor-styles-wrapper)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
scope="div:where(.editor-styles-wrapper)"
scope=":where(.editor-styles-wrapper)"

This selector doesn't match when the iframe preview is active (class is applied to body, not a div). We can just remove the tag from the selector and it will work just as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

The selector doesn't need to match the iframed state, because this instance of EditorStyles only renders when there's no iframe.

This comment explains why the increased specificity provided by the div selector is necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could we add a comment inline?

Copy link
Contributor

Choose a reason for hiding this comment

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

When testing in 6.5, this selector was still being applied even with the iframe preview. It seemed like the intent of this PR was to ensure it's always available no matter if the iframe preview is in use or not. In it's current form, this will break if it applies to an iframe, since the iframe markup has this class on the body and not a div.

If the intended behavior is for this to only show without an iframe preview, then it appears there's a bug somewhere. I replicated this yesterday with this branch checkout and the latest 6.5 RC (4, I believe).

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment added!

this selector was still being applied even with the iframe preview

Do you mean .editor-styles-wrapper or div:where(.editor-styles-wrapper)? If the latter, could you please provide detailed reproduction steps? The change in this PR is exclusively targeting the non-iframed editor. However, .editor-styles-wrapper may still be in use in the iframed editor.

@tellthemachines
Copy link
Contributor

I've had another quick look to see where some of the .editor-styles-wrapper selectors I was seeing were coming from. It looks like their from the elements block support here.

Thanks for tracking that down! This is a similar case to the .editor-styles-wrapper instance I removed from the layout styles. I've removed this one too, because it's no longer needed after the global styles specificity reduction.

The downside is that after these changes I'm no longer 100% sure this patch will be suitable for a WP minor release. Looking into it now.

@tellthemachines
Copy link
Contributor

The downside is that after these changes I'm no longer 100% sure this patch will be suitable for a WP minor release. Looking into it now.

Ok I tested both layout and element styles applied to block instances, which is where the .editor-styles-wrapper selectors removed in this PR were being applied, and from removing the selector manually in the inspector styles still seem to apply ok. I checked element styles with a link style in a Paragraph block, and custom settings for constrained/flex layouts in Group blocks. Element styles without the additional selector now have exactly the same specificity as global element styles, but the order they are output in ensures the block instance style prevails.

@tellthemachines
Copy link
Contributor

Does this PR still make sense to pursue after the recent specificity changes? The issue it was proposed as a fix for has been otherwise resolved.

@ellatrix
Copy link
Member Author

I think this should still be done, but with :where(.editor-styles-wrapper). If the styles are loaded outside an iframe, it should have the same specificity as styles inside the iframe.

@talldan
Copy link
Contributor

talldan commented Aug 15, 2024

Just found this issue. There's another bug that's arisen recently - #63925 that might fall under this umbrella.

One of my concerns (not with this PR, but generally) is the way the prefixer works. Usually it prefixes, but for root selectors It replaces the root part of the selector. It can create inconsistency since some styles end up with specificity bumps while others don't.

An example is that what's proposed in this PR would mean a style like :root :where(.some-selector) becomes div:where(.editor-styles-wrapper) where(.some-selector), reducing its specificity rather than keeping it the same. What's in trunk also changes the specificity of selectors beginning with body and html to be completely different.

I was recently looking at an alternative prefixing library in this PR - CSS transformation: Fix mangled selectors by switching to a different postcss plugin for prefixing. It has a callback that runs for each selector, and would allow us to change how prefixing works per selector. We could try switching to that library or propose something like that in postcss-prefixwrap (if the maintainer is receptive) for less disruption.

The idea could be to transform selectors like this:

  • :root :where(.some-selector) becomes :root :where(.editor-visual-styles) :where(.some-selector)
  • body :where(.some-selector) becomes body :where(.editor-visual-styles) :where(.some-selector)
  • html :where(.some-selector) becomes html :where(.editor-visual-styles) :where(.some-selector)
  • All other selectors are prefixed normally with :where(.editor-visual-styles)... e.g.:
    • h1 becomes :where(.editor-visual-styles) h1
    • .some-class-name becomes :where(.editor-visual-styles) .some-class-name

I think that could maintain specificity and ensure individual selectors are relative to one another.

@talldan
Copy link
Contributor

talldan commented Aug 15, 2024

I've put together a proof of concept of the above in #64534

@talldan
Copy link
Contributor

talldan commented Aug 28, 2024

I'll close this as #64534 has now been merged.

@talldan talldan closed this Aug 28, 2024
@talldan talldan deleted the try/editor-style-scope-without-specificity branch August 28, 2024 04:12
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. [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants