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

Fix default duotone preset SVG and style generation #38681

Merged
merged 22 commits into from
Mar 9, 2022

Conversation

ajlende
Copy link
Contributor

@ajlende ajlende commented Feb 9, 2022

Description

This is fixing two issues that both depend on having a new defaultDuotone option in theme.json.

Fix #38299

Prevents the respective styles and SVGs from generating when defaultPalette, defaultGradients, or defaultDuotone are set to false in theme.json settings.

In non-fse themes these settings are false by default. Colors and gradients have editor-color-palette and editor-gradient-presets to enable them from #36496.

In fse themes with a theme.json, these settings are true by default.

Fix #38690

This makes duotone filters behave more like the colors and gradients.

Enables multi origin colors and duotone presets to be added to the UI.

Adds defaultDuotone to disable the default palette from generating.

As a follow-up, we'll want to update the UI to indicate where the presets are coming from like in #35970

Testing Instructions

In both a classic (non-fse) theme and a block (fse/theme.json) theme with defaultDuotone disabled:

  1. View any page/post that doesn't contain a block with duotone applied to it.
  2. See that no duotone SVGs or CSS variables are generated (by searching for "duotone" in the html).

In a block (fse) theme with defaultDuotone enabled and theme duotone presets included:

  1. Open the duotone palette for a block that supports it.
  2. See both the default and theme duotone presets in the list.

Screenshots

Classic Theme (Twenty Twenty)


Block Theme "defaultDuotone": true (Skatepark, default)


Block Theme "defaultDuotone": false (Skatepark, edited)


Types of changes

New feature, bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
  • I've updated related schemas if appropriate.

@ajlende ajlende 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 Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release labels Feb 9, 2022
@ajlende ajlende requested a review from oandregal February 9, 2022 21:17
@ajlende ajlende self-assigned this Feb 9, 2022
@github-actions
Copy link

github-actions bot commented Feb 10, 2022

Size Change: +88 B (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-editor/index.min.js 144 kB +88 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/admin-manifest/index.min.js 1.24 kB
build/annotations/index.min.js 2.77 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.49 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 14.8 kB
build/block-editor/style.css 14.8 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 65 B
build/block-library/blocks/archives/style.css 65 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 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 103 B
build/block-library/blocks/code/style.css 103 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 406 B
build/block-library/blocks/columns/style.css 406 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-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 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-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.56 kB
build/block-library/blocks/cover/style.css 1.56 kB
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 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 965 B
build/block-library/blocks/gallery/editor.css 967 B
build/block-library/blocks/gallery/style-rtl.css 1.61 kB
build/block-library/blocks/gallery/style.css 1.61 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 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 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 522 B
build/block-library/blocks/image/style.css 528 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 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 493 B
build/block-library/blocks/media-text/style.css 490 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 649 B
build/block-library/blocks/navigation-link/editor.css 650 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 375 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.89 kB
build/block-library/blocks/navigation/style.css 1.88 kB
build/block-library/blocks/navigation/view.min.js 2.85 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 363 B
build/block-library/blocks/page-list/editor.css 363 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 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 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/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 521 B
build/block-library/blocks/post-comments/style.css 521 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/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 323 B
build/block-library/blocks/post-template/style.css 323 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 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 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 201 B
build/block-library/blocks/quote/style.css 201 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 202 B
build/block-library/blocks/rss/editor.css 204 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 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 744 B
build/block-library/blocks/site-logo/editor.css 744 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 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 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 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.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 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 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 235 B
build/block-library/blocks/template-part/editor.css 235 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/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 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 934 B
build/block-library/common.css 932 B
build/block-library/editor-rtl.css 9.92 kB
build/block-library/editor.css 9.92 kB
build/block-library/index.min.js 168 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 11.4 kB
build/block-library/style.css 11.4 kB
build/block-library/theme-rtl.css 665 B
build/block-library/theme.css 670 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 46.4 kB
build/components/index.min.js 217 kB
build/components/style-rtl.css 15.6 kB
build/components/style.css 15.6 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 14 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.39 kB
build/customize-widgets/style.css 1.39 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.03 kB
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.53 kB
build/edit-navigation/index.min.js 16.1 kB
build/edit-navigation/style-rtl.css 4.04 kB
build/edit-navigation/style.css 4.05 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 29.9 kB
build/edit-post/style-rtl.css 7.07 kB
build/edit-post/style.css 7.07 kB
build/edit-site/index.min.js 41.9 kB
build/edit-site/style-rtl.css 7.43 kB
build/edit-site/style.css 7.42 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.39 kB
build/edit-widgets/style.css 4.39 kB
build/editor/index.min.js 38.4 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 kB
build/element/index.min.js 4.29 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.83 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 957 B
build/nux/index.min.js 2.12 kB
build/nux/style-rtl.css 751 B
build/nux/style.css 749 B
build/plugins/index.min.js 1.98 kB
build/preferences/index.min.js 1.2 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 611 B
build/react-i18n/index.min.js 704 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.69 kB
build/reusable-blocks/index.min.js 2.24 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.1 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.94 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.21 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

@skorasaurus
Copy link
Member

skorasaurus commented Feb 10, 2022

Thanks for all of your work on this; I look forward to this eventually being integrated into trunk.

I'm not sure what you mean by an 'FSE' theme (a theme that uses exclusively blocks and no PHP templates? a theme that has a theme.json ?)

Using the @annezazu 's definitions, could you clarify which themes you'd recommend to test?

_Classic theme: a theme built the way we’ve been used to with PHP templates, functions.php, and more.
Block theme: a theme made for FSE using HTML templates and theme.json, allowing one to manage all parts of their site with blocks.
Hybrid theme: a classic theme that adopts a feature(s) of FSE, like theme.json or the template editor (some insights here) https://developer.wordpress.org/themes/block-themes/converting-a-classic-theme-to-a-block-theme/
Universal theme: a theme that works with both the Customizer and the Site Editor._

Tested:

Twentyseventeen 2.9 (no modifications made to theme), WordPress 5.9, and gutenberg built as of 36782a3 :

On page when no blocks containing a duotone were present and gutenberg activated
CSS variables for the duotone were still present; with the global-styles-inline-css (searching for duotone in source html, returned 16 results, all within the global-styles-inline-css
The dutone SVGs were not present.

On page when no blocks containing a duotone and When gutenberg was not activated:
duotone returned 24 results; global-styles-inline-css and in the SVGs at the bottom of the page.

Note: After publishing a page with a block containing a gradient (made when 36782a3 was activated); I deactivated the plugin.
When you view the page and relying solely on 5.9; the gradient does not appear; and when entering block editor, the block (in this instance, it was a cover block), block validation failed and I was presented with the block recovery screen.


TwentyTwenty (with this theme.json ) WordPress 5.9, and gutenberg built as of https://github.com/WordPress/gutenberg/pull/38681/commits /36782a3557e0f536d7dfb2082d8186ae3508d1f0 (defaultPalette, defaultGradients, or defaultDuotone all set to false):

On page when no blocks containing a duotone were present and gutenberg activated
CSS variables for the duotone were still present; with the global-styles-inline-css (searching for duotone in source html, returned 16 results, all within the global-styles-inline-css
The dutone SVGs were not present.

On page when no blocks containing a duotone and When gutenberg was not activated:
duotone returned 24 results; global-styles-inline-css and in the SVGs at the bottom of the page.


@ajlende
Copy link
Contributor Author

ajlende commented Feb 11, 2022

@skorasaurus thanks for taking an early look! I'm still actively working on this branch which is why it is marked as a draft and some things are not working as expected. Things were working properly until I rebased with trunk today, so I will be sorting that out tomorrow. When it is ready for review, I will move the PR out of draft, and I can request a review from you at that point.

@ajlende ajlende force-pushed the fix/default-duotone-generation branch from 36782a3 to 18b6f62 Compare February 11, 2022 17:48
@ajlende
Copy link
Contributor Author

ajlende commented Feb 11, 2022

If I understand the release process for 5.9.1, the changes in lib/compat/wordpress-5.9 marked as Backport to WP Minor Release will be merged into core. So any changes that will be backported should be tested against the WP 5.8 branch. Is that correct @oandregal?

This PR depends on #36236 which didn't make it into WP 5.9, so the duotone styles are still being generated in wp_get_global_stylesheet in core which isn't overridden by the plugin. If testing against WP 5.9, you should expect to see two sets of default duotone filters prior to this change and only one with this change.

I figured out #38701 is what caused the issue when I rebased yesterday. When running the plugin on the 5.8 branch, it causes the styles to not show up. I've rebased to just before this change for testing.

@ajlende ajlende marked this pull request as ready for review February 11, 2022 18:03
@ajlende ajlende requested a review from skorasaurus February 11, 2022 18:05
@skorasaurus
Copy link
Member

skorasaurus commented Feb 14, 2022

Thanks for following up:


TwentyTwenty (with this theme.json ) WordPress 5.9, and gutenberg built as of 18b6f62 (defaultPalette, defaultGradients, or defaultDuotone all set to false):

On page when no blocks containing a duotone were present and gutenberg activated:
CSS variables for the duotone were still present; with the global-styles-inline-css (searching for duotone in source html, returned 16 results, all within the global-styles-inline-css
The duotone SVGs were not present.

On page when no blocks containing a duotone and When gutenberg was not activated:
duotone returned 24 results; The global-styles-inline-css included duotones and duotone SVGs were at the bottom of the page.


@ajlende
Copy link
Contributor Author

ajlende commented Feb 15, 2022

@skorasaurus Thanks for testing again!

CSS variables for the duotone were still present; with the global-styles-inline-css (searching for duotone in source html, returned 16 results, all within the global-styles-inline-css

I tried your theme.json file, but couldn't reproduce the variables being generated in global-styles-inline-css.

My generated <style id="global-styles-inline-css">...</style> (click to expand)

<style id="global-styles-inline-css">
body {
	--wp--preset--color--primary-blue: #0057B7;
	--wp--preset--color--primary-gold: #E9E186;
	--wp--preset--color--white: #FFFFFF;
	--wp--preset--color--black: #000000;
	--wp--preset--color--sec-salmon: #FF8D7E;
	--wp--preset--color--sec-goldenrod: #F1C400;
	--wp--preset--color--sec-aqua: #94B7BB;
	--wp--preset--color--sec-teal: #4298B5;
	--wp--preset--color--sec-green: #56944F;
	--wp--preset--font-size--small: 13px;
	--wp--preset--font-size--medium: 20px;
	--wp--preset--font-size--large: 36px;
	--wp--preset--font-size--x-large: 42px;
}
body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.has-primary-blue-color {
	color: var(--wp--preset--color--primary-blue) !important;
}
.has-primary-gold-color {
	color: var(--wp--preset--color--primary-gold) !important;
}
.has-white-color {
	color: var(--wp--preset--color--white) !important;
}
.has-black-color {
	color: var(--wp--preset--color--black) !important;
}
.has-sec-salmon-color {
	color: var(--wp--preset--color--sec-salmon) !important;
}
.has-sec-goldenrod-color {
	color: var(--wp--preset--color--sec-goldenrod) !important;
}
.has-sec-aqua-color {
	color: var(--wp--preset--color--sec-aqua) !important;
}
.has-sec-teal-color {
	color: var(--wp--preset--color--sec-teal) !important;
}
.has-sec-green-color {
	color: var(--wp--preset--color--sec-green) !important;
}
.has-primary-blue-background-color {
	background-color: var(--wp--preset--color--primary-blue) !important;
}
.has-primary-gold-background-color {
	background-color: var(--wp--preset--color--primary-gold) !important;
}
.has-white-background-color {
	background-color: var(--wp--preset--color--white) !important;
}
.has-black-background-color {
	background-color: var(--wp--preset--color--black) !important;
}
.has-sec-salmon-background-color {
	background-color: var(--wp--preset--color--sec-salmon) !important;
}
.has-sec-goldenrod-background-color {
	background-color: var(--wp--preset--color--sec-goldenrod) !important;
}
.has-sec-aqua-background-color {
	background-color: var(--wp--preset--color--sec-aqua) !important;
}
.has-sec-teal-background-color {
	background-color: var(--wp--preset--color--sec-teal) !important;
}
.has-sec-green-background-color {
	background-color: var(--wp--preset--color--sec-green) !important;
}
.has-primary-blue-border-color {
	border-color: var(--wp--preset--color--primary-blue) !important;
}
.has-primary-gold-border-color {
	border-color: var(--wp--preset--color--primary-gold) !important;
}
.has-white-border-color {
	border-color: var(--wp--preset--color--white) !important;
}
.has-black-border-color {
	border-color: var(--wp--preset--color--black) !important;
}
.has-sec-salmon-border-color {
	border-color: var(--wp--preset--color--sec-salmon) !important;
}
.has-sec-goldenrod-border-color {
	border-color: var(--wp--preset--color--sec-goldenrod) !important;
}
.has-sec-aqua-border-color {
	border-color: var(--wp--preset--color--sec-aqua) !important;
}
.has-sec-teal-border-color {
	border-color: var(--wp--preset--color--sec-teal) !important;
}
.has-sec-green-border-color {
	border-color: var(--wp--preset--color--sec-green) !important;
}
.has-small-font-size {
	font-size: var(--wp--preset--font-size--small) !important;
}
.has-medium-font-size {
	font-size: var(--wp--preset--font-size--medium) !important;
}
.has-large-font-size {
	font-size: var(--wp--preset--font-size--large) !important;
}
.has-x-large-font-size {
	font-size: var(--wp--preset--font-size--x-large) !important;
}

</style>

It could be a caching issue since the SVGs and stylesheets are cached separately (which may be another issue for another PR). I think the cache only lasts a minute, but you can also disable it by adding the following to wp-config.php.

define( 'WP_DEBUG', true );
define( 'SCRIPT_DEBUG', true );

@skorasaurus
Copy link
Member

Thanks again for the tip re: adding ; I've done that in 2 different testing sites and still am able to reproduce the results as I shared above. I'm not quite sure what I'm doing incorrectly.

I followed Steps 1-4, as follows;
I replaced npm run build with npm run build:plugin-zip because I like to test across a couple different installations that have different themes, content.

git fetch upstream pull/38681/head

git checkout 18b6f62213631e89662c2f057df0e0931ee2d836

npm install

npm run build:plugin-zip

I will then copy the zip into a couple other installations, activate the plugin.

@gwwar
Copy link
Contributor

gwwar commented Feb 15, 2022

@ajlende is this intended to be tested with a WordPress-develop patch too? I tested this against a clean 5.9 instance, Theme: 2017, Gutenberg activated to this branch and I see default filters added and referenced in global styles:

CleanShot 2022-02-15 at 15 10 55@2x

@ajlende
Copy link
Contributor Author

ajlende commented Feb 15, 2022

@gwwar and @skorasaurus I think the problem may be that you're testing against WP 5.9 instead of WP 5.8.

I was incorrect when I said, "If testing against WP 5.9, you should expect to see two sets of default duotone filters prior to this change and only one with this change." What you're both seeing is actually what is expected when testing against 5.9 instead of 5.8—no SVGs, but the CSS variables still getting generated in the stylesheet.

The code rendering the stylesheet is in get-global-styles-and-settings.php. The function for rendering stylesheets already exists in 5.9, so the function in the lib/compat/wordpress-5.9 folder isn't loaded for those. The function for rendering the SVGs was not included in 5.9, so it still gets included when testing against 5.9.

According to an earlier conversation, the changes in lib/compat/wordpress-5.9 with the "Backport to WP Minor Release" tag will be included in 5.9.1. Because of that, any functions defined in lib/compat/wordpress-5.9 that were already included in 5.9 need to be tested against 5.8 or they won't be loaded.

Hopefully my explanation makes sense, but I can elaborate and rephrase things if it doesn't 🙂

@gwwar
Copy link
Contributor

gwwar commented Feb 16, 2022

The function for rendering the SVGs was not included in 5.9, so it still gets included when testing against 5.9.

Right, so was there an equivalent WordPress-develop PR to test? Or should we test against the 5.9 branch directly?

In terms of manual testing for the related issue, I'd expect us to need to test against the 5.8/5.9 lines with both Gutenberg enabled and disabled. It'd also be super helpful to update the summary with an example literal before/after output for a particular theme.

@ajlende
Copy link
Contributor Author

ajlende commented Feb 16, 2022

Right, so was there an equivalent WordPress-develop PR to test? Or should we test against the 5.9 branch directly?

You should be testing with this branch and WP 5.8 (not 5.9) which can be the wordpress-develop 5.8 branch or 5.8.3 from the releases.

The files in lib/compat/wordpress-5.9 add features from the Gutenberg plugin to earlier versions, so we need the earlier version in order for the changes here to load. There isn't a patch for wordpress-develop 5.9 because that patch will be generated from the merged PRs with the "Backport to WP Minor Release" label.

Maybe @gziolo can correct me if I'm wrong. Figuring out how these changes need to be included in 5.9.1 is a bit confusing.

In terms of manual testing for the related issue, I'd expect us to need to test against the 5.8/5.9 lines with both Gutenberg enabled and disabled. It'd also be super helpful to update the summary with an example literal before/after output for a particular theme.

👍 I'll add that (but maybe not until tomorrow morning, it's getting kind of late here)

@Mamaduka Mamaduka removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Mar 28, 2022
@mcsf
Copy link
Contributor

mcsf commented Mar 28, 2022

I've been pondering this one for a while, as — per #38681 (comment) —  it needs some sort of clear decision amongst the participants of this PR, and subsequently it might need clear communication with the community in case of changes to existing behaviour.

There are clear downsides with whichever decision we make, but ultimately we need to honour the fact that defaultPalette and defaultGradient options were designed as UI switches and the fact that these default palette and gradient were designed to always¹ be enqueued. They have been around long enough for third-party uses that we can't responsibly change their inclusion conditions. Lastly, if nothing else, it's a requirement for the correct operation of block patterns that they remain enqueued.

That said, these constraints don't apply to Duotone. Seeing as it is also the most expensive feature of the three, there is an opportunity to try something new here and not enqueue its styles when the Duotone option is disabled.

I discussed this with Matías to check my judgment and he's on board. /cc @ajlende @oandregal @youknowriad


¹: Save for explicit intervention, of course.

@ajlende
Copy link
Contributor Author

ajlende commented Mar 29, 2022

Seeing as it is also the most expensive feature of the three, there is an opportunity to try something new here and not enqueue its styles when the Duotone option is disabled.

I want to avoid treating duotone as a special case. From a themer's perspective and from a user's perspective duotone is just another style that can be applied to their site. When the behavior of defaultPalette differs from the behavior of defaultDuotone, users are going to interpret that as a bug. Then, from a development perspective, if we begin making too many exceptions for duotone, it's going to become increasingly likely for the behavior to diverge (palette/gradients get updated without updating duotone or vice versa) which wouldn't be good for the user experience.

@mcsf
Copy link
Contributor

mcsf commented Mar 30, 2022

I want to avoid treating duotone as a special case. […]

Fair enough, special-casing duotone was a secondary concern. And as to reverting for defaultPalette and defaultGradient?

@ajlende
Copy link
Contributor Author

ajlende commented Mar 30, 2022

And as to reverting for defaultPalette and defaultGradient?

I've thought of a couple options.

  1. Increment the theme.json version. In the new version, the default* options maintain the behavior added in this PR. Theme authors can opt-in to the new behavior by incrementing the version.
  2. Add a new default*Generation option that uses the behavior added in this PR. The behavior of the defaultPalette and defaultGradients options from this PR are reverted, and defaultDuotone gets changed to only disabling the UI.

I like the simplicity of the first one. From the discussion in #38299, many people already expected the options to behave like they do in this PR, so I don't know if the functionality will be missed to toggle them separately.

@youknowriad
Copy link
Contributor

Reading the discussion here. There are a few things that click with me.

I think we shouldn't disregard the principle we set for block patterns. We've always committed to the fact that block patterns should be allowed to use "core" palettes and work cross themes. This is not something we can break I think. I also think even core duotone should be usable in block patterns.

So adding default*generation or a new version for theme.json is the same thing, we're breaking the premise above. So I don't think it's something we should be doing.

The other thing I wanted to mention is that duotone is different than colors in a lot of ways and I think being consistent here is just harming us more than solving anything. It is different regardless of how defaultGradients work.

  • Duotone styles is always applied server side.
  • Color styles are persisted in the markup.

This is an important distinction because it opens a lot of opportunities for us. It means we can change how duotone is applied without breaking changes. It also means that we don't persist any classname in the markup.

Based on this, I think the ideal solution here is to rollback to how duotone initially worked. Instead of treating them like "presets" where you generate classnames for themes and attach classnames to blocks... consider the styles being generated by duotone as "server side inline styles" (like we do for layout styles for instance). Basically, for each duotone used in a block, output the style by the block.

The pros here are:

  • No global stylesheet added for all themes, regardless of whether they allow core duotone presets, they hide them or even if they provide their own.
  • Only the pages that actually use duotone load these styles. Meaning a use-cases that is not addressed now is solved: We can use duotone sporadically (the most common use case IMO) without hurting the size of the stylesheets loaded by your theme/pages.

The potential con:

  • Duplication: If you use the same duotone twice in a page, you're duplicating a style that might not be necessary. I would argue here that this is not that bad, because duplicating 4/5 duotone styles in the page is still less expensive than loading the whole presets styles.

Let's also consider that that last point is something we don't want, we can introduce deduplication in the optimization phase of the generated styles. It's actually an area that some folks are working on (in a so called style engine) cc @andrewserong @ramonjd and others. So it's not specific to duotone at all and we can start an adhoc solution in duotone while expanding this to any style as well.


If reverting to the old way of judged too ambitious/impactful for now, I'm fine with reverting default* to the previous behavior as well for now (WP 6.0 beta next week).

@jasmussen
Copy link
Contributor

Let's also consider that that last point is something we don't want, we can introduce deduplication in the optimization phase of the generated styles. It's actually an area that some folks are working on (in a so called style engine)

Sounds good. Skatepark sets a duotone filter by default on all images, which presumably in that situation would cause a great deal of duplication on archive pages.

@youknowriad
Copy link
Contributor

youknowriad commented Mar 31, 2022

Sounds good. Skatepark sets a duotone filter by default on all images, which presumably in that situation would cause a great deal of duplication on archive pages.

It depends how the "default" is added. If it's a global styles (theme.json) config, it only generates the style once.

@ajlende
Copy link
Contributor Author

ajlende commented Mar 31, 2022

Thanks @youknowriad for the thoughtful response. Hearing the specifics is helping me understand your concerns more fully.

This is my understanding of the situation:

  • For block patterns (that use per-block rendering), theme.json preset generation for colors/gradients (.has-midnight-gradient-background) is required unless the color is custom; whereas, theme.json preset generation for duotone is irrelevant.
  • For global styles, theme.json preset generation is required in all cases (but we can be smart about including specific ones by scanning the page for blocks and elements that use it with the styles engine).

The other thing I wanted to mention is that duotone is different than colors in a lot of ways and I think being consistent here is just harming us more than solving anything. It is different regardless of how defaultGradients work.

  • Duotone styles is always applied server side.
  • Color styles are persisted in the markup.

Based on this, I think the ideal solution here is to rollback to how duotone initially worked. Instead of treating them like "presets" where you generate classnames for themes and attach classnames to blocks... consider the styles being generated by duotone as "server side inline styles" (like we do for layout styles for instance). Basically, for each duotone used in a block, output the style by the block.

For individual blocks, we are not generating classnames for duotone or attaching the classnames to blocks—that hasn't changed. The rendering for individual blocks is necessarily different due to the kses requirement of rendering the SVGs on the server, the CSS requirement that the filter property cannot be applied to a block's container, and the Safari requirement that SVGs must be rendered before the filtered content in the body of the document*.

However, for the global styles in question gradients/colors are not that different! Duotone still generates a selector and CSS using the same code for colors/gradients. The only** difference is that duotone also has to generate the SVGs in the document body.

body {
  /* Generated gradient CSS variable */
 --wp--preset--color--black: #000000;

  /* Generated duotone CSS variable */
  --wp--preset--duotone--grayscale: url('#wp-duotone-grayscale');
}

/* Generated global styles gradient */
a {
	color: var(--wp--preset--color--black);
}

/* Generated global styles duotone */
.wp-block-image img {
	filter: var(--wp--preset--duotone--grayscale);
}

* Or use hacks to repaint the filtered content in Safari.
** There's currently an ad-hoc solution for the nested selector (__experimentalDuotone in block.json) so that it can apply to something inside the block container, but the usefulness of that goes beyond the CSS filter property, and I'd like to see that moved to something more robust like block.json selectors that I proposed earlier.


This might be another no-go solution because I haven't read through the internals for block patterns, but could we require block patterns to always save using custom colors?

Instead of this:

<!-- wp:group {"gradient":"midnight"} -->
<div class="wp-block-group has-midnight-gradient-background has-background"><!-- wp:paragraph -->
<p>Grouped content with a background gradient</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

We save this:

<!-- wp:group {"style":{"color":{"gradient":"linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 95%)"}}} -->
<div class="wp-block-group has-background" style="background:linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%)"><!-- wp:paragraph -->
<p>Grouped content with a background gradient</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

We could even reverse-lookup the gradient in the active palettes to convert it back when the pattern is used. That way themes that don't want to include the default palette don't have to worry about it, and block patterns will still work.


With 6.0 being so close and this still not having a decision, for now this is what I will do:

  1. Open a PR that:
    • reverts the behavior of defaultGradient and defaultPalette
    • keeps the combined default+theme palette for duotone
    • defaultDuotone will follow the same behavior of only disabling the UI
  2. Reopen WP 5.9 adds default Duotones before closing the body #38299
  3. Continue discussing potential solutions that are less heavy-handed than waiting for the styles engine to solve it. This is an important issue to folks, and I want to get it resolved sooner rather than later.

@youknowriad
Copy link
Contributor

Thanks for the reply, there something I'd like to clarify on your answer above.

So If I'm understanding properly, we only need the presets styles when duotone is applied as a style in theme.json, am I right?

Why can't we just avoid including the filters and SVGs in the body of the page unless the duotone in question is actually used in the style object? Basically instead of regenerating the whole list of filter variables and svgs from in the presets style generation, do it in the actual "style" object processing and only include what's actually used? (Basically and unless I'm missing something, it's just moves the same code from one function to another in theme json class or something like that)

@ajlende
Copy link
Contributor Author

ajlende commented Apr 1, 2022

So If I'm understanding properly, we only need the presets styles when duotone is applied as a style in theme.json, am I right?

For things generated by global styles, yes. But themers can still use the generated CSS custom properties in their own CSS files that we can't easily scan. For example the Archeo theme uses color presets, but could just as easily use duotone presets. https://github.com/Automattic/themes/blob/trunk/archeo/style.css#L44

It seems like a bad experience for themers if the colors work, but duotone doesn't in that scenario.

@youknowriad
Copy link
Contributor

For things generated by global styles, yes. But themers can still use the generated CSS custom properties in their own CSS files that we can't easily scan. For example the Archeo theme uses color presets, but could just as easily use duotone presets. https://github.com/Automattic/themes/blob/trunk/archeo/style.css#L44

I think it's fine personally, one of the main point of block themes is that themes don't use CSS anymore (or less) and because duotone is complex, I expect most themes will rely on block customization (block support) to add duotone to their templates.

@ajlende
Copy link
Contributor Author

ajlende commented Apr 1, 2022

I think it's fine personally, one of the main point of block themes is that themes don't use CSS anymore (or less) and because duotone is complex, I expect most themes will rely on block customization (block support) to add duotone to their templates.

Worst case scenario, we can add an option to opt-in to rendering all of them if a theme author needs them. And it's a pretty simple solution that will cover a lot of cases. I'll make a follow-up to #39966 to try it out.

@oandregal
Copy link
Member

Considering this PR is not going to be ported to a 5.9 minor, we should revert all the changes done in the lib/compat/5.9 folder and port them to lib/compat/6.0.

@gziolo
Copy link
Member

gziolo commented Apr 6, 2022

Considering this PR is not going to be ported to a 5.9 minor, we should revert all the changes done in the lib/compat/5.9 folder and port them to lib/compat/6.0.

Does it mean that we still need to backport any changes to WordPress trunk for 6.0? Or is it only to ensure that we have shims for WordPress 5.9 covered?

@oandregal
Copy link
Member

I believe so. Note that part of this is being reverted at #39966

ajlende pushed a commit to ajlende/wordpress-develop that referenced this pull request Apr 7, 2022
oandregal added a commit that referenced this pull request Apr 7, 2022
pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Apr 11, 2022
Follow-up for [53129].

This PR backports the remaining `defaultDuotone` option changes added in the Gutenberg plugin. Related PRs: WordPress/gutenberg#38681 and WordPress/gutenberg#39966.

Props oandregal, ajlende.
See #55505.
 



git-svn-id: https://develop.svn.wordpress.org/trunk@53130 602fd350-edb4-49c9-b593-d223f7449a82
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Apr 11, 2022
Follow-up for [53129].

This PR backports the remaining `defaultDuotone` option changes added in the Gutenberg plugin. Related PRs: WordPress/gutenberg#38681 and WordPress/gutenberg#39966.

Props oandregal, ajlende.
See #55505.
 


Built from https://develop.svn.wordpress.org/trunk@53130


git-svn-id: https://core.svn.wordpress.org/trunk@52719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Apr 11, 2022
Follow-up for [53129].

This PR backports the remaining `defaultDuotone` option changes added in the Gutenberg plugin. Related PRs: WordPress/gutenberg#38681 and WordPress/gutenberg#39966.

Props oandregal, ajlende.
See #55505.
 


Built from https://develop.svn.wordpress.org/trunk@53130


git-svn-id: http://core.svn.wordpress.org/trunk@52719 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@sitoexpress
Copy link

sitoexpress commented May 24, 2022

I am sorry to introduce myself in a conversation that's maybe already ended, however I'd like to point out one thing because I'm reading here and in other threads that duotone filters are considered and treated just like a color scheme/palette equivalent.

I cannot understand how it can be for real. As @youknowriad already explained, there are some technical differences amongst the two, being Duotone filters applied server side, while a color scheme is persistent in the markup.

However I think that the issue should be solved by looking at the very conceptual difference between Duotone Filters and color presets:

  • Color presents are likely vital and necessary. They're a commodity for any theme developer/user. You cannot have a website without colors. 99% of the people are going to use them.
  • Duotone filters, on the other hand, are just an additional feature. Since they're complex and (very) rarely used, theme/plugin developers will likely rely on their own implementation of the thing (as maybe they're not even considering Gutenberg as crucial). You definitely can have a website without duotone filters and hey, that's the vast majority of them. Maybe 1% of the paople are going to use them.

So, just for saying, this thing (i dont know what else to call it) should be just removed from core. It can be an additional Jetpack feature, it can be a block adding the thing, it can be a plugin or whatever, but just not core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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