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

Enqueue preset styles for all themes in the editor #35424

Merged

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Oct 7, 2021

Follow-up to #34334

This fixes a bug by which preset classes were not added to the editor for all themes.

In #34334 I missed enqueueing the preset classes in the editor for all themes. When they were removed from the base-style package at #34510 they started to be missing in the editor.

Why this wasn't noticeable before

In the editor, when the user selects a color from the preset palette, classes are added to it. The block also gets inline styles for legacy reasons. That we inline styles hid the fact that we were not enqueueing preset classes in the editor.

Setup affected by this bug

This only affected blocks that don't use our support hooks (so they don't get inline styles) when the active theme is a classic one (no theme.json or legacy link color support) that also delegated the enqueueing of preset classes to core (either because they don't define any preset or because they do but don't enqueue it themselves). A example of this is the Storefront theme.

This was introduced in Gutenberg 11.5.

How to test

  • Use the Storefront theme.
  • Add a paragraph block and set some colors.
  • Open the devtools and remove the inline styles added to the paragraph in the editor.

The expected result is that the paragrah still has the colors applied (because the classes are now in scope).

Another check you can do is to verify the core classes are present, such as: .has-vivid-red-color, .has-luminous-vivid-orange-background-color, etc. See full list of colors. The classes generated are in the form of .has-$slug-color, .has-$slug-background-color.

@oandregal oandregal self-assigned this Oct 7, 2021
@oandregal oandregal added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [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 labels Oct 7, 2021
@oandregal oandregal requested review from senadir and Aljullu October 7, 2021 09:45
@oandregal oandregal changed the title Enqueue preset classes for all themes in the editor Enqueue preset styles for all themes in the editor Oct 7, 2021
@oandregal oandregal requested a review from a team October 7, 2021 10:15
@oandregal oandregal added this to the Gutenberg 11.7 milestone Oct 7, 2021
Copy link
Contributor

@senadir senadir left a comment

Choose a reason for hiding this comment

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

This tests fine for me!

@oandregal oandregal force-pushed the fix/preset-classes-for-themes-that-dont-provide-any branch from ff10d3b to e265764 Compare October 7, 2021 16:11
if (
'site-editor' !== $context &&
'mobile' !== $context &&
( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() || get_theme_support( 'experimental-link-color' ) )
Copy link
Member Author

@oandregal oandregal Oct 7, 2021

Choose a reason for hiding this comment

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

We no longer need to check for theme.json presence of legacy link color support, because we now enqueue the preset styles for all themes.

We can also simplify the double negation by using all instead.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

The change makes sense to me 👍

Copy link
Contributor

@senadir senadir left a comment

Choose a reason for hiding this comment

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

Still works after the update!

@oandregal
Copy link
Member Author

oandregal commented Oct 18, 2021

This inadvertently introduced a bug for themes that do not provide any editor styles. See #35730 (comment) and potential fixes #35736 and #35737

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants