Skip to content

Editor: Narrow the Style Engine types and fix two bugs they surfaced - #16114

Draft
westonruter wants to merge 5 commits into
WordPress:trunkfrom
westonruter:fix/style-engine-strict-types
Draft

westonruter wants to merge 5 commits into
WordPress:trunkfrom
westonruter:fix/style-engine-strict-types

Conversation

@westonruter

@westonruter westonruter commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Note

Please review the Gutenberg PRs instead of this one to avoid duplicate work.

Backports two Gutenberg PRs, and adds src/wp-includes/style-engine.php to the strict PHPStan paths alongside the style-engine directory already there:

Bugs fixed (WordPress/gutenberg#87134), each with a test that fails on trunk:

  • wp_style_engine_get_stylesheet_from_context() called get_all_rules() on null for an empty context, since WP_Style_Engine::get_store() returns null for a store name that is not a non-empty string. It now returns an empty string.
  • A preset for a border side that matches none of its CSS var patterns, such as var:preset|font-size|large for border.top.color, was left out of the CSS but returned by wp_style_engine_get_styles() as an empty declaration, 'border-top-color' => ''. It is now skipped.

Types (WordPress/gutenberg#87117):

  • Declarations passed in are typed as array<string, string>. Those the Style Engine produces are array<non-falsy-string, non-empty-string>: the ones stored by WP_Style_Engine_CSS_Declarations, which filters out empty names and values, and the ones parsed from block styles, through to those returned by wp_style_engine_get_styles(). is_valid_style_value() asserts that a valid value is not '', and the strings of the Style_Definition alias are narrowed to match the non-empty literals of BLOCK_STYLE_DEFINITIONS_METADATA.
  • Options are merged with array_merge() rather than wp_parse_args(), which returns array<mixed> and loses the shapes derived from their hash notation. A query string is therefore no longer parsed, since the options are documented as arrays. null options to wp_style_engine_get_styles(), which the tests pass, are still treated as no options. In WP_Style_Engine_CSS_Declarations no merge is needed at all, since the only default, important => false, was filtered out again right away.
  • The default selector of wp_style_engine_get_styles() is '' rather than null, which every consumer already treated the same way.

The shapes of the options come from their hash notation, so unlike in Gutenberg no @phpstan-param shapes are added for them. The five baselined errors of the style-engine directory are fixed. The angle and translate value parsers that WordPress/gutenberg#87117 also types belong to the Transform block support, which is not in core yet.

Trac ticket: https://core.trac.wordpress.org/ticket/66739

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (medium effort)
Used for: Porting the changes from the Gutenberg PRs, adapting them to the hash-derived shapes, regenerating the PHPStan baselines, running the Style Engine tests, and drafting this description, under my direction and review.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

westonruter and others added 2 commits November 19, 2026 11:44
wp_style_engine_get_stylesheet_from_context() called get_all_rules() on
the store, which WP_Style_Engine::get_store() returns as null for a
store name that is not a non-empty string, so an empty context was a
fatal error. Return an empty string instead.

get_individual_property_css_declarations() checked for an empty value
before converting a preset to a CSS var, and get_css_var_value() returns
an empty string for a preset that matches none of the patterns, such as
a font size preset for `border.top.color`. The empty declaration was
dropped from the compiled CSS, but wp_style_engine_get_styles() still
returned it, e.g. `'border-top-color' => ''`. Skip it instead.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
Declarations passed in are typed as `array<string, string>` rather than
`string[]` or a bare `array`. Those the Style Engine produces are keyed
by non-falsy strings with non-empty string values: the ones stored by
WP_Style_Engine_CSS_Declarations, which filters out empty names and
values, and the ones parsed from block styles, through to those
returned by wp_style_engine_get_styles(). is_valid_style_value()
asserts that a valid value is not an empty string, and the strings of
the Style_Definition alias are narrowed to match the non-empty literals
of BLOCK_STYLE_DEFINITIONS_METADATA.

Options are merged with array_merge() rather than wp_parse_args(),
which returns `array<mixed>` and loses the shapes derived from their
hash notation. The tests pass null options to
wp_style_engine_get_styles(), so null is still treated as no options.
In WP_Style_Engine_CSS_Declarations no merge is needed at all, since the
only default, `important => false`, was filtered out again right away.
The default selector is now an empty string rather than null, which
every consumer already treated the same way.

With these, the style engine directory no longer needs its baselined
errors, and style-engine.php is added to the strict paths.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

westonruter and others added 3 commits November 24, 2026 22:11
Match the check for an unmatched border side preset as merged in
Gutenberg, which uses is_valid_style_value() instead of comparing the
value to an empty string, so the synced files stay in step.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
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.

1 participant