Skip to content

Bind font-shorthand custom property families to font-family presets - #5261

Open
chubes4 wants to merge 1 commit into
trunkfrom
fix/issue-5215-font-shorthand-preset
Open

chubes4 wants to merge 1 commit into
trunkfrom
fix/issue-5215-font-shorthand-preset

Conversation

@chubes4

@chubes4 chubes4 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5215.

Root cause

PresetBinding::bindStylesheet() binds colour literals inside custom properties, but never the font-family part of a custom property that holds a font shorthand (--t:normal normal normal 18px/1.6em Example Light,Example,sans-serif, consumed as font:var(--t)). Text styled through such tokens never follows a Global Styles font change. On a real multi-page import, about 120 of 190 text elements on the home page are styled this way.

Change

  • Move CssFontShorthand from HtmlToBlocks\Style to the shared Css layer. It depends only on Css\CssValueSplitter, and the layer-direction contract forbids WordPressSitePlan from importing conversion internals. It now reports the family's offset so the value is never reserialized.
  • In PresetBinding, when a custom property value parses as a font shorthand whose complete family stack exactly matches a font-family preset, rewrite only that family in place: --t:normal normal normal 18px/1.6em var(--wp--preset--font-family--body). Style, weight, size, line-height, spacing and !important stay literal. Values that don't match fall through to the existing colour-token binding unchanged.

Evidence

New contract tests/contract/preset-binding-font-shorthand-custom-property.php (auto-discovered by tests/run.php):

  • trunk: --t:normal normal normal 18px/1.6em Example Light,Example,sans-serif → fails ("Style, weight, size, line-height, spacing and priority survive family binding.")
  • this branch: --t:normal normal normal 18px/1.6em var(--wp--preset--font-family--body) → passes. Unmatched stacks and primary-family-only matches stay literal, color:rgb(var(--c)) keeps its preset binding, and --sh:0 0 2px #2f2e2e keeps its colour-token binding.

composer test:scripts passes on the Lab runner after rebasing on trunk (1313 tests, 0 failed), and composer lint reports no errors.


AI disclosure: the fix was produced by a Homeboy cook (OpenAI GPT via the Lab runner). Claude (Anthropic Claude Opus, in Claude Code via Roadie) reviewed it, found and fixed a regression where non-font custom properties lost colour binding, added the shadow assertion, ran the Lab suite, and opened this PR with the maintainer's approval after the cook's final gate failed on a Lab transport error.

Move CssFontShorthand into the shared Css layer so WordPressSitePlan can parse
shorthand values, and rewrite only the exactly matching family part of a
custom property in place. Non-matching values fall through to the existing
colour token binding.

Fixes #5215
@chubes4
chubes4 force-pushed the fix/issue-5215-font-shorthand-preset branch from c2276bd to 38c8c50 Compare November 9, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restyle: font-family inside a font-shorthand custom property is never bound to its preset

1 participant