Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor defaults for themes with no editor styles and when user disables theme styles #35736

Merged
merged 11 commits into from
Oct 22, 2021

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Oct 18, 2021

Fixes #35730
Follow up to #35424 and #34439

In Gutenberg 11.5, we added some defaults for themes that didn't enqueue any editor styles, see #34439

In Gutenberg 11.7, we made every theme to have some styles in the editor: we provided at least the core presets. See #35424 As an unintended side effect of this change, there are no themes that don't provide editor styles anymore, hence we didn't provide any editor defaults for them.

This PR adds back some defaults for themes that don't provide any editor styles.

How to test

Make sure it works with "theme styles" deactivated

  • I've tested this with TwentyTwentyOne, TT1-blocks, EmptyTheme, and Nucleare. Can't test with TwentyTwenty because it enqueues some things directly, no with the editor styles API.
  • Go to the editor and in the "preferences" section disable "themes styles".
  • Verify that editor styles look the same across different themes.
  • Verify that presets work still as expected.

Nucleare

This branch v11.6 (last worked fine)
no-theme-styles-nucleare nucleare-no-theme-styles-v11-6

Empty theme

This branch v11.6 (last worked fine)
no-theme-styles-empty-theme no-theme-styles-empty-theme-v11-6-1

TT1 Blocks

This branch v11.6 (last worked fine)
no-theme-styles-tt1-blocks no-theme-styles-tt1-blocks-v11-6

TwentyTwentyOne

This branch v11.6 (last worked fine)
no-theme-styles-twenty-twenty-one no-theme-styles-twenty-twenty-one-v11-6

Make sure it works with "theme styles" activated

  • I've tested this with TwentyTwentyOne, TT1-blocks, EmptyTheme, and Nucleare. Can't test with TwentyTwenty because it enqueues some things directly, no with the editor styles API.
  • Go to the editor and in the preferences section enable "theme styles".
  • Verify that editor styles look proper for the same themes above.
  • Verify that presets work still as expected.

Nucleare

This branch v11.6 (last worked fine)
theme-styles-nucleare nucleare-theme-styles-v11-6

Empty theme

This branch v11.6 (last worked fine)
theme-styles-empty-theme theme-styles-empty-theme-v11-6

TT1 Blocks

This branch v11.6 (last worked fine)
theme-styles-tt1-blocks theme-styles-tt1-blocks-v11-6

TwentyTwentyOne

This branch v11.6 (last worked fine)
theme-styles-twenty-twenty-one theme-styles-twenty-twenty-one-v11-6

@github-actions
Copy link

github-actions bot commented Oct 18, 2021

Size Change: +43 B (0%)

Total Size: 1.07 MB

Filename Size Change
build/edit-post/index.min.js 29.4 kB +43 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.2 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/index.min.js 135 kB
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.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 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 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 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 549 B
build/block-library/blocks/button/style.css 549 B
build/block-library/blocks/buttons/editor-rtl.css 309 B
build/block-library/blocks/buttons/editor.css 309 B
build/block-library/blocks/buttons/style-rtl.css 317 B
build/block-library/blocks/buttons/style.css 317 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 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/columns/style-rtl.css 497 B
build/block-library/blocks/columns/style.css 496 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.17 kB
build/block-library/blocks/cover/style.css 1.17 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 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 322 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 977 B
build/block-library/blocks/gallery/editor.css 982 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 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/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 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 502 B
build/block-library/blocks/image/style.css 505 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 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 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 488 B
build/block-library/blocks/navigation-link/editor.css 489 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/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.71 kB
build/block-library/blocks/navigation/editor.css 1.71 kB
build/block-library/blocks/navigation/style-rtl.css 1.7 kB
build/block-library/blocks/navigation/style.css 1.69 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 198 B
build/block-library/blocks/page-list/style.css 198 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 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 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 396 B
build/block-library/blocks/post-featured-image/editor.css 397 B
build/block-library/blocks/post-featured-image/style-rtl.css 156 B
build/block-library/blocks/post-featured-image/style.css 156 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 391 B
build/block-library/blocks/post-template/style.css 392 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 60 B
build/block-library/blocks/post-title/style.css 60 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 378 B
build/block-library/blocks/pullquote/style.css 378 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 262 B
build/block-library/blocks/query-pagination/editor.css 255 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 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 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 250 B
build/block-library/blocks/separator/style.css 250 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 770 B
build/block-library/blocks/site-logo/editor.css 770 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 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 824 B
build/block-library/blocks/social-links/editor.css 823 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 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 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 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 815 B
build/block-library/common.css 812 B
build/block-library/editor-rtl.css 9.62 kB
build/block-library/editor.css 9.62 kB
build/block-library/index.min.js 149 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.3 kB
build/block-library/style.css 10.3 kB
build/block-library/theme-rtl.css 668 B
build/block-library/theme.css 673 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46 kB
build/components/index.min.js 212 kB
build/components/style-rtl.css 15.3 kB
build/components/style.css 15.3 kB
build/compose/index.min.js 10.4 kB
build/core-data/index.min.js 12.4 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.1 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.44 kB
build/edit-navigation/index.min.js 15.8 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/style-rtl.css 7.12 kB
build/edit-post/style.css 7.12 kB
build/edit-site/index.min.js 30.7 kB
build/edit-site/style-rtl.css 5.71 kB
build/edit-site/style.css 5.71 kB
build/edit-widgets/index.min.js 15.8 kB
build/edit-widgets/style-rtl.css 4.12 kB
build/edit-widgets/style.css 4.13 kB
build/editor/index.min.js 37.6 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.21 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.99 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 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.92 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.19 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.7 kB
build/server-side-render/index.min.js 1.52 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.74 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@oandregal oandregal added [Type] Bug An existing feature does not function as intended CSS Styling Related to editor and front end styles, CSS-specific issues. labels Oct 18, 2021
lib/global-styles.php Outdated Show resolved Hide resolved
@jasmussen
Copy link
Contributor

Thanks for the followup. What's a good way to test? And do you personally prefer this PR or #35737?

// settings.styles can have styles that core adds.
// We don't want these to count as "theme styles".
const filteredStyles = settings.styles?.length
? settings.styles.filter( ( style ) => ! style.toSkip )
Copy link
Contributor

Choose a reason for hiding this comment

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

So we're excluding these styles from the styles passed to the block editor. Why are we adding them in the backend in the first place then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I think I understand now: "preset styles" are included in settings.styles and we only want to check for the styles that comes from the theme.json styles or custom editor styles here.

I wonder if we should maybe expand on the __unstableType instead and clarify what each stylesheet is about, the "theme", "core" existing types don't seem to be enough anymore.

we need more granular things:

  • "core": Any core style that is loaded for all themes
  • "theme presets"
  • "theme styles" (theme.json or add_editor_styles calls)

It also seems like "theme presets" should also be included in the fallback in addition to settings.defaultEditorStyles to ensure the presets do work even if the user chooses to not user "theme styles" in its editor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I saw your comment on the other thread and now understand this better. Will continue to iterate on this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, essentially we want the ability to remove theme styles in the post editor, for which they need to be enqueued separately. We need this:

  1. theme.json styles (core)
  2. editor styles provided via add_editor_styles (theme)
  3. theme.json styles (theme)
  4. theme.json styles (user)
  5. preset classes (core, theme, user)
  6. preset css vars for the sidebar, are not processed by .editor-styles-wrapper (core, theme, user)

So when the user disables "theme styles" we recalculate styles without 2 & 3. Perhaps we also skip 1 as well? Does this look correct to you?

Copy link
Member Author

Choose a reason for hiding this comment

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

This use case is new for me, and it's making me reconsider how we do some things.: would the styles for editors be simpler if we let them access the raw data so they can calculate the stylesheets themselves?

In addition to what I've shared for the post editor above (the 6 stylesheet plus the __experimentalSettings as well), this is what we currently send to the site editor:

  • __experimentalGlobalStylesUserEntityId for theme.json user data
  • __experimentalGlobalStylesBaseConfig with theme.json data (core+theme)
  • __experimentalSettings theme.json settings (core+theme+user)
  • editor styles provided via add_editor_styles

What if we just sent these four pieces of data instead:

  • theme.json core
  • theme.json theme
  • theme.json user
  • editor styles provided via add_editor_styles

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the list above, I don't see why we should split 1, 2, and 4? It's fine if these are combined. and on the list you shared, the list from 1 to 4 are the things we want to exclude from the post editor if the user chooses to. So basically we only need to split presets and styles.

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't we want to keep user styles (4) in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think so, for me 4 is just the equivalent of custom CSS editor styles and when toggling the "theme styles", the user expect the same design across all themes.

@oandregal
Copy link
Member Author

Thanks for the followup. What's a good way to test? And do you personally prefer this PR or #35737?

Initially, I thought #35737 was a better approach but after some clarifications of the use cases to cover, I've closed that one and will focus on this direction instead. It needs a few tweaks, I'll ping you again when it's ready.

@@ -995,19 +995,6 @@ private function get_block_classes( $style_nodes ) {
$selector_duotone = self::scope_selector( $metadata['selector'], $metadata['duotone'] );
$block_rules .= self::to_ruleset( $selector_duotone, $declarations_duotone );
}

if ( self::ROOT_BLOCK_SELECTOR === $selector ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is going to make the existing tests for styles fail. I need to fix them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you have to remove this? This is not just for editor styles, it's also important for the frontend.

Copy link
Member Author

Choose a reason for hiding this comment

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

These styles are part of "block styles", hence, in the client, we can't distinguish the empty state (a theme with no "block classes").

Copy link
Member Author

@oandregal oandregal Oct 22, 2021

Choose a reason for hiding this comment

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

Note that these weren't removed, but moved to another place lib/compat/wordpress-5.9/spacing-styles.php

Copy link
Contributor

@youknowriad youknowriad Oct 22, 2021

Choose a reason for hiding this comment

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

These styles are part of "block styles", hence, in the client, we can't distinguish the empty state (a theme with no "block classes").

Is a theme with theme.json ever a theme without editor styles? IMO no, so I think it's fine to consider them theme editor styles.

Copy link
Contributor

Choose a reason for hiding this comment

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

The behavior of using the default editor styles in themes is specially tailored toward old themes that don't have any Gutenberg support (which is not the case for themes using theme.json)

Copy link
Member Author

@oandregal oandregal Oct 22, 2021

Choose a reason for hiding this comment

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

I was able to make this work properly while retaining those styles working as they are (commit).

After what you said, I realized that those spacing styles should not be enqueued for themes without theme.json, neither in the editor or the frontend. While that is true for the frontend, we do enqueue the spacing styles in the editor in trunk. So this is a bug that we're also fixing with this PR (here).

@oandregal
Copy link
Member Author

@youknowriad what are your thoughts on the current direction?

The main thing is that the "spacing styles" (align, block gap) can't be part of the block styles generated as they are today: we need the block styles to be empty for themes that don't provide any editor styles.

@oandregal oandregal added the [Status] In Progress Tracking issues with work in progress label Oct 21, 2021
@oandregal oandregal changed the title Enqueue some editor defaults for themes with no editor styles Editor defaults for themes with no editor styles and when user disables theme styles Oct 21, 2021
@oandregal oandregal force-pushed the fix/themes-with-no-editor-styles branch from 06c57fc to d50af2b Compare October 21, 2021 15:50
@oandregal
Copy link
Member Author

@jasmussen @chad1008 @youknowriad I've pushed all the changes and tested this across a number of themes. Left also test instructions in the issue description. It seems to work fine in my testing.

@chad1008
Copy link
Contributor

This tests well for me across different themes, with and without theme styles active. Thanks @oandregal!

@oandregal oandregal removed the [Status] In Progress Tracking issues with work in progress label Oct 22, 2021
*
* @return string Stylesheet.
*/
function gutenberg_experimental_global_styles_get_stylesheet( $tree, $type = null ) {
// Check if we can use cached.
$can_use_cached = (
Copy link
Member Author

Choose a reason for hiding this comment

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

The cache in this method is dead code, it's never used, so we can remove it.

@jasmussen
Copy link
Contributor

This appears to generally be working for me.

One thing I'm noticing, is that the theme colors are not used here, these are the default WordPress blues:
Screenshot 2021-10-22 at 09 52 56

Matías encountered the same issue in #35662 ("Disabling theme editor styles in preferences makes some elements in the page load with default colors and not the current color scheme."), so it may be a separate issue. But at the same time, I see this in trunk:
Screenshot 2021-10-22 at 09 55 39

that is — the default styles with fonts and such are incorrect, but the colors are correct.

@oandregal
Copy link
Member Author

@jasmussen I'm struggling to see what the issue is. Tested with the TT1-blocks them in a few branches (including v11.6, where the issue this PR fixes was not happening) and they all look the same to me. Tried in Firefox and Chrome with no differences.

With theme styles:

This branch Trunk v11.6
tt1-blocks-with-theme-styles-branch tt1-blocks-with-theme-styles-trunk tt1-blocks-with-theme-styles-v11-6

No theme styles:

This branch Trunk v11.6
tt1-blocks-no-theme-styles-branch tt1-blocks-no-theme-styles-trunk tt1-blocks-no-theme-styles-v11-6

@jasmussen
Copy link
Contributor

Go to your user profile and choose an admin color scheme other than the default one:
Screenshot 2021-10-22 at 11 45 28

Now observe that the color of the primary button remains #007cba (oldschool WordPress blue) even though it should be a color assigned by the color scheme. This might be an existing issue with trunk and "no editor styles", and not a result of this PR, but wanted to just clarify that bit.

@oandregal
Copy link
Member Author

This might be an existing issue with trunk and "no editor styles", and not a result of this PR, but wanted to just clarify that bit.

Oh, thanks for the instructions. I've checked v11.5, v11.6, trunk and this branch and all behave the same (colors don't represent the user color scheme), so it points to a different issue.

*
* @return string Stylesheet.
*/
public function get_stylesheet( $type = 'all', $origins = self::VALID_ORIGINS ) {
public function get_stylesheet( $types = array( 'css_variables', 'block_classes', 'preset_classes' ), $origins = self::VALID_ORIGINS ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if css_variables should be a type. I mean we don't really know where these variables are used and it seems we should always render them anyway regardless of what types are passed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you want to avoid duplication in the applied stylesheets.

Copy link
Member Author

Choose a reason for hiding this comment

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

responded #35736 (comment)

}

$new_block_classes = array(
'css' => 'block_classes',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unclear what this "type" is about?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is the theme styles generated from theme.json, the name is a bit confusing. It's not just about block classes, isn't it.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, these are the "types":

  • block_classes => whatever is in styles plus the "spacing styles" we add
  • css_variables => the css vars we generate for presets plus settings.custom (these need to be in scope for the sidebar UI controls, which is the main driver. They can't get rewritten by the editor-styles-wrapper while the other types can)
  • preset_classes => the classes for the presets

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just "styles", "variables" and "presets".

Copy link
Member Author

Choose a reason for hiding this comment

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

I perhaps can expand a bit more: for the preset UI controls to work, we need the CSS Custom Properties in the scope of the sidebar, as they use these values. They are currently scoped to body so we can't let the editor convert that to .editor-styles-wrapper.

Copy link
Member Author

Choose a reason for hiding this comment

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

Those names work for me.

(sorry, GitHub didn't show me your comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the names.

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.

This is looking good to me, the naming "block_classes" is a bit weird though.

@oandregal oandregal force-pushed the fix/themes-with-no-editor-styles branch from c83eb9d to c73e850 Compare October 22, 2021 11:44
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.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor styles are applied inconsistently for themes that do not support theme.json
4 participants