Skip to content

[WP 6.1] Block-specific global styles don't seem to save #44434

Closed

Description

@RahiDroid

Description

  • Original trac ticket: https://core.trac.wordpress.org/ticket/56644 by @jorgefilipecosta
  • 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,

  1. Go to the site editor.
  2. Open the global styles sidebar.
  3. Open the blocks section.
  4. Navigate to the paragraph block (or button, heading, etc, I think most static blocks).
  5. Apply a background color.
  6. Save the global styles.
  7. 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.

Yes

Activity

  1. added
    [Type] Bug
    Global Styles
    [Priority] High
    on Sep 26, 2022
  2. ndiego commented on Sep 26, 2022

    @ndiego
    Member

    I can confirm this issue. It's a pretty major one 😬
    global-style-no-saving

  3. glendaviesnz commented on Sep 27, 2022

    @glendaviesnz
    Contributor

    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.

  4. glendaviesnz commented on Sep 27, 2022

    @glendaviesnz
    Contributor

    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

  5. andrewserong commented on Sep 27, 2022

    @andrewserong
    Contributor

    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.

  6. andrewserong commented on Sep 27, 2022

    @andrewserong
    Contributor

    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 🤔)

  7. ndiego commented on Sep 27, 2022

    @ndiego
    Member

    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? 🤔

  8. oandregal commented on Sep 27, 2022

    @oandregal
    Member

    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:

    • the database has the actual user data
    {
      "styles": {
        "color": { "background": "var:preset|color|vivid-red" },
        "blocks": {
          "core/heading": {
            "color": { "background": "var:preset|color|luminous-vivid-amber" }
          }
        }
      },
      "isGlobalStylesUserThemeJSON": true,
      "version": 2
    }
    • the result of calling 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.

  9. oandregal commented on Sep 27, 2022

    @oandregal
    Member

    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:

    (
        [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
    )
  10. oandregal commented on Sep 27, 2022

    @oandregal
    Member

    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.

  11. 13 remaining items

  12. andrewserong commented on Oct 4, 2022

    @andrewserong
    Contributor

    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.

  13. ockham commented on Oct 4, 2022

    @ockham
    Contributor

    Update: We now have a few candidates to fix this issue:

    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.

  14. ockham commented on Oct 4, 2022

    @ockham
    Contributor

    We have two partial fixes/improvements that I consider very low-risk:

    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.

  15. ockham commented on Oct 4, 2022

    @ockham
    Contributor

    I think one important thing is to treat the issues separately:

    1. The WP_Theme_JSON PR fixes the manual Global Styles-styling of buttons by the user (this issue).
    2. The theme.json stuff is broken because of WP_Theme_JSON_Resolver caching (#44619).

    @c4rl0sbr4v0 is currently looking into @oandregal's suggestion.

  16. ockham commented on Oct 4, 2022

    @ockham
    Contributor

    Update:

    1. We've now landed the WP_Theme_JSON caching fix; it's part of WP 6.1 Beta 3.
    2. Carlos has filed Try to cache the theme json file reading wordpress-develop#3401 as a tentative fix for [WP 6.1] Block Styles in theme.json do not appear in the Editor or Frontend #44619.

    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? 👍 / 👎

  17. ndiego commented on Oct 4, 2022

    @ndiego
    Member

    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

  18. andrewserong commented on Oct 5, 2022

    @andrewserong
    Contributor

    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?

    @c4rl0sbr4v0 is currently looking into @oandregal's WordPress/wordpress-develop#3359 (comment).

    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!

  19. ockham commented on Oct 5, 2022

    @ockham
    Contributor

    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!

    Thank you for all your work and research! ❤️

  20. Repository owner moved this from Research/Discussions in progress to Done in WordPress 6.1 Editor Taskson Oct 5, 2022
  21. ockham commented on Oct 5, 2022

    @ockham
    Contributor

    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 👍

    https://core.trac.wordpress.org/ticket/56736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global Styles[Priority] High[Type] Bug

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions