Skip to content

Style Engine: refactor global/theme.json styles to use the style engine #46563

Closed

Description

@ramonjd

The proposal

The Style Engine generates CSS for block styles in WordPress, and hence knows how to parse block style objects.

Given that theme.json shares the block style object data model, it now should be possible to use the Style Engine to parse global style objects as well.

There will be some exceptions, and it's going to be a big job.

This goal of this issue is to break down and track the tasks/investigations.

Tasks

  • Generate CSS for global stylesheet: might involve replacing the WP_Theme_JSON::compute_style_properties WP_Theme_JSON::to_ruleset methods with the Style Engine in WP_Theme_JSON::get_styles_for_block(). The Style Engine can accept a single theme.json style node and a selector.
    • Possibly Start with top-level global styles, then elements, then blocks, then layout... etc
    • Ensure we correctly handle elements and pseudo elements
    • Ensure we correctly handle custom CSS var handling such as blockGap
    • Following from above, we might have to cater for CSS var —wp—style—root— properties and PROTECTED_PROPERTIES if we're skipping compute_style_properties calls in get_styles_for_block.
    • Add support for block.json __experimentalSelector. These are the block support selectors that can be defined in block.json. Can be done by refactoring the relevant logic in WP_Theme_JSON::get_styles_for_block(), and building nodes instead of declaration arrays.
    • Explore how to manage or deal with CSS rules that are not covered by safecss_filter_attr — for example, there are rules that might be applicable to global styles (e.g. setting display: flex on flex layouts) that are suitable for global styles rules, but that should not be exposed generally for users without the unfiltered_html capability.
    • Should there be a lighter-weight way to add allowed / approved CSS rules for output that are more broad than the global values allowed by kses? E.g. if we were to allow transitions, transforms, or other fancy styling features in global styles, that we might not want to expose for all WordPress users.
    • If output is moved away from compute_style_properties, update settings and styles validation to ensure that rules output via global styles are allowed for users without the unfiltered_html capability.
  • Come up with a way to enqueue global styles, for example, by replacing/refactoring gutenberg_enqueue_global_styles , taking into account the logic in gutenberg_add_global_styles_for_blocks that enqueues block styles separately via wp_should_load_separate_core_block_assets()
    • Need to ensure that, if we store the global styles, that they’re printed first. Add a priority option?
  • Migrate away from preset values to use only the style object for blocks, see comment: Improving our saving/rendering of block styles #37495 (reply in thread)

More to come...

Previous, and maybe relevant, investigations

Activity

  1. converted this from a draft issue on Dec 15, 2022
  2. changed the title [-]Style Engine: refactor Global/theme.json styles to use the style engine[/-] [+]Style Engine: refactor global/theme.json styles to use the style engine[/+] on Dec 15, 2022
  3. added
    [Package] Style Engine
    [Type] Tracking Issue
    Global Styles
    on Dec 15, 2022
  4. removed
    [Type] Tracking Issue
    on Mar 21, 2024
  5. ramonjd commented on Aug 7, 2026

    @ramonjd
    MemberAuthor

    We should do this first: #65728

  6. moved this from 📢 Not started to 🏆 Done in Gutenberg Style Engineon Aug 7, 2026
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[Package] Style Engine

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions