Skip to content

Strip null values from styles when saving to theme.json #885

Open

Description

@iamtakashi

Description

When the user's global styles contain null values, "Save Changes to Theme" writes them into theme.json as they are. The theme.json schema rejects null here, and WordPress ignores these keys, so they're only noise that theme authors have to remove by hand.

The editor currently saves such nulls when border sides are unlinked in Global Styles (WordPress/gutenberg#84814), for example:

"core/quote": {
  "border": {
    "color": null,
    "style": null,
    "width": null,
    "left": { "color": "currentColor", "style": "solid", "width": "4px" }
  }
}

Steps to reproduce

  1. Activate Twenty Twenty-Five with Create Block Theme.
  2. Site Editor → Styles → Blocks → Quote → Borders: click "Unlink sides", set the left width to 4px, save.
  3. Save Changes to Theme (or call CBT_Theme_JSON_Resolver::export_theme_data( 'all' )).

Expected

null values are dropped from the exported theme.json (and style variations).

Actual

styles.blocks["core/quote"].border in the export has "color":null, "style":null and "width":null.

Environment

  • Create Block Theme 2.10.2
  • WordPress 7.1.3, Gutenberg 24.2.0

Drafted with AI assistance, reproduced and verified by me.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions