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

Global Styles: Fix Separator block color use #67269

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

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Nov 25, 2024

Related:

What?

This PR removes problematic fudging of Separator block style declarations in favour of filtering the actual theme.json data at both the theme and user origin levels within the theme.json resolver. This approach improves color consistency and flexibility across both origins while also making the Separator block styles more filterable and standardized.

Why?

Global Styles currently only sets a single property in the user origin theme.json data, background. This means if a theme sets the border.color or color.text property, the background color isn't applied consistently.

How?

  • Remove hack tweaking style declarations in favour of theme.json data based approach
  • Tweak Separator block style data based on data origin (theme vs user) to provide expected behaviour e.g. user color selection in Global Styles being honoured.
Detailed Breakdown

lib/class-wp-theme-json-gutenberg.php

  • Removed bespoke function fudging style declarations for separator block.
  • This is now handled by filtering the theme origin data in the theme.json resolver. See WP_Theme_JSON_Resolver::get_theme_data()

lib/class-wp-theme-json-resolver-gutenberg.php

  • Separator data is now tweaked at both the user (get_user_data) and theme (get_theme_data) level.
  • User origin data is tweak such that if a user has selected a color that color is used in all color paths the Separator block might require (i.e. color.background, color.text, or border.color)
  • Theme origin data is tweaked so that if a color.background value has been defined it is used as a fallback for color.text and border.color if they haven't been defined.
  • These tweaks to the theme.json data have been done within the resolver here to avoid the overhead of filters.

packages/block-editor/src/components/global-styles/use-global-styles-output.js

  • The old hack modifying theme.json data on the fly when generating Global Styles output has been removed as it only related to the theme origin data (hence the global styles bug) and is now covered by the theme.json resolver update at the theme origin level.
  • An added benefit of tweaking the Separator style data in the resolver is that it becomes filterable too by extenders which is likely expected.

packages/editor/src/components/global-styles-provider/index.js

  • The Global Styles provider was updated to handle tweaking user origin data in the same fashion as the theme.json resolver.
  • This JS change is required because the editor needs to handle unsaved changes to Global Styles that the user has made. This changes aren't passed through the PHP theme.json resolver until they are saved.

phpunit/class-wp-theme-json-resolver-test.php

  • New unit tests were added to cover the tweaking of Separator style data in the theme.json resolver.

phpunit/class-wp-theme-json-test.php

  • The old unit test for the bespoke function handling the fudging of separator style declarations in the theme.json class has been removed. This is now covered by the resolver tests.
Initial context from early explorations into a fix

Approach

The initial idea was to enforce the user selected color from Global Styles, i.e. background in the user origin. That evolved to perhaps do so in a way that wouldn't mean that it was also saved to the CPT. This didn't really seem achievable as it would mean having to instantiate additional WP_Theme_JSON_Gutenberg instances which come with not insignificant overhead.

To simply have something for testing purposes, I tweaked the retrieval of user origin data in the theme.json resolver class and where the user and theme origin data is merged on the JS side. If we pursue an approach of enforcing the background color across multiple properties, the points at which it is done in JS and PHP should be the same e.g. during merge, or retrieval of user data etc.

The same consistency should also be applied to the existing fudging of separator data in useGlobalStylesOutput and the style declarations in WP_Theme_JSON_Gutenberg.

Alternatives

  1. On the PHP side, the Separator block could add a wp_theme_json_data_user filter and set things there. The equivalent in JS could be done in useGlobalStylesContext or useGlobalStylesUserConfig.
  2. Another hack could be to add Separator specific code to the Global Styles color panel. When setting the background color there, update all the appropriate style values. Then there'd be no tweaking before merging required.

Testing Instructions

  1. Activate a theme that defines Separator styles using border or text color e.g. TT4 or TT5.
  2. Edit a post, page, or template, adding multiple Separator blocks
  3. Assign different block styles to each e.g. dots, wide etc.
  4. Navigate to Global Styles > Blocks and set a background color for the Separator block
  5. Inspect the Separator blocks in the editor and ensurje that they get all three color properties styled i.e. background, border-color, and color.
  6. Save and view on the frontend.
  7. Repeat the process of checking the applied styles. All three should be present there as well.
  8. Back in the editor double-check that setting block instance styles on the Separator blocks works as per trunk.

Replicating original issue on trunk

  • Use TT5
  • Assign a light or bright color to the Separator block in Global Styles
  • Note that you can still see the theme set dark color over the top of the color you selected and not at all for a block with the Dots block style selected

Screenshots or screencast

Excuse the bright yellow color in these screenshots, it was the easiest option to highlight the pre-existing theme.json color impacting the Global Styles selection.

Before

Screenshot 2024-11-25 at 6 47 36 pm

After

Screenshot 2024-11-25 at 6 48 31 pm

@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended [Block] Separator Affects the Separator Block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Nov 25, 2024
@aaronrobertshaw aaronrobertshaw self-assigned this Nov 25, 2024
Copy link

github-actions bot commented Nov 25, 2024

Size Change: +1 B (0%)

Total Size: 1.83 MB

Filename Size Change
build/block-editor/index.min.js 258 kB -128 B (-0.05%)
build/block-library/blocks/separator/style-rtl.css 266 B +18 B (+7.26%) 🔍
build/block-library/blocks/separator/style.css 266 B +18 B (+7.26%) 🔍
build/block-library/style-rtl.css 15 kB +15 B (+0.1%)
build/block-library/style.css 15 kB +14 B (+0.09%)
build/editor/index.min.js 114 kB +64 B (+0.06%)
ℹ️ View Unchanged
Filename Size
build-module/a11y/index.min.js 482 B
build-module/block-library/file/view.min.js 447 B
build-module/block-library/image/view.min.js 1.78 kB
build-module/block-library/navigation/view.min.js 1.16 kB
build-module/block-library/query/view.min.js 742 B
build-module/block-library/search/view.min.js 616 B
build-module/interactivity-router/index.min.js 3.03 kB
build-module/interactivity/debug.min.js 17.2 kB
build-module/interactivity/index.min.js 13.6 kB
build/a11y/index.min.js 952 B
build/annotations/index.min.js 2.26 kB
build/api-fetch/index.min.js 2.32 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 579 B
build/block-directory/index.min.js 7.26 kB
build/block-directory/style-rtl.css 1 kB
build/block-directory/style.css 1 kB
build/block-editor/content-rtl.css 4.47 kB
build/block-editor/content.css 4.46 kB
build/block-editor/default-editor-styles-rtl.css 394 B
build/block-editor/default-editor-styles.css 394 B
build/block-editor/style-rtl.css 15.7 kB
build/block-editor/style.css 15.7 kB
build/block-library/blocks/archives/editor-rtl.css 84 B
build/block-library/blocks/archives/editor.css 83 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 149 B
build/block-library/blocks/audio/editor.css 151 B
build/block-library/blocks/audio/style-rtl.css 132 B
build/block-library/blocks/audio/style.css 132 B
build/block-library/blocks/audio/theme-rtl.css 134 B
build/block-library/blocks/audio/theme.css 134 B
build/block-library/blocks/avatar/editor-rtl.css 115 B
build/block-library/blocks/avatar/editor.css 115 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/button/editor-rtl.css 265 B
build/block-library/blocks/button/editor.css 265 B
build/block-library/blocks/button/style-rtl.css 555 B
build/block-library/blocks/button/style.css 555 B
build/block-library/blocks/buttons/editor-rtl.css 291 B
build/block-library/blocks/buttons/editor.css 291 B
build/block-library/blocks/buttons/style-rtl.css 345 B
build/block-library/blocks/buttons/style.css 345 B
build/block-library/blocks/calendar/style-rtl.css 240 B
build/block-library/blocks/calendar/style.css 240 B
build/block-library/blocks/categories/editor-rtl.css 132 B
build/block-library/blocks/categories/editor.css 131 B
build/block-library/blocks/categories/style-rtl.css 152 B
build/block-library/blocks/categories/style.css 152 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 139 B
build/block-library/blocks/code/style.css 139 B
build/block-library/blocks/code/theme-rtl.css 122 B
build/block-library/blocks/code/theme.css 122 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 420 B
build/block-library/blocks/columns/style.css 420 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 124 B
build/block-library/blocks/comment-author-avatar/editor.css 124 B
build/block-library/blocks/comment-author-name/style-rtl.css 72 B
build/block-library/blocks/comment-author-name/style.css 72 B
build/block-library/blocks/comment-content/style-rtl.css 120 B
build/block-library/blocks/comment-content/style.css 120 B
build/block-library/blocks/comment-date/style-rtl.css 65 B
build/block-library/blocks/comment-date/style.css 65 B
build/block-library/blocks/comment-edit-link/style-rtl.css 70 B
build/block-library/blocks/comment-edit-link/style.css 70 B
build/block-library/blocks/comment-reply-link/style-rtl.css 71 B
build/block-library/blocks/comment-reply-link/style.css 71 B
build/block-library/blocks/comment-template/style-rtl.css 200 B
build/block-library/blocks/comment-template/style.css 199 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 238 B
build/block-library/blocks/comments-pagination/editor.css 231 B
build/block-library/blocks/comments-pagination/style-rtl.css 245 B
build/block-library/blocks/comments-pagination/style.css 241 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 837 B
build/block-library/blocks/comments/editor.css 836 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 637 B
build/block-library/blocks/cover/editor-rtl.css 631 B
build/block-library/blocks/cover/editor.css 631 B
build/block-library/blocks/cover/style-rtl.css 1.7 kB
build/block-library/blocks/cover/style.css 1.69 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 86 B
build/block-library/blocks/details/style.css 86 B
build/block-library/blocks/embed/editor-rtl.css 331 B
build/block-library/blocks/embed/editor.css 331 B
build/block-library/blocks/embed/style-rtl.css 419 B
build/block-library/blocks/embed/style.css 419 B
build/block-library/blocks/embed/theme-rtl.css 133 B
build/block-library/blocks/embed/theme.css 133 B
build/block-library/blocks/file/editor-rtl.css 326 B
build/block-library/blocks/file/editor.css 326 B
build/block-library/blocks/file/style-rtl.css 278 B
build/block-library/blocks/file/style.css 279 B
build/block-library/blocks/footnotes/style-rtl.css 198 B
build/block-library/blocks/footnotes/style.css 197 B
build/block-library/blocks/form-input/editor-rtl.css 229 B
build/block-library/blocks/form-input/editor.css 229 B
build/block-library/blocks/form-input/style-rtl.css 357 B
build/block-library/blocks/form-input/style.css 357 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 344 B
build/block-library/blocks/form-submission-notification/editor.css 341 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 470 B
build/block-library/blocks/freeform/editor-rtl.css 2.6 kB
build/block-library/blocks/freeform/editor.css 2.6 kB
build/block-library/blocks/gallery/editor-rtl.css 946 B
build/block-library/blocks/gallery/editor.css 951 B
build/block-library/blocks/gallery/style-rtl.css 1.83 kB
build/block-library/blocks/gallery/style.css 1.82 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 334 B
build/block-library/blocks/group/editor.css 334 B
build/block-library/blocks/group/style-rtl.css 103 B
build/block-library/blocks/group/style.css 103 B
build/block-library/blocks/group/theme-rtl.css 79 B
build/block-library/blocks/group/theme.css 79 B
build/block-library/blocks/heading/style-rtl.css 188 B
build/block-library/blocks/heading/style.css 188 B
build/block-library/blocks/html/editor-rtl.css 346 B
build/block-library/blocks/html/editor.css 347 B
build/block-library/blocks/image/editor-rtl.css 799 B
build/block-library/blocks/image/editor.css 799 B
build/block-library/blocks/image/style-rtl.css 1.6 kB
build/block-library/blocks/image/style.css 1.59 kB
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/latest-comments/style-rtl.css 355 B
build/block-library/blocks/latest-comments/style.css 354 B
build/block-library/blocks/latest-posts/editor-rtl.css 139 B
build/block-library/blocks/latest-posts/editor.css 138 B
build/block-library/blocks/latest-posts/style-rtl.css 520 B
build/block-library/blocks/latest-posts/style.css 520 B
build/block-library/blocks/list/style-rtl.css 107 B
build/block-library/blocks/list/style.css 107 B
build/block-library/blocks/loginout/style-rtl.css 61 B
build/block-library/blocks/loginout/style.css 61 B
build/block-library/blocks/media-text/editor-rtl.css 321 B
build/block-library/blocks/media-text/editor.css 320 B
build/block-library/blocks/media-text/style-rtl.css 552 B
build/block-library/blocks/media-text/style.css 550 B
build/block-library/blocks/more/editor-rtl.css 427 B
build/block-library/blocks/more/editor.css 427 B
build/block-library/blocks/navigation-link/editor-rtl.css 644 B
build/block-library/blocks/navigation-link/editor.css 645 B
build/block-library/blocks/navigation-link/style-rtl.css 192 B
build/block-library/blocks/navigation-link/style.css 191 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 295 B
build/block-library/blocks/navigation-submenu/editor.css 294 B
build/block-library/blocks/navigation/editor-rtl.css 2.2 kB
build/block-library/blocks/navigation/editor.css 2.2 kB
build/block-library/blocks/navigation/style-rtl.css 2.24 kB
build/block-library/blocks/navigation/style.css 2.23 kB
build/block-library/blocks/nextpage/editor-rtl.css 392 B
build/block-library/blocks/nextpage/editor.css 392 B
build/block-library/blocks/page-list/editor-rtl.css 378 B
build/block-library/blocks/page-list/editor.css 378 B
build/block-library/blocks/page-list/style-rtl.css 192 B
build/block-library/blocks/page-list/style.css 192 B
build/block-library/blocks/paragraph/editor-rtl.css 236 B
build/block-library/blocks/paragraph/editor.css 236 B
build/block-library/blocks/paragraph/style-rtl.css 341 B
build/block-library/blocks/paragraph/style.css 340 B
build/block-library/blocks/post-author-biography/style-rtl.css 74 B
build/block-library/blocks/post-author-biography/style.css 74 B
build/block-library/blocks/post-author-name/style-rtl.css 69 B
build/block-library/blocks/post-author-name/style.css 69 B
build/block-library/blocks/post-author/editor-rtl.css 107 B
build/block-library/blocks/post-author/editor.css 107 B
build/block-library/blocks/post-author/style-rtl.css 188 B
build/block-library/blocks/post-author/style.css 189 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 527 B
build/block-library/blocks/post-comments-form/style.css 528 B
build/block-library/blocks/post-content/style-rtl.css 61 B
build/block-library/blocks/post-content/style.css 61 B
build/block-library/blocks/post-date/style-rtl.css 62 B
build/block-library/blocks/post-date/style.css 62 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 155 B
build/block-library/blocks/post-excerpt/style.css 155 B
build/block-library/blocks/post-featured-image/editor-rtl.css 729 B
build/block-library/blocks/post-featured-image/editor.css 726 B
build/block-library/blocks/post-featured-image/style-rtl.css 347 B
build/block-library/blocks/post-featured-image/style.css 347 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 399 B
build/block-library/blocks/post-template/style.css 398 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 70 B
build/block-library/blocks/post-time-to-read/style.css 70 B
build/block-library/blocks/post-title/style-rtl.css 162 B
build/block-library/blocks/post-title/style.css 162 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 134 B
build/block-library/blocks/pullquote/editor.css 134 B
build/block-library/blocks/pullquote/style-rtl.css 351 B
build/block-library/blocks/pullquote/style.css 350 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 121 B
build/block-library/blocks/query-pagination-numbers/editor.css 118 B
build/block-library/blocks/query-pagination/editor-rtl.css 154 B
build/block-library/blocks/query-pagination/editor.css 154 B
build/block-library/blocks/query-pagination/style-rtl.css 237 B
build/block-library/blocks/query-pagination/style.css 237 B
build/block-library/blocks/query-title/style-rtl.css 64 B
build/block-library/blocks/query-title/style.css 64 B
build/block-library/blocks/query/editor-rtl.css 527 B
build/block-library/blocks/query/editor.css 527 B
build/block-library/blocks/quote/style-rtl.css 238 B
build/block-library/blocks/quote/style.css 238 B
build/block-library/blocks/quote/theme-rtl.css 233 B
build/block-library/blocks/quote/theme.css 236 B
build/block-library/blocks/read-more/style-rtl.css 138 B
build/block-library/blocks/read-more/style.css 138 B
build/block-library/blocks/rss/editor-rtl.css 101 B
build/block-library/blocks/rss/editor.css 101 B
build/block-library/blocks/rss/style-rtl.css 288 B
build/block-library/blocks/rss/style.css 287 B
build/block-library/blocks/search/editor-rtl.css 199 B
build/block-library/blocks/search/editor.css 199 B
build/block-library/blocks/search/style-rtl.css 660 B
build/block-library/blocks/search/style.css 658 B
build/block-library/blocks/search/theme-rtl.css 113 B
build/block-library/blocks/search/theme.css 113 B
build/block-library/blocks/separator/editor-rtl.css 100 B
build/block-library/blocks/separator/editor.css 100 B
build/block-library/blocks/separator/theme-rtl.css 195 B
build/block-library/blocks/separator/theme.css 195 B
build/block-library/blocks/shortcode/editor-rtl.css 286 B
build/block-library/blocks/shortcode/editor.css 286 B
build/block-library/blocks/site-logo/editor-rtl.css 806 B
build/block-library/blocks/site-logo/editor.css 803 B
build/block-library/blocks/site-logo/style-rtl.css 218 B
build/block-library/blocks/site-logo/style.css 218 B
build/block-library/blocks/site-tagline/editor-rtl.css 87 B
build/block-library/blocks/site-tagline/editor.css 87 B
build/block-library/blocks/site-tagline/style-rtl.css 65 B
build/block-library/blocks/site-tagline/style.css 65 B
build/block-library/blocks/site-title/editor-rtl.css 85 B
build/block-library/blocks/site-title/editor.css 85 B
build/block-library/blocks/site-title/style-rtl.css 143 B
build/block-library/blocks/site-title/style.css 143 B
build/block-library/blocks/social-link/editor-rtl.css 309 B
build/block-library/blocks/social-link/editor.css 309 B
build/block-library/blocks/social-links/editor-rtl.css 729 B
build/block-library/blocks/social-links/editor.css 727 B
build/block-library/blocks/social-links/style-rtl.css 1.51 kB
build/block-library/blocks/social-links/style.css 1.5 kB
build/block-library/blocks/spacer/editor-rtl.css 346 B
build/block-library/blocks/spacer/editor.css 346 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-of-contents/style-rtl.css 83 B
build/block-library/blocks/table-of-contents/style.css 83 B
build/block-library/blocks/table/editor-rtl.css 394 B
build/block-library/blocks/table/editor.css 394 B
build/block-library/blocks/table/style-rtl.css 640 B
build/block-library/blocks/table/style.css 639 B
build/block-library/blocks/table/theme-rtl.css 152 B
build/block-library/blocks/table/theme.css 152 B
build/block-library/blocks/tag-cloud/editor-rtl.css 144 B
build/block-library/blocks/tag-cloud/editor.css 144 B
build/block-library/blocks/tag-cloud/style-rtl.css 266 B
build/block-library/blocks/tag-cloud/style.css 265 B
build/block-library/blocks/template-part/editor-rtl.css 368 B
build/block-library/blocks/template-part/editor.css 368 B
build/block-library/blocks/template-part/theme-rtl.css 113 B
build/block-library/blocks/template-part/theme.css 113 B
build/block-library/blocks/term-description/style-rtl.css 126 B
build/block-library/blocks/term-description/style.css 126 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 165 B
build/block-library/blocks/text-columns/style.css 165 B
build/block-library/blocks/verse/style-rtl.css 98 B
build/block-library/blocks/verse/style.css 98 B
build/block-library/blocks/video/editor-rtl.css 441 B
build/block-library/blocks/video/editor.css 442 B
build/block-library/blocks/video/style-rtl.css 192 B
build/block-library/blocks/video/style.css 192 B
build/block-library/blocks/video/theme-rtl.css 134 B
build/block-library/blocks/video/theme.css 134 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.08 kB
build/block-library/common.css 1.08 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 11.8 kB
build/block-library/editor.css 11.8 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 222 kB
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/theme-rtl.css 708 B
build/block-library/theme.css 712 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 53 kB
build/commands/index.min.js 16.1 kB
build/commands/style-rtl.css 955 B
build/commands/style.css 952 B
build/components/index.min.js 228 kB
build/components/style-rtl.css 12.4 kB
build/components/style.css 12.4 kB
build/compose/index.min.js 12.7 kB
build/core-commands/index.min.js 3.09 kB
build/core-data/index.min.js 74.3 kB
build/customize-widgets/index.min.js 11 kB
build/customize-widgets/style-rtl.css 1.35 kB
build/customize-widgets/style.css 1.35 kB
build/data-controls/index.min.js 641 B
build/data/index.min.js 8.69 kB
build/date/index.min.js 18 kB
build/deprecated/index.min.js 458 B
build/dom-ready/index.min.js 325 B
build/dom/index.min.js 4.66 kB
build/edit-post/classic-rtl.css 578 B
build/edit-post/classic.css 580 B
build/edit-post/index.min.js 13.3 kB
build/edit-post/style-rtl.css 2.75 kB
build/edit-post/style.css 2.75 kB
build/edit-site/index.min.js 220 kB
build/edit-site/posts-rtl.css 7.54 kB
build/edit-site/posts.css 7.55 kB
build/edit-site/style-rtl.css 13.8 kB
build/edit-site/style.css 13.8 kB
build/edit-widgets/index.min.js 17.7 kB
build/edit-widgets/style-rtl.css 4.09 kB
build/edit-widgets/style.css 4.09 kB
build/editor/style-rtl.css 9.27 kB
build/editor/style.css 9.27 kB
build/element/index.min.js 4.82 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 8.05 kB
build/format-library/style-rtl.css 476 B
build/format-library/style.css 476 B
build/hooks/index.min.js 1.65 kB
build/html-entities/index.min.js 445 B
build/i18n/index.min.js 3.58 kB
build/is-shallow-equal/index.min.js 526 B
build/keyboard-shortcuts/index.min.js 1.31 kB
build/keycodes/index.min.js 1.46 kB
build/list-reusable-blocks/index.min.js 2.13 kB
build/list-reusable-blocks/style-rtl.css 852 B
build/list-reusable-blocks/style.css 852 B
build/media-utils/index.min.js 3.58 kB
build/notices/index.min.js 946 B
build/nux/index.min.js 1.62 kB
build/nux/style-rtl.css 749 B
build/nux/style.css 745 B
build/patterns/index.min.js 7.37 kB
build/patterns/style-rtl.css 687 B
build/patterns/style.css 685 B
build/plugins/index.min.js 1.86 kB
build/preferences-persistence/index.min.js 2.06 kB
build/preferences/index.min.js 2.9 kB
build/preferences/style-rtl.css 554 B
build/preferences/style.css 554 B
build/primitives/index.min.js 829 B
build/priority-queue/index.min.js 1.54 kB
build/private-apis/index.min.js 972 B
build/react-i18n/index.min.js 630 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 6.76 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.55 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.3 kB
build/router/index.min.js 5.42 kB
build/server-side-render/index.min.js 1.94 kB
build/shortcode/index.min.js 1.4 kB
build/style-engine/index.min.js 2.04 kB
build/token-list/index.min.js 581 B
build/url/index.min.js 3.9 kB
build/vendors/react-dom.min.js 41.7 kB
build/vendors/react-jsx-runtime.min.js 556 B
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 965 B
build/vips/index.min.js 36.2 kB
build/warning/index.min.js 250 B
build/widgets/index.min.js 7.16 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.03 kB

compressed-size-action

* selection of a background color should be applied to the other paths
* so it can be honoured.
*/
$separator_color = $config['styles']['blocks']['core/separator']['color']['background'] ?? null;
Copy link
Member

Choose a reason for hiding this comment

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

This reminds me to brush off the theme json style-related methods abstraction issue

@aaronrobertshaw
Copy link
Contributor Author

In e71fd97 I've taken a run at removing the fudging of style declarations for the separator block in favour of a theme.json data based approach.

There's a slight change in logic when it comes to merging the theme origin data (i.e. the separator styles when defined in theme.json).

Previously, the color.background value was only used if both color.text and border.color aren't set. It's a little more robust if we apply the color.background value to the other paths if they are undefined. This way, if a theme author set two of the three paths (including color.background), any block styles or rendering of the separator block that relied on the missing color value would get the likely expected background color.

The theme origin tweaking of separator color only needs to happen on the PHP class side in get_theme_data as the updated data gets passed to the editor via the block editor settings.

The user origin data tweaks still need to occur on the JS side too. This is due to the editor needing to handle unsaved selections made by the user in the Global Styles UI.

I've removed the old update_separator_declarations function and tests. New unit tests have been added to the theme.json resolver tests. I might have gone a little overboard there as they are quite verbose but for the purpose of this PR and discussion, I'll leave them for now and we can cull, clean, or take a different approach later.

@ramonjd, this isn't a high priority but if you get the chance, let me know what you think of the general approach now. If you think it has legs, I'll take this out of draft status and cast the net wider for alternative ideas.

Copy link

github-actions bot commented Nov 27, 2024

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

@ramonjd
Copy link
Member

ramonjd commented Dec 2, 2024

I've taken a run at removing the fudging of style declarations for the separator block in favour of a theme.json data based approach.

I like that the code is now in existing internals. I know it's not always easy in practice, but the fewer bespoke private functions we have in theme.json the better.

It's a little more robust if we apply the color.background value to the other paths if they are undefined. This way, if a theme author set two of the three paths (including color.background), any block styles or rendering of the separator block that relied on the missing color value would get the likely expected background color.

These are the changes in get_theme_data()?

I think that's sound reasoning.

From looking at the changes, it's doing its best to honor the theme.json values and safe-guard against unexpected separator colors.

Overall, I think it's a good direction and you've balanced the competing priorities. Off the top of my head, no backwards compat issues occur to me, but hopefully wider testing will wash that out.

Thank a lot for persisting with this.

What do you think? Should we try to get eyes on it early in 6.8 cycle?

@ramonjd
Copy link
Member

ramonjd commented Dec 2, 2024

Forgot to add that I tested the PR too in TT4 and TT5 and it works as expected 😄

@aaronrobertshaw
Copy link
Contributor Author

These are the changes in get_theme_data()?

That's correct. I should have been clearer on that point.

There was previously no consideration of which origin the data was coming from. Which in part, was the cause for global styles selections not being honoured.

What do you think? Should we try to get eyes on it early in 6.8 cycle?

💯 Agreed.

I'll give the PR, its description, and test instructions a bit of a polish and flag for review later this afternoon.

Thanks for all the sanity checking around the approach 🙇

@aaronrobertshaw aaronrobertshaw changed the title Try enforcing global styles separator color Global Styles: Fix Separator block color use Dec 2, 2024
@aaronrobertshaw aaronrobertshaw marked this pull request as ready for review December 2, 2024 05:27
Copy link

github-actions bot commented Dec 2, 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: aaronrobertshaw <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: talldan <[email protected]>

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

@aaronrobertshaw
Copy link
Contributor Author

I've added a more detailed breakdown of all the changes to the PR description and flagged as ready for review. I'll sort out the backport shortly and then ping for a few reviews.

@aaronrobertshaw
Copy link
Contributor Author

Backport is available (WordPress/wordpress-develop#7927) and changelog added here.

@aaronrobertshaw aaronrobertshaw requested review from talldan and tellthemachines and removed request for tellthemachines December 2, 2024 07:40
@ramonjd ramonjd requested a review from cbravobernal December 2, 2024 23:59
* selection of a background color should be applied to the other paths
* so it can be honored.
*/
$separator_color = $config['styles']['blocks']['core/separator']['color']['background'] ?? null;
Copy link
Member

Choose a reason for hiding this comment

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

Noticed over here: #57297 (comment)

What do you think we should do about gradients? If anything at all?

They are applied to the background prop, but don't really have any effect. And linear-gradient is invalid for color and border-color anyway as far as I see 🤔

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'll dig into this one tomorrow and see if there's anything we can smooth out.

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've spent some time on an archaeological dig today around the addition of gradient support to the Separator block.

The TL;DR is that I believe it was simply mistakenly added. It wasn't referred to at all on the original PR and doesn't appear to have been tested in any way either. From what I can tell gradients have been broken since their adoption.


So...here's the long version of my current understanding 😅

  • Global Styles will generate styles targeting the background CSS property
  • The Separator block's hr element will inherit currentColor for its color CSS value
  • In the editor, the Separator block has a tiny amount of padding added which exposes some background
  • On the frontend, the Separator has no padding normally so no background is visible
  • Even in the editor where there is some background visible it's overlaid by the color property effectively masking any gradient applied here
  • If the background property has a linear-gradient value at all, copying that to border-color or color results in an invalid CSS rule and falls back to currentColor
  • The Separator block was updated in Separator block: refactor to use color block supports #38428 which skipped color block support serialization but it didn't take gradients into account at all
  • The approach in #38428 means
    • gradient classes aren't considered and remain on the block wrapper
    • any preset gradient isn't retrieved and processed like the backgroundColor value
    • when customColor is determined it only takes into account style.color.background forgetting about style.color.gradient
  • There's one default theme (TwentyTwenty) that appears to leverage linear-gradient while it sort of works the // characters don't get the gradient and hovering the block in the editor breaks the // onto separate lines
  • A theme could style the Separator block's hr element to not use border or color, give it a height or padding and then apply any background style including gradients.

At the end of all of that, I'm not sure if this is fixable to a degree where the Separator block could reliably have gradients applied to it. If it was "fixed" it might only be for use cases where the Separator block has had its default styles overridden or has a block style that makes color transparent, removes border, and gives it a visible height.

I'd like to see gradient support removed from the block. Given its current broken state and that it has been that way since its inception, I don't think there's much of a backwards compatibility argument to be made. Removing the gradients support at least lowers complexity and maintenance burden moving forward.

What do you think @ramonjd?

Copy link
Member

Choose a reason for hiding this comment

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

Amazing digging, thank you!

I'd like to see gradient support removed from the block. Given its current broken state and that it has been that way since its inception, I don't think there's much of a backwards compatibility argument to be made. Removing the gradients support at least lowers complexity and maintenance burden moving forward.

+1

In any case, since it's a long-standing issue, and doesn't affect the intention of this PR it's a "tomorrow" thing.

I appreciate the time you spent researching. It'll be useful to whoever picks it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we do go with removing support it should only be deleting a single line from the block.json. Despite that, still worth a separate PR to debate and document the decision. I'll spin that up after I work through the possible follow-up for the issue Dan flagged below.

@talldan
Copy link
Contributor

talldan commented Dec 4, 2024

Gave this a test. In TT4, I'm seeing that the block's instance color settings aren't overriding global style color for the 'Default' or 'Wide Line' block styles variations:
Screenshot 2024-12-04 at 10 09 00 am

It seems like the color and background color are being overridden, but not the border color:
Screenshot 2024-12-04 at 10 10 39 am

@aaronrobertshaw
Copy link
Contributor Author

Thanks for testing @talldan 👍

I'm seeing that the block's instance color settings aren't overriding global style color for the 'Default' or 'Wide Line' block styles variations:

This was another oversight in the original implementation in #38428 in addition to mistakenly (in my opinion) adopting gradient support. Further details from some recent digging can be found in #67269 (comment).

If my understanding is correct, the noted behaviour is consistent with trunk. My focus for this PR was fixing Global Styles. If we're changing the application of background to border-color on the block instance, it will need a deprecation as well. Do you think this is ok as a follow-up?

@talldan
Copy link
Contributor

talldan commented Dec 5, 2024

Do you think this is ok as a follow-up?

Yep, sounds good if you think it's best to split it across multiple PRs.

@aaronrobertshaw
Copy link
Contributor Author

Given it's taken me a while to get back to this, I've pushed what I think could be a fix to this PR for the block instance styles not appearing to take effect correctly in 4074641.

Before After
Screenshot 2024-12-06 at 6 03 35 pm Screenshot 2024-12-06 at 6 03 29 pm

I went with a 0-2-0 specificity style in the block library styles (see 4074641) to avoid needing to override the global styles inline, potentially requiring a deprecation.

Let me know what you think, whether you see any pitfalls to this approach etc 🙏

Comment on lines +11 to +16
// 0-2-0 specificity required to enforce block instance
// color selections over global styles.
.wp-block-separator.has-background,
.wp-block-separator.has-text-color {
border-color: currentColor;
}
Copy link
Member

Choose a reason for hiding this comment

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

Just so I understand:

  • if the separator block has a background color set, the color property will have the same value (thanks to the changes in this PR),
  • this rule therefore ensures the border color has the same value as color, through currentColor

Gave this a test. In TT4, I'm seeing that the block's instance color settings aren't overriding global style color for the 'Default' or 'Wide Line' block styles variations:

The CSS rule above addresses this issue for me in the editor and frontend:

  1. In TT4, change the background value of Wide Line variation in global styles
  2. At the block level, apply Wide Line variation, and overwrite the background color

Do block style variation global styles need the same treatment? 🤔

  1. In TT4, change the background value of Wide Line variation in global styles
  2. At the block level, apply Wide Line variation

The background color is set, but the theme.json border color still affects the appearance. Here's what I'm seeing in in the frontend:

:root :where(.wp-block-separator.is-style-wide--2) {
    background-color: #00ff40;
}

:root :where(.wp-block-separator) {
}
:root :where(.wp-block-separator) {
    border-color: currentColor;
    border-width: 0 0 1px 0;
    border-style: solid;
    color: var(--wp--preset--color--contrast);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Separator Affects the Separator Block Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants