Skip to content

Block Editor: Fix blockGap fallback handling for nested var() fallback values#77750

Merged
tellthemachines merged 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/block-gap-nested-var-fallback
Apr 29, 2026
Merged

Block Editor: Fix blockGap fallback handling for nested var() fallback values#77750
tellthemachines merged 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/block-gap-nested-var-fallback

Conversation

@Mustafabharmal

Copy link
Copy Markdown
Contributor

What?

This PR fixes invalid gap CSS generation when styles.spacing.blockGap in theme.json uses nested var() fallbacks, and the user updates row/column gap controls in the editor.
Closes #76896

Why?

The previous fallback logic split processed gap strings by whitespace. That approach breaks values like:

"blockGap": "var(--a, var(--b, 1.2rem))"

because whitespace inside nested var() expressions is not a safe delimiter.

How?

Use existing gap helpers to read row/column values directly instead of string splitting:

  • getGapBoxControlValueFromStyle(...)
  • getSpacingPresetCssVar(...)

This keeps the fix minimal and scoped to fallback resolution.

Testing Instructions

  1. Use a block theme with:
    {
      "styles": {
        "spacing": {
          "blockGap": "var(--a, var(--b, 1.2rem))"
        }
      }
    }
  2. Insert a Columns block.
  3. Confirm initial gap is valid.
  4. Update only column-gap (and then row-gap) from block settings.
  5. Verify generated CSS remains valid and parentheses stay balanced.

Co-authored-by: Copilot <copilot@github.com>
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Apr 28, 2026
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: karthikeya-io <karthikeya01@git.wordpress.org>
Co-authored-by: Swanand01 <swanandm@git.wordpress.org>
Co-authored-by: inc2734 <inc2734@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Layout Layout block support, its UI controls, and style output. labels Apr 29, 2026

@tellthemachines tellthemachines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! Code LGTM and is testing well.

In testing I found another bug, but not caused by this PR 😅
I guess it's not much of a problem yet because blocks with Grid support don't have axial spacing enabled, but if you try

  • add "sides": [ "horizontal", "vertical" ] to blockGap in the Group's block.json,
  • add a Grid block to a post,
  • set both Columns and Min column width on it,
  • then set different spacing values for top and left

the responsive grid-template-columns breaks because it gets two gap values where it expects one:

grid-template-columns: repeat(auto-fill, minmax(max(min(15rem, 100%), (100% - (10px 0px * (3 - 1))) /3), 1fr)); (in this case the 10px 0px)

Anyway, that's something to be looked at later.

@tellthemachines tellthemachines merged commit 8dd0b92 into WordPress:trunk Apr 29, 2026
61 of 63 checks passed
@github-actions github-actions Bot added this to the Gutenberg 23.1 milestone Apr 29, 2026
@t-hamano

Copy link
Copy Markdown
Contributor

It might be worth backporting this PR to the 7.0 minor release. See #78743 (comment)

@t-hamano t-hamano added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release [Feature] Layout Layout block support, its UI controls, and style output. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The gap control breaks theme.json block gap when using nested CSS var() fallback.

3 participants