Block Editor: Fix blockGap fallback handling for nested var() fallback values#77750
Conversation
Co-authored-by: Copilot <copilot@github.com>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
tellthemachines
left a comment
There was a problem hiding this comment.
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.
|
It might be worth backporting this PR to the 7.0 minor release. See #78743 (comment) |
What?
This PR fixes invalid gap CSS generation when
styles.spacing.blockGapintheme.jsonuses nestedvar()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:
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
{ "styles": { "spacing": { "blockGap": "var(--a, var(--b, 1.2rem))" } } }