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 push-to-global-styles clearing of attributes, border fallbacks, link hover colors, and behaviors #51621

Merged
merged 7 commits into from
Aug 11, 2023

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented Jun 18, 2023

Fixes: #48048

What?

  • Adds fallback default border style when applying block styles globally so a visual border is maintained
  • Fixes pushing of border styles to global styles
  • Fixes resetting of block attributes for presets when applying globally
  • Cleans updated block style attribute to remove empty objects that were left behind
  • Fixes pushing link hover colors
  • Fixes clearing of behavior attributes
  • Updates hook dependencies to satisfy linter (needs extra testing to ensure no regressions)

Why?

Currently, the pushing of block instance styles to global styles doesn't work for borders creating unexpected UX.

How?

  • When determining the changes that need to be pushed to the user's global styles, we apply the required global styles logic to border styles (e.g. global styles needs longhand config).
  • Border style fallbacks are only added if the side doesn't already have one in global styles to maintain prior selections
  • Updates the config arrays so that border color preset values are added to the changes correctly
  • Clears preset block attribute values from the updated block attributes
  • Handle case where single support key for linkColor needs to check two style properties for changes
  • Fix snackbar undo actions to also undo clearing of attributes

Testing Instructions

  1. Replicate the original issue before checking out this PR. See Featured Image block: applying styles globally resets the border changes in the editor #48048 for further info.
  2. In the site editor, select an individual block that has border support e.g. Featured Image or Group
  3. Apply a border width or color only to that block, note that the editor shows a visual border
  4. Switch to the settings tab and expand the Advanced panel revealing the Apply globally button
  5. Click "Apply globally" and confirm that the border remains visible as before in the editor, including color application now being fixed
  6. Switch back to the styles tab and ensure that the border controls there are now reset
  7. Navigate to Global Styles > Blocks > and then to the block type you styled
  8. Confirm that block type's border controls now show the color or width you selected, along with the default border style
  9. Repeat the process however this time set a dashed or dotted border style and confirm that border style is retained throughout
  10. Test the application of block styles global setting all available color and font preset values e.g. text, background, gradient, border color, font size, font family etc. Confirm that now when you apply those styles globally, the block's attribute has been reset.
  11. Test setting global styles first, then updating a block instance style before applying the block styles globally e.g. Global Styles: Fix push-to-global-styles clearing of attributes, border fallbacks, link hover colors, and behaviors #51621 (comment)
  12. Test with varied border configs per side ensuring they are applied as expected globally.
  13. Make sure that block instance styles are correctly applied globally when the block has per-side config, the global styles are using shorthand, and vice versa.
  14. Confirm that when configuring per-side borders on a block instance the border style attributes are properly cleaned from the block attributes.
  15. Test that after applying block styles globally, the undo link in the snackbar notice works correctly. In particular, ensure that preset attribute values are reinstated.
  16. Test that block gap styles trigger the activation of the "Apply Globally" button and that they are successfully pushed to global styles and cleared from the block instance when the button is clicked.
  17. Confirm link hover color is successfully pushed and cleared from block instance
  18. Confirm pushed behaviours are also cleared

Screenshots or screencast

Screen.Recording.2023-06-18.at.7.34.45.pm.mp4

@aaronrobertshaw aaronrobertshaw added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jun 18, 2023
@aaronrobertshaw aaronrobertshaw self-assigned this Jun 18, 2023
}

return changes;
}, [ supports, attributes ] );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused dependency removed to satisfy linter. I couldn't see any regressions but worth flagging in case I missed something.

Comment on lines 203 to 407
}, [
changes,
attributes,
userConfig,
name,
createSuccessNotice,
setAttributes,
setUserConfig,
__unstableMarkNextChangeAsNotPersistent,
] );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing dependencies added to keep linter happy.

@github-actions
Copy link

github-actions bot commented Jun 18, 2023

Size Change: +420 B (0%)

Total Size: 1.5 MB

Filename Size Change
build/edit-site/index.min.js 91.1 kB +420 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.28 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 451 B
build/block-directory/index.min.js 7.01 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/content-rtl.css 4.26 kB
build/block-editor/content.css 4.25 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 B
build/block-editor/index.min.js 211 kB
build/block-editor/style-rtl.css 14.9 kB
build/block-editor/style.css 14.9 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 584 B
build/block-library/blocks/button/editor.css 582 B
build/block-library/blocks/button/style-rtl.css 624 B
build/block-library/blocks/button/style.css 623 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 421 B
build/block-library/blocks/columns/style.css 421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.61 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view-interactivity.min.js 317 B
build/block-library/blocks/file/view.min.js 375 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 1.42 kB
build/block-library/blocks/image/style.css 1.42 kB
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/image/view-interactivity.min.js 1.46 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 507 B
build/block-library/blocks/media-text/style.css 505 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 712 B
build/block-library/blocks/navigation-link/editor.css 711 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.23 kB
build/block-library/blocks/navigation/style.css 2.22 kB
build/block-library/blocks/navigation/view-interactivity.min.js 988 B
build/block-library/blocks/navigation/view-modal.min.js 2.85 kB
build/block-library/blocks/navigation/view.min.js 469 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 401 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 319 B
build/block-library/blocks/post-featured-image/style.css 319 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 314 B
build/block-library/blocks/post-template/style.css 314 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 335 B
build/block-library/blocks/pullquote/style.css 335 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 302 B
build/block-library/blocks/query-pagination/style.css 299 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 450 B
build/block-library/blocks/query/editor.css 449 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 178 B
build/block-library/blocks/search/editor.css 178 B
build/block-library/blocks/search/style-rtl.css 608 B
build/block-library/blocks/search/style.css 608 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 631 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.44 kB
build/block-library/blocks/social-links/style.css 1.43 kB
build/block-library/blocks/spacer/editor-rtl.css 348 B
build/block-library/blocks/spacer/editor.css 348 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 645 B
build/block-library/blocks/table/style.css 644 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 185 B
build/block-library/blocks/video/style.css 185 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.1 kB
build/block-library/editor.css 12.1 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 203 kB
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 13.7 kB
build/block-library/style.css 13.8 kB
build/block-library/theme-rtl.css 686 B
build/block-library/theme.css 691 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51.2 kB
build/commands/index.min.js 15.3 kB
build/commands/style-rtl.css 863 B
build/commands/style.css 857 B
build/components/index.min.js 245 kB
build/components/style-rtl.css 11.8 kB
build/components/style.css 11.8 kB
build/compose/index.min.js 12.1 kB
build/core-commands/index.min.js 2.44 kB
build/core-data/index.min.js 16.8 kB
build/customize-widgets/index.min.js 12 kB
build/customize-widgets/style-rtl.css 1.46 kB
build/customize-widgets/style.css 1.45 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 8.38 kB
build/date/index.min.js 17.8 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.64 kB
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/edit-post/index.min.js 35.7 kB
build/edit-post/style-rtl.css 7.59 kB
build/edit-post/style.css 7.59 kB
build/edit-site/style-rtl.css 13.2 kB
build/edit-site/style.css 13.2 kB
build/edit-widgets/index.min.js 16.9 kB
build/edit-widgets/style-rtl.css 4.53 kB
build/edit-widgets/style.css 4.53 kB
build/editor/index.min.js 45.5 kB
build/editor/style-rtl.css 3.55 kB
build/editor/style.css 3.55 kB
build/element/index.min.js 4.82 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.59 kB
build/format-library/style-rtl.css 554 B
build/format-library/style.css 553 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/index.min.js 10.4 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.64 kB
build/keycodes/index.min.js 1.87 kB
build/list-reusable-blocks/index.min.js 2.2 kB
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 1.99 kB
build/nux/style-rtl.css 735 B
build/nux/style.css 732 B
build/plugins/index.min.js 1.79 kB
build/preferences-persistence/index.min.js 1.84 kB
build/preferences/index.min.js 1.24 kB
build/primitives/index.min.js 943 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 951 B
build/react-i18n/index.min.js 615 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.71 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 11 kB
build/router/index.min.js 1.78 kB
build/server-side-render/index.min.js 1.94 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 1.85 kB
build/sync/index.min.js 53.8 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.73 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 958 B
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.16 kB
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@github-actions
Copy link

github-actions bot commented Jun 18, 2023

Flaky tests detected in 1fcce00.
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/5826903699
📝 Reported issues:

@ramonjd ramonjd requested a review from noisysocks June 18, 2023 23:14
@t-hamano
Copy link
Contributor

Thanks for the PR, @aaronrobertshaw!

I have tried applying various styles globally. Perhaps some of them are not included in the scope of this PR, but they are listed below.


The "Apply globally" button is not enabled when I change the Block Spacing of the block. If I change other styles, that button is enabled, but it is not reflected in the global style. This problem also occurs with trunk.

Recorded Video
blockgap_disabled.mp4

If you apply only a border color to a block, its border will be rendered. However, if you push that style globally, the border will disappear. In trunk, if only the border color is changed, the "Apply globally" button cannot be pressed.

Recorded Video
border_disappear.mp4

If you specify a custom value for the border color and push it globally, an error is logged in the browser console. In trunk, if you change only the border color, the "Apply globally" button cannot be pushed, but if you change other styles (such as margin) and push globally, the same error is logged.

Recorded Video
browser_error.mp4

@ramonjd
Copy link
Member

ramonjd commented Jun 19, 2023

I was trying the reverse and think I found a bug: setting global border styles to a group block, then applying local block border changes globally doesn't work. The bug is also in trunk, so I'm not sure what the scope of this branch is.

  1. In the Site editor, edit a template with some group blocks
  2. Apply group block border width and color in global styles
  3. Save - The editor and frontend match 👍
  4. Now click on a single block and adjust its border width and color styles. Select a custom color.
  5. Apply these globally
  6. Styles are not applied, and when adding a custom color and width the Group block edit.js throws an error

Removing a style property during rerender (borderColor) when a conflicting property is set (borderBottomColor) can lead to styling bugs. To avoid this, don't mix shorthand and non-shorthand properties for the same value; instead, replace the shorthand with separate values.

Screencast

2023-06-19 16 12 21

@aaronrobertshaw
Copy link
Contributor Author

Thanks for the testing and reviews. I've also just been working on a fix for pushing split borders i.e. borders with different configurations per side.

Block gap isn't included in the __EXPERIMENTAL_STYLE_PROPERTY constant so doesn't get picked up in the changes as determined by useChangesToPush. Furthermore, there are a number of other supports and styles that aren't in that constant e.g. filter, shadow etc. I'm not clear on when that was added and if there are any reasons why some things were left out.

For this PR, I think it would be best to now limit the scope to just the border styles, and address each other style/support in a follow up.

@aaronrobertshaw
Copy link
Contributor Author

Styles are not applied, and when adding a custom color and width the Group block edit.js throws an error

I can replicate the application of a block instance's styles not overriding pre-existing global styles but I can't get the error at all.

I'll keep digging but it might be a few days before I can devote too much time to this. Given this is bug related we should still be able to get it merged within the next GB beta period.

@aaronrobertshaw
Copy link
Contributor Author

I'll keep digging but it might be a few days before I can devote too much time to this. Given this is bug related we should still be able to get it merged within the next GB beta period.

There's a catch with global styles borders and theme.json set borders. If the theme json sets per side borders, the global styles also has to apply per side borders even if the user's border is "flat" and can be a simple shorthand border: ... rule.

Currently, if the border is a flat border on the instance it's still being pushed as that and so won't clear or override the per side config set by Global Styles. We could clear the Global Styles per side config but then might expose the issue if a theme.json sets per side borders.

Long story, short, applying block styles globally will require PushChangesToGlobalStylesControl to convert a flat border to a split "per-side" border.

@aaronrobertshaw
Copy link
Contributor Author

I've pushed some changes that I believe fix the issues reported on earlier reviews (although I still can't replicate the error).

Given there are so many different ways borders can be configured, I'd really appreciate some further thorough testing 🙏

Screen.Recording.2023-06-19.at.6.06.57.pm.mp4

gradient: undefined,
fontSize: undefined,
fontFamily: undefined,
style: cleanEmptyObject( newBlockStyles ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only clearing the individual border side properties would still leave empty objects in the block style attribute without this cleanEmptyObject.

Comment on lines +170 to +223
// The shorthand border styles can't be mapped directly as global
// styles requires longhand config.
if ( flatBorderProperties.includes( key ) && value ) {
// The shorthand config path is included to clear the block attribute.
const borderChanges = [ { path, value } ];
sides.forEach( ( side ) => {
const currentPath = [ ...path ];
currentPath.splice( -1, 0, side );
borderChanges.push( { path: currentPath, value } );
} );
return borderChanges;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an issue where if a theme.json configures longhand border properties and the user's global styles only configured shorthand border styles, the theme.json styles would incorrectly take precedence. As a result, Global Styles applies even shorthand borders to the longhand border properties.

This block of code maps shorthand block instance border styles to the longhand paths required by global styles.

const { user: userConfig, setUserConfig } =
useContext( GlobalStylesContext );

const changes = useChangesToPush( name, attributes, userConfig );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now pass the current user global styles to assist with determining if we need to provide a fallback border style to maintain a visible border.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

If I'm not wrong, I think we've discussed a potential alternative to actually add the fallback when generating the styles (I don't remember entirely why we discarded this option). It feels to me, like this PR is kind of a hack because we're not applying the fallback properly.

I know that there are some nuances there that might make the above not easy to achieve, so not entirely a blocker but if we want to remove these hacks, I think we should probably apply the conceptual fix at some point.

@aaronrobertshaw
Copy link
Contributor Author

If I'm not wrong, I think we've discussed a potential alternative to actually add the fallback when generating the styles (I don't remember entirely why we discarded this option).

I'm not sure of the alternative you are referring to. Was it setting defaults in controls from global styles? I think a blocker for that was flagged in this comment.

For some history and context. The discussion began after the extraction of the border panel. Which required some follow-up fixes in #49603. That lead to the proposal to remove the "smart" border style behaviour. That PR has more in the way of explanations.

Ultimately, from those discussions, we went with two fixes for the extracted panel that continued to handle the edge cases with borders:

It feels to me, like this PR is kind of a hack because we're not applying the fallback properly.

I'd be 100% on board with a holistic fix to covering these edge cases. Unfortunately, I don't know what that fix is, whether it is getting global styles defaults in the block editor for all controls, updating the style engine or its use to cover these edge cases etc.

I'm happy to close this PR if you have better ideas. I created it to try and get this feature fixed as it has had bugs since it landed (not clearing preset attributes etc, missing some styles) and is accumulating more as additional styles have been added to the style config arrays in the block editor package and not here.

@ramonjd
Copy link
Member

ramonjd commented Jun 20, 2023

Thanks for updating the PR @aaronrobertshaw

I've retested the changes using Featured Image and Group blocks in the site editor.

Applying a block's styles globally, I can:

  • set border color, width and radius values for all blocks
  • update border color, width and radius values set in block global styles
  • set and update individual side border color, width and radius values. This includes updating any individual sides that have been previously set in global block styles.
  • overwrite any theme.json styles set in styles.blocks['core/group']^
  • reset them via "reset to defaults"

It's working well for me. Haven't run into any issues so far.

^
I still see the js console error (could be just me). Here's the theme.json styles I'm using

	"styles": {
		"blocks": {
			"core/group": {
				"border": {
					"color": "#000000",
					"style": "solid",
					"width": "10px"
				}
			}
		}
	},
Screenshot 2023-06-20 at 2 22 31 pm

@youknowriad
Copy link
Contributor

Just noting that I'm not suggesting that we change anything in this PR. I think if you're all satisfied with it please continue and merge. Mainly trying to understand the problem better to see why it's so complex.


Here's my mental model,, just sharing how I think about this problem and what might be an alternative solution.

We have two places where we generate styles based on "user input":

1- Global Styles (theme.json) root level
2- Global Styles (theme.json) block level
3- Block Styles (block supports): individual block level

When do we need the fallback? (this is where I'm not sure about my answer, so correct me here because the logic depends on it)

  • We need to apply the fallback for 2 and 3 from the list above but not on 1 (is that right?)

Or maybe the correct fallback by taking into consideration the edge cases is:

  • Don't apply the fallback for 1.
  • Apply the fallback for 2.
  • Apply the fallback for 3 but only if 2 didn't define a border style?

So we could move the fallback logic to the style generation if we have access to global styles from the block supports it seems, right?

@aaronrobertshaw
Copy link
Contributor Author

Thank you for expanding on things @youknowriad 👍

When do we need the fallback?

We need to potentially apply a fallback on all three places users can set styles.

  • Don't apply the fallback for 1.
  • Apply the fallback for 2.
  • Apply the fallback for 3 but only if 2 didn't define a border style?

Use Case 1 - Global Styles - root level - set by user

We still need a fallback here if nothing is set in the theme.json.

The UI control handles this as it should get the theme.json value as a default on the control.

Use Case 2 - Global Styles - block level - set by user

Almost the same as Use Case 1. We need a fallback if nothing has been set yet, either by theme.json or the user's global root styles

Use Case 3 - Block Styles (block supports): individual block level

We need a fallback only if theme.json or global styles haven't set a border style. This is currently handled via a :where() CSS rule given the block editor didn't have access to global styles data.

Use Case 4 - Pushing Block Styles To Global Styles

So for the use case in this PR, moving from block styles to global styles, the :where() CSS rule no longer works so hence the application of logic that we're trying to remove.

So we could move the fallback logic to the style generation if we have access to global styles from the block supports it seems, right?

Yes, if the style engine could access the global styles data and apply some logic during style generation, the fallback could be applied there.

The ability to add some logic to the style generation would also be useful to clean up the global styles for borders which currently has to be the longhand version. This is to overcome the scenario where a theme.json defines different borders per side (longhand). In this case, if a user sets a uniform flat border (shorthand), the theme.json's longhand styles take precedence overriding the user's choice.

Effectively, we need to conditionally generate styles via the style engine, or avoid merging longhand values when the user origin sets a shorthand definition. FWIW the current fallback approaches pre-date the style engine.

@tellthemachines
Copy link
Contributor

Hey peeps, how likely is it that this can still be included in 6.3? It's a regression from 6.2 so could still be added during RC if we're confident it won't impact anything else.

@aaronrobertshaw
Copy link
Contributor Author

Hey peeps, how likely is it that this can still be included in 6.3? It's a regression from 6.2 so could still be added during RC if we're confident it won't impact anything else.

@tellthemachines I will take a look at reviving this tomorrow.

It fixes bugs that have been present since the apply globally feature was introduced rather than a regression. Given it is still a bug fix, it would be good to include it if possible.

Addressing the concerns around a better solution to the fallback logic can be worked on post-6.3.

@tellthemachines
Copy link
Contributor

It fixes bugs that have been present since the apply globally feature was introduced rather than a regression.

Oh, I mentioned this as a regression because I'm unable to reproduce #48048 in WP 6.2.2. That's what this PR fixes, right? Or is its scope wider than that?

@aaronrobertshaw
Copy link
Contributor Author

That's what this PR fixes, right? Or is its scope wider than that?

The scope is wider as there were bugs in the packages/edit-site/src/hooks/push-changes-to-global-styles/index.js script since its inception. Those are detailed in the PR description but to summarise the "apply globally" issues:

  • Didn't handle required border fallback logic to ensure visible borders
  • Didn't clear preset block attributes
  • Missed including block supports in the config arrays such as borders or block gap
  • Leaves empty objects within the block's style attribute

The regression aspect might have been caused by #47098 which duplicated config arrays from the block editor package and those were out of date or incomplete.

@aaronrobertshaw
Copy link
Contributor Author

This PR should be ready for a final review now 🙏

The console error for clearing custom border colors has been fixed and this PR now fixes the detection of block gap changes etc.

A more holistic approach to border-style fallbacks is outside the scope of this PR and will be considered a follow-up.

@aaronrobertshaw aaronrobertshaw requested review from ramonjd, glendaviesnz and kevin940726 and removed request for ramonjd July 27, 2023 06:09
@t-hamano
Copy link
Contributor

t-hamano commented Aug 3, 2023

Thanks for your continuous work on this issue, @aaronrobertshaw!

The series of processes starting with PushChanges() is very complicated for me, but I tried various tests on global pushing of styles again. There are probably some things that this PR shouldn't cover, but I'll list all the things that caught my eye during testing.


In the global style, apply the border style in one direction only. Then apply the border style on the block other than that direction and push it globally. Then the border styles are merged. Is this the intended behavior? For padding, margin and border radius it seems to overwrite global styles when pushed globally. In this screencast, I'm applying the style for the top border in the global style, and then pushing the global from the block that applied the bottom border.

Screencast
border-style-merge.mp4

Border control does not allow only border style to be applied in one direction when unlinked. To select a border style, you must set either border width or border color.

Screencast
border-style-unlinked.mp4

Of the link colors, the default color is successfully pushed globally, but the hover state color is not.

Screencast
hover-color.mp4

#52370 adds Behaviors to the global styles and also updates the files this PR is changing. I noticed that when I push the behaviors setting globally, it doesn't clear the block level setting.

Screencast
behaviors.mp4

The padding disappears when the background is pushed globally. This may be due to the has-background class disappearing at the block level.

Screencast
background-padding.mp4

@aaronrobertshaw
Copy link
Contributor Author

Thank you @t-hamano for the thorough testing, great stuff! 🥇

I'll work through making any required updates to this PR over the next few days.

Then the border styles are merged. Is this the intended behavior?

I'm not certain on what the best approach here is. I'd probably lean towards the current behaviour as the user is seeing the combined results of theme.json, global styles, and individual block styles. The push-to-global-styles, is pushing the current appearance/styling for the block so it applies to all.

If the user wants to override the top border, as per your example, they'd only have to apply a 0 border width to the top border on the block instance, then push.

I'll investigate the spacing controls and border radius behaviour as I address the other issues raised in your review.

Border control does not allow only border style to be applied in one direction when unlinked.

This has been a behaviour on those controls since their inception and not really related to the pushing of global styles. So, I think that would be better suited to a follow-up where the history and context on those controls can be dug up,

Of the link colors, the default color is successfully pushed globally, but the hover state color is not.

Good catch. This looks like another one that was missed with the duplicated config arrays not being kept in sync. A possible follow-up to this might be trying to consolidate those via our private APIs lock/unlock mechanism.

I noticed that when I push the behaviors setting globally, it doesn't clear the block level setting.

Thanks. When I first created this PR the behaviors weren't merged as you noted. After rebasing this, I wasn't expecting to also have to fix any new additions, so missed that 🤦

I'll update this PR accordingly. The sooner we can get this in the better I think so there is a complete example that can be followed for future additions so this doesn't keep reoccurring.

The padding disappears when the background is pushed globally. This may be due to the has-background class disappearing at the block level.

I'm not sure there's an easy fix for this. That CSS class is added by the color block supports. We also don't currently have a way to conditionally generate global styles for some properties, or add extra CSS classes based on theme.json/global styles values.

It's part of the reason, global border styles have to include longhand definitions, even though a shorthand definition has been applied, to ensure they correctly override any longhand definition in theme.json.

For now, I'm inclined to say that is out of the scope for this PR. The user can add padding styles to what they are pushing to global styles to restore or maintain padding. If we left the color support values in place, that block would have padding but not the rest of that block type. Erring towards consistency seems like the best bet here to me.

I'll update again once I've addressed all the actionable items.

Thanks again for the great feedback and review 🙇

Copy link
Contributor Author

@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.

I've fixed the pushing of link hover colors and the clearing of their style attribute. This was a little clunky due to the single supports key covering two separate attributes.

The behaviors only needed to have the block attribute cleared but it highlights that the behaviours and styles should probably be being processed together in a single set of changes. If you set behaviors as well as styles, then push them all globally, you'll receive two snackbar notices each with a different "undo" action.

This is better suited to a follow-up once we have this suite of fixes in place.

if ( userHasEditedBehaviors ) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( { behaviors: undefined } );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A good potential follow-up here might be to consolidate the updating of attributes and snackbar notices for both styles and behaviours. To keep the scope of this PR manageable for testing I've opted against this larger refactor.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Just to be sure, I rebased this PR locally with the latest trunk and tested it. I believe everything is working as expected 🚀

a94dd70857c52932943cfa66692b15ca.mp4

@tellthemachines tellthemachines added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Aug 10, 2023
@glendaviesnz glendaviesnz force-pushed the fix/application-of-border-styles-globally branch from b305a17 to 1fcce00 Compare August 10, 2023 22:55
Copy link
Contributor

@glendaviesnz glendaviesnz left a comment

Choose a reason for hiding this comment

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

Tested well for me:

✅ All typograpy, padding, margin, block spacing, border settings were removed from block settings, but still applied in editor canvas when pushed to global
✅ The settings pushed to global were applied to new blocks
✅ With global settings set first, styles applied after at block level took priority
✅ A range of single border, custom per side settings, different styles, custom colors all pushed successfully to global

@aaronrobertshaw aaronrobertshaw changed the title Global Styles: Add default border style when applying block styles globally Global Styles: Fix push-to-global-styles clearing of attributes, border fallbacks, link hover colors, and behaviors Aug 11, 2023
@aaronrobertshaw
Copy link
Contributor Author

Thank you for the reviews and testing everyone, I appreciate this one got a bit gnarly 🙇

I've updated the PR description and title to also cover the link hover color and behavior fixes.

@aaronrobertshaw aaronrobertshaw merged commit bf2ed0a into trunk Aug 11, 2023
51 checks passed
@aaronrobertshaw aaronrobertshaw deleted the fix/application-of-border-styles-globally branch August 11, 2023 00:08
@github-actions github-actions bot added this to the Gutenberg 16.5 milestone Aug 11, 2023
@tellthemachines
Copy link
Contributor

This PR can't be cherry-picked cleanly onto the wp/6.3 branch because the file on trunk has diverged too much from the version on that branch (mostly I think because
the behaviours changes don't exist yet). If this fix is required for 6.3.x it's going to need a new PR done against that branch, taking into account that the code in this file is at a much earlier stage there 😅

@aaronrobertshaw
Copy link
Contributor Author

The fixes for the behaviour changes in this PR are very minor. Hopefully, that will mean spinning up a new PR against wp/6.3 won't take too long. I can do that tomorrow morning.

@tellthemachines
Copy link
Contributor

Thanks Aaron! The conflicts weren't straightforward to solve at all, but you have more context on the feature than I do 😄

@aaronrobertshaw
Copy link
Contributor Author

The conflicts weren't straightforward to solve at all, but you have more context on the feature than I do

Another source for the conflicts might be the removal of the lodash function use.

I've knocked up a quick draft in #53624 but am out of time, so I'll give it a proper test and once over tomorrow as promised.

@tellthemachines tellthemachines removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi 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
No open projects
Development

Successfully merging this pull request may close these issues.

Featured Image block: applying styles globally resets the border changes in the editor
7 participants