You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[WP 6.1] Block-specific global styles don't seem to save #44434
Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended
Moving here along with some added visuals to help out better understand the issue.
I could reproduce it with multiple blocks like paragraph, heading, button, site title, etc. It doesn't seem to be happening with all of the blocks, though.
The issue isn't specific to only colors. It's happening with other properties of a block too.
Block-specific global styles don't seem to save. Changing the global styles not under the Blocks section still works.
Was able to reproduce with both TT2 and TT3 themes.
Step-by-step reproduction instructions
Copy pasting from the trac ticket,
Go to the site editor.
Open the global styles sidebar.
Open the blocks section.
Navigate to the paragraph block (or button, heading, etc, I think most static blocks).
Apply a background color.
Save the global styles.
The background color is wholly discarded on save.
Screenshots, screen recording, code snippet
wp6.1-global-styles.mov
Environment info
WP(6.1-beta1-54298)
TT2 or TT3 theme
PHP 7.4
Gutenberg plugin deactivated
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Looks like the values are being saved to the styles custom post type, but are not being retrieved for some reason, will see if I can work out why that is.
It looks like in wordpress-develop this call is not returning the custom global styles data. The correct data is there in the preceding config var, ran out of time to try and work out why it is working in GB trunk and not 6.1 beta.
@oandregal may have some thoughts - this PR touched on some of these areas, but it all seems to have been ported to 6.1
Interestingly, in wordpress-develop I can save styles for server rendered blocks in global styles (e.g. site title), but not static blocks (like Group). Just in case that points in any particular direction for this one or the linked trac issue.
I think this one will likely need to be fixed from the core side, but I noticed (and commented here on the trac issue) that if we update the priority of the register_core_block_types_from_metadata callback on the init action to have a priority of 1, that appears to resolve the issue (this line). So it sounds like it's likely related to a caching issue / order of calls with get_blocks_metadata being called too early, like @jorgefilipecosta described? (While updating the priority worked in my local environment, I imagine that won't work as a proper fix, as it possibly obfuscates the real bug 🤔)
I can confirm that this issue does not occur with Gutenberg active. Only in 6.1 Beta. So it seemly like something might not have been ported over properly? 🤔
I've done some testing: go to the global styles sidebar and set the global background color and the background color of the heading block. This is how I'm tracing this data usage:
What happens is that, at some point, the theme.json class receives the data saved in the database. It wants to sanitize it. One of the things it does is removing data for blocks that are not registered. And, apparently, the core/heading is not, hence its data is removed and the styles are generated without it. These are the "valid blocks" at the point the user data is first calculated:
I've quickly looked at the places where we require global styles data. Inspected the usage of the wp_get_global_stylesheet (and similar functions) as well as the classes (WP_Theme_JSON and WP_Theme_JSON_Resolver). I wanted to learn if we had changed the places where we use this code (script-loader.php, etc.) and made it so it runs earlier than block registration. I haven't found anything meaningful.
The other reason some blocks may not be registered at that point is that block registration had changed, as Jorge suggested in the trac ticket. A bit out of my expertise at the moment, and given some time-constraints I have this week I'm not sure if I'm going to be able to help investigate much further this path.
I've updated WordPress/wordpress-develop#3392 to move the hook to the registry class, which now seems to capture all cases where a block might be registered.
Adds a static clean_cached_data method to WP_Theme_JSON and uses that plus the existing WP_Theme_JSON_Resolver::clean_cached_data method after registration of the Template Part block.
⚠️It also means manually clearing a -- seemingly unrelated -- cache from within registration of a specific block. While not a problem currently, there's a risk that other blocks might need similar intervention -- and it's likely not a pattern we'd like to see proliferate.
Doesn't change any functionality but is a related minor performance and code quality improvement. (This probably disqualifies it from backporting into WP 6.1, but it doesn't harm to have it in GB).
This leaves us with the caching issue in WP_Theme_JSON_Resolver. I would like to explore this suggestion by @oandregal for a bit, since it seems like it would tackle the caching issue at its core.
If we cannot get that ready in time, we might instead merge a fallback. I'm currently leaning towards WordPress/wordpress-develop#3384, since it doesn't introduce any new APIs.
I'm considering closing this issue (since it's arguably fixed), and moving discussion over to #44619 (which AFAICS covers the remaining issue with the theme resolver). Thoughts? 👍 / 👎
I'm considering closing this issue (since it's arguably fixed), and moving discussion over to #44619 (which AFAICS covers the remaining issue with the theme resolver). Thoughts?
Yeah, in my testing, this issue appears to be fixed in Beta 3
Thanks for weighing up all the options @ockham, and landing the incremental fixes! 🙇
I'm considering closing this issue (since it's arguably fixed), and moving discussion over to #44619 (which AFAICS covers the remaining issue with the theme resolver). Thoughts? 👍 / 👎
That sounds good to me. Should we keep a trac issue open for #44619, though, as it's still a blocker for 6.1?
To keep efforts streamlined, I've closed out my alternate PRs now, but do ping me if you need a review on anything. Thanks for digging in to find the right solution!
That sounds good to me. Should we keep a trac issue open for #44619, though, as it's still a blocker for 6.1?
Yeah, good point. I'll file one 👍
To keep efforts streamlined, I've closed out my alternate PRs now, but do ping me if you need a review on anything. Thanks for digging in to find the right solution!
Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended
Activity
ndiego commentedon Sep 26, 2022
I can confirm this issue. It's a pretty major one 😬

glendaviesnz commentedon Sep 27, 2022
Looks like the values are being saved to the styles custom post type, but are not being retrieved for some reason, will see if I can work out why that is.
glendaviesnz commentedon Sep 27, 2022
It looks like in wordpress-develop this call is not returning the custom global styles data. The correct data is there in the preceding config var, ran out of time to try and work out why it is working in GB trunk and not 6.1 beta.
@oandregal may have some thoughts - this PR touched on some of these areas, but it all seems to have been ported to 6.1
andrewserong commentedon Sep 27, 2022
Interestingly, in wordpress-develop I can save styles for server rendered blocks in global styles (e.g. site title), but not static blocks (like Group). Just in case that points in any particular direction for this one or the linked trac issue.
andrewserong commentedon Sep 27, 2022
I think this one will likely need to be fixed from the core side, but I noticed (and commented here on the trac issue) that if we update the priority of the
register_core_block_types_from_metadatacallback on theinitaction to have a priority of1, that appears to resolve the issue (this line). So it sounds like it's likely related to a caching issue / order of calls withget_blocks_metadatabeing called too early, like @jorgefilipecosta described? (While updating the priority worked in my local environment, I imagine that won't work as a proper fix, as it possibly obfuscates the real bug 🤔)ndiego commentedon Sep 27, 2022
I can confirm that this issue does not occur with Gutenberg active. Only in 6.1 Beta. So it seemly like something might not have been ported over properly? 🤔
oandregal commentedon Sep 27, 2022
I've done some testing: go to the global styles sidebar and set the global background color and the background color of the heading block. This is how I'm tracing this data usage:
{ "styles": { "color": { "background": "var:preset|color|vivid-red" }, "blocks": { "core/heading": { "color": { "background": "var:preset|color|luminous-vivid-amber" } } } }, "isGlobalStylesUserThemeJSON": true, "version": 2 }WP_Theme_JSON_Resolver::get_user_data()is this (notice how the block data is missing):( [theme_json:protected] => Array ( [styles] => Array ( [color] => Array ( [background] => var:preset|color|vivid-red ) ) [version] => 2 ) )So the data is properly saved but is discarded when rendering.
oandregal commentedon Sep 27, 2022
What happens is that, at some point, the theme.json class receives the data saved in the database. It wants to sanitize it. One of the things it does is removing data for blocks that are not registered. And, apparently, the
core/headingis not, hence its data is removed and the styles are generated without it. These are the "valid blocks" at the point the user data is first calculated:( [0] => core/legacy-widget [1] => core/widget-group [2] => core/archives [3] => core/avatar [4] => core/block [5] => core/calendar [6] => core/categories [7] => core/comment-author-name [8] => core/comment-content [9] => core/comment-date [10] => core/comment-edit-link [11] => core/comment-reply-link [12] => core/comment-template [13] => core/comments [14] => core/comments-pagination [15] => core/comments-pagination-next [16] => core/comments-pagination-numbers [17] => core/comments-pagination-previous [18] => core/comments-title [19] => core/cover [20] => core/file [21] => core/gallery [22] => core/home-link [23] => core/image [24] => core/latest-comments [25] => core/latest-posts [26] => core/loginout [27] => core/navigation [28] => core/navigation-link [29] => core/navigation-submenu [30] => core/page-list [31] => core/pattern [32] => core/post-author [33] => core/post-author-biography [34] => core/post-comments-form [35] => core/post-content [36] => core/post-date [37] => core/post-excerpt [38] => core/post-featured-image [39] => core/post-navigation-link [40] => core/post-template [41] => core/post-terms [42] => core/post-title [43] => core/query [44] => core/query-no-results [45] => core/query-pagination [46] => core/query-pagination-next [47] => core/query-pagination-numbers [48] => core/query-pagination-previous [49] => core/query-title [50] => core/read-more [51] => core/rss [52] => core/search [53] => core/shortcode [54] => core/site-logo [55] => core/site-tagline [56] => core/site-title [57] => core/social-link [58] => core/tag-cloud )oandregal commentedon Sep 27, 2022
I've quickly looked at the places where we require global styles data. Inspected the usage of the
wp_get_global_stylesheet(and similar functions) as well as the classes (WP_Theme_JSONandWP_Theme_JSON_Resolver). I wanted to learn if we had changed the places where we use this code (script-loader.php, etc.) and made it so it runs earlier than block registration. I haven't found anything meaningful.The other reason some blocks may not be registered at that point is that block registration had changed, as Jorge suggested in the trac ticket. A bit out of my expertise at the moment, and given some time-constraints I have this week I'm not sure if I'm going to be able to help investigate much further this path.
13 remaining items
andrewserong commentedon Oct 4, 2022
I've updated WordPress/wordpress-develop#3392 to move the hook to the registry class, which now seems to capture all cases where a block might be registered.
ockham commentedon Oct 4, 2022
Update: We now have a few candidates to fix this issue:
clean_cached_datamethod toWP_Theme_JSONand uses that plus the existingWP_Theme_JSON_Resolver::clean_cached_datamethod after registration of the Template Part block.WP_Theme_JSON::get_blocks_metadatato add blocks metadata for any blocks that aren't cached yet.WP_Theme_JSON_Resolver::get_theme_data.WP_Theme_JSONandWP_Theme_JSON_Resolverbased on number of blocks.Finally, while not a fix to this issue, there's #44658, which is a related minor performance and code quality improvement.
I'll review these alternatives in a follow-up comment and will try to draw up a strategy that we can take from here.
ockham commentedon Oct 4, 2022
We have two partial fixes/improvements that I consider very low-risk:
WP_Theme_JSON::get_blocks_metadatapart only)WP_Theme_JSON_Resolver::get_theme_data). While that would fix the other part of the issue (theme.jsonper-block Global Styles settings aren't applied; edit: I just learned that we have a separate issue for this: [WP 6.1] Block Styles in theme.json do not appear in the Editor or Frontend #44619), the performance impact might be too big.I would then like to land those two.
This leaves us with the caching issue in
WP_Theme_JSON_Resolver. I would like to explore this suggestion by @oandregal for a bit, since it seems like it would tackle the caching issue at its core.If we cannot get that ready in time, we might instead merge a fallback. I'm currently leaning towards WordPress/wordpress-develop#3384, since it doesn't introduce any new APIs.
ockham commentedon Oct 4, 2022
I think one important thing is to treat the issues separately:
WP_Theme_JSONPR fixes the manual Global Styles-styling of buttons by the user (this issue).theme.jsonstuff is broken because of WP_Theme_JSON_Resolver caching (#44619).@c4rl0sbr4v0 is currently looking into @oandregal's suggestion.
ockham commentedon Oct 4, 2022
Update:
WP_Theme_JSONcaching fix; it's part of WP 6.1 Beta 3.I'm considering closing this issue (since it's arguably fixed), and moving discussion over to #44619 (which AFAICS covers the remaining issue with the theme resolver). Thoughts? 👍 / 👎
ndiego commentedon Oct 4, 2022
Yeah, in my testing, this issue appears to be fixed in Beta 3
andrewserong commentedon Oct 5, 2022
Thanks for weighing up all the options @ockham, and landing the incremental fixes! 🙇
That sounds good to me. Should we keep a trac issue open for #44619, though, as it's still a blocker for 6.1?
To keep efforts streamlined, I've closed out my alternate PRs now, but do ping me if you need a review on anything. Thanks for digging in to find the right solution!
ockham commentedon Oct 5, 2022
Yeah, good point. I'll file one 👍
Thank you for all your work and research! ❤️
ockham commentedon Oct 5, 2022
https://core.trac.wordpress.org/ticket/56736
Editor: Fix performance regression in WP_Theme_JSON_Resolver.
Editor: Fix performance regression in WP_Theme_JSON_Resolver.
Editor: Fix performance regression in WP_Theme_JSON_Resolver.
Editor: Fix performance regression in WP_Theme_JSON_Resolver.