Repository navigation
Editor: Narrow the Style Engine types and fix two bugs they surfaced - #16114
Draft
westonruter wants to merge 5 commits into
Draft
westonruter wants to merge 5 commits into
westonruter wants to merge 5 commits into
Conversation
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
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.phpto the strict PHPStan paths alongside thestyle-enginedirectory already there:Bugs fixed (WordPress/gutenberg#87134), each with a test that fails on trunk:
wp_style_engine_get_stylesheet_from_context()calledget_all_rules()on null for an empty context, sinceWP_Style_Engine::get_store()returns null for a store name that is not a non-empty string. It now returns an empty string.var:preset|font-size|largeforborder.top.color, was left out of the CSS but returned bywp_style_engine_get_styles()as an empty declaration,'border-top-color' => ''. It is now skipped.Types (WordPress/gutenberg#87117):
array<string, string>. Those the Style Engine produces arearray<non-falsy-string, non-empty-string>: the ones stored byWP_Style_Engine_CSS_Declarations, which filters out empty names and values, and the ones parsed from block styles, through to those returned bywp_style_engine_get_styles().is_valid_style_value()asserts that a valid value is not'', and the strings of theStyle_Definitionalias are narrowed to match the non-empty literals ofBLOCK_STYLE_DEFINITIONS_METADATA.array_merge()rather thanwp_parse_args(), which returnsarray<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.nulloptions towp_style_engine_get_styles(), which the tests pass, are still treated as no options. InWP_Style_Engine_CSS_Declarationsno merge is needed at all, since the only default,important => false, was filtered out again right away.wp_style_engine_get_styles()is''rather thannull, which every consumer already treated the same way.The shapes of the options come from their hash notation, so unlike in Gutenberg no
@phpstan-paramshapes are added for them. The five baselined errors of thestyle-enginedirectory 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.