-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Don't output preset classes for colors defined by the theme #35514
Conversation
@@ -739,11 +739,11 @@ private static function get_settings_values_by_slug( $settings, $preset_metadata | |||
* | |||
* @return array Array of presets where the key and value are both the slug. | |||
*/ | |||
private static function get_settings_slugs( $settings, $preset_metadata ) { | |||
private static function get_settings_slugs( $settings, $preset_metadata, $origins = self::VALID_ORIGINS ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was trying to understand how this change was different than the existing code, but then I realized I was missing the bigger picture: how get_settings_slugs
was being called.
It looks like when we introduced this function from a refactoring we forgot to add the last parameter (see).
This is what happened as far as I understand: we introduced the |
I've milestoned this for 11.7 as it fixes a bug we detected during the testing period for a PR introduced in 11.7 as well. |
…theme (#35514) * Global Styles: Don't output preset classes for colors defined by the theme * Make linter happy Co-authored-by: André <583546+oandregal@users.noreply.github.com>
Description
I think this is a regression introduced in #34334.
Consider a classic theme without a theme.json file, which adds a theme support for
editor-color-palette
. Because these colors get included in the theme.json viaget_from_editor_settings
, when we callget_preset_classes
, these color classes from the theme origin are being output. So for example if you are using the "Canard" theme, Global Styles outputs some CSS like this:However the CSS variable isn't defined, but it doesn't get ignored, instead it seems to fall back to the broswer default.
So the root of the problem is that the CSS variables used by
get_preset_classes
don't match the variables output byget_css_variables
. This is becauseget_css_variables
only outputs CSS variables defined on thecore
origin, whereasget_preset_classes
doesn't filter out origins.This PR adds a filter to
get_settings_slugs
which is used byget_preset_classes
to only output settings that are defined on the passed origins. The alternative approach would be to remove the filter fromget_settings_values_by_slug
and output the CSS variables for both the theme and core origins. In some ways this is preferable as it lightens the load for themes to opt into Global Styles, but it might create unexpected changes.How has this been tested?
Screenshots
Before:
After:
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).