Skip to content

Style Engine: Add PHPStan types for style definitions and avoid fatal errors when storing rules - #86468

Merged
westonruter merged 8 commits into
trunkfrom
fix/phpstan-style-engine-types
Nov 10, 2026
Merged

westonruter merged 8 commits into
trunkfrom
fix/phpstan-style-engine-types

Conversation

@westonruter

Copy link
Copy Markdown
Member

What?

Follow up to #86105. See #86088.

Improves the PHPStan types in WP_Style_Engine beyond level 5, and fixes two problems the stricter types surfaced: a fatal error when storing a rule with a whitespace-only selector, and non-string values leaking into the returned CSS declarations.

Core backport: WordPress/wordpress-develop#15823 (Core-65817)

Why?

At level 10, packages/style-engine/src/class-wp-style-engine.php has 38 PHPStan errors on trunk, almost all from the untyped style definition arrays. This PR brings it to 5, all of them missingType.iterableValue on $options parameters. Core does not report those, because its PHPStan setup derives array shapes from the existing @type hashes.

How?

Types

  • Add a Style_Definition PHPStan type alias for one entry of BLOCK_STYLE_DEFINITIONS_METADATA, and use it for the constant and for every method that receives a definition. This replaces the inline shape on get_classnames().
  • Document the remaining raw $style_value parameters as mixed, since the parsers check the type themselves, and $block_styles as array<string, mixed>.
  • Correct the classnames entry of the parse_block_styles() return value, which is an array, not a space-separated string, matching Core.
  • Link the docblock references to {@see self::BLOCK_STYLE_DEFINITIONS_METADATA}. Using self:: keeps the reference valid after the build renames the class to WP_Style_Engine_Gutenberg.

Fixes

  • store_css_rule() rejects an empty selector, but WP_Style_Engine_CSS_Rules_Store::add_rule() trims it and returns nothing when the result is empty. A selector of only whitespace therefore called add_declarations() on null, a fatal error reachable from wp_style_engine_get_stylesheet_from_css_rules() when a context is passed. A non-string store name fails the same way, since the store lookup returns nothing. Both are now skipped, and the method declares void.
  • get_css_declarations() and get_individual_property_css_declarations() are documented to return string[], but passed raw values through, so textColumns: 2 or a padding side of 5 came back as integers. They now skip non-string values. WP_Style_Engine_CSS_Declarations::add_declaration() already dropped them, so the compiled CSS is unchanged; only the declarations array returned by wp_style_engine_get_styles() loses them.
  • A few small guards keep the analysis sound: the sibling definition lookup reads the constant directly instead of through _wp_array_get(), a definition without property_keys returns no declarations instead of reading an undefined index, and url() is only built from a string url.

Testing Instructions

  1. Run composer phpstan and confirm it passes.
  2. Run the Style Engine PHP unit tests: npm run test:unit:php -- -- --filter WP_Style_Engine_Test. Two new tests cover the whitespace selector and the non-string values.
  3. Optionally, run PHPStan at level 10 on packages/style-engine/src/class-wp-style-engine.php and compare with trunk.

Testing Instructions for Keyboard

Not applicable. There are no UI changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (medium effort)
Used for: Investigating the PHPStan errors, drafting the type changes, fixes, and tests, and syncing them to the Core backport; reviewed and directed by me.

westonruter and others added 4 commits November 7, 2026 09:51
…ADATA

Wrap the docblock mentions of the constant in
`{@see self::BLOCK_STYLE_DEFINITIONS_METADATA}` so the developer docs
link to it. `self::` keeps the reference valid after the build renames
the class with the `_Gutenberg` suffix.

Also qualify the mention in the inline comment in `get_classnames()`
and align its asterisks.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 1064defd-b2b0-40d4-bfca-0c5b60899c05
Add a `Style_Definition` PHPStan type alias to `WP_Style_Engine`,
describing one entry of `BLOCK_STYLE_DEFINITIONS_METADATA`, and use it
for the constant and for every method that receives a definition. This
gives PHPStan the shapes of `property_keys`, `path`, `css_vars`,
`classnames`, and `value_func`.

Document the remaining raw style value parameters as `mixed`, since
`parse_block_styles()` passes whatever is found at the definition's
`path`, and the parsers already check its type. Also correct the
`classnames` entry of the `parse_block_styles()` return value, which is
an array rather than a space-separated string, matching core.

With the types in place, a few small code changes keep the analysis
sound without changing behavior for valid definitions:

* Read the sibling definition in
  `get_individual_property_css_declarations()` from the constant
  directly, instead of through `_wp_array_get()`, which loses its type.
* Return early from `get_css_declarations()` when a definition has
  neither a callable `value_func` nor `property_keys`, rather than
  reading an undefined index.
* Only build a `url()` value in `get_url_or_value_css_declaration()`
  when the value is an array with a string `url`.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 1064defd-b2b0-40d4-bfca-0c5b60899c05
`WP_Style_Engine::store_css_rule()` rejects an empty selector, but
`WP_Style_Engine_CSS_Rules_Store::add_rule()` trims the selector and
returns nothing when the result is empty. A selector made only of
whitespace therefore passed the first check and then called
`add_declarations()` on null, which is a fatal error. It is reachable
from `wp_style_engine_get_stylesheet_from_css_rules()` when a `context`
is passed.

Skip storing the rule when no store or rule is returned, and declare the
method's `void` return type.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 1064defd-b2b0-40d4-bfca-0c5b60899c05
`get_css_declarations()` and `get_individual_property_css_declarations()`
are documented to return `string[]`, but they passed raw block style
values through unchanged, so a numeric value such as `textColumns: 2` or
a padding side of `5` ended up in the declarations as an integer.
`WP_Style_Engine_CSS_Declarations::add_declaration()` already drops
non-string values, so they never reached the compiled CSS; they only
leaked into the `declarations` array returned by
`wp_style_engine_get_styles()`.

Skip non-string values in both methods, so the return type holds. The
compiled CSS is unchanged.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 1064defd-b2b0-40d4-bfca-0c5b60899c05
@westonruter westonruter added [Type] Code Quality Issues or PRs that relate to code quality [Package] Style Engine /packages/style-engine labels Nov 7, 2026
Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 1064defd-b2b0-40d4-bfca-0c5b60899c05
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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: westonruter <westonruter@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: dknauss <dpknauss@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric f8a0b0c trunk % Change
timeToFirstByte 32.55 ms +10.14% -1.69% 33.25 ms +10.68% -5.41% -2.11%
largestContentfulPaint 60 ms +3.33% -6.67% 58 ms +10.34% -3.45% 3.45%
lcpMinusTtfb 23.85 ms +14.26% -4.61% 24.55 ms +20.98% -7.74% -2.85%
wpBeforeTemplate 17.06 ms +12.78% -1.47% 17.37 ms +7.71% -4.15% -1.78%
wpTemplate 12.64 ms +6.49% -4.11% 12.83 ms +6.63% -7.79% -1.48%
wpTotal 29.62 ms +10.8% -2.03% 30.54 ms +10.22% -5.99% -3.01%
wpMemoryUsage 7.72 MB +0% -0% 7.69 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric f8a0b0c trunk % Change
timeToFirstByte 27.7 ms +5.6% -1.99% 27.75 ms +8.29% -3.78% -0.18%
largestContentfulPaint 64 ms +0% -3.13% 64 ms +0% -6.25% 0%
lcpMinusTtfb 36 ms +1.94% -6.81% 34.85 ms +5.88% -6.17% 3.3%
wpBeforeTemplate 15.46 ms +1.75% -2.01% 15.13 ms +10.58% -1.39% 2.18%
wpTemplate 9.74 ms +1.64% -2.67% 9.57 ms +7.52% -2.82% 1.78%
wpTotal 25.22 ms +5.67% -2.18% 25.29 ms +9.41% -3.28% -0.28%
wpMemoryUsage 6.41 MB +0% -0% 6.38 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric f8a0b0c trunk % Change
mediaProcessingJpeg 215.33 ms +1.81% -1.71% 216.47 ms +1.79% -2.21% -0.53%
mediaProcessingAvif 3499.35 ms +2.89% -0.24% 3517.68 ms +1.56% -0.26% -0.52%
mediaProcessingJpegToAvif 2436.96 ms +1.53% -0.77% 2493.08 ms +1.01% -1.15% -2.25%

media-upload

Metric f8a0b0c trunk % Change
jpegUploadProcessing 1395.7 ms +2% -2.27% 1398.88 ms +1.22% -0.37% -0.23%
pngUploadProcessing 167.09 ms +20.65% -4.55% 174.05 ms +12.26% -6.66% -4%
largeJpegUploadProcessing 1397.83 ms +1.04% -0.7% 1389.52 ms +0.37% -1.14% 0.6%
multipleImageUploadProcessing 1447.72 ms +0.65% -1.19% 1436.42 ms +1.47% -0.48% 0.79%

post-editor

Metric f8a0b0c trunk % Change
serverResponse 265.42 ms +3.19% -0.89% 255.34 ms +2.88% -7.4% 3.95%
firstPaint 287.43 ms +17.06% -24.08% 235.35 ms +33.88% -14.91% 22.13%
domContentLoaded 556.08 ms +1.27% -0.47% 528.57 ms +2.21% -1.86% 5.2%
loaded 556.93 ms +1.24% -0.46% 529.24 ms +2.21% -1.85% 5.23%
firstContentfulPaint 335.9 ms +0.86% -1.98% 317.56 ms +2.14% -3.92% 5.78%
firstBlock 1467.38 ms +5.61% -1.6% 1365.92 ms +2.16% -0.55% 7.43%
type 12.72 ms +7.15% -8.25% 12.3 ms +2.52% -8.86% 3.41%
typeWithoutInspector 12.13 ms +3.46% -8.99% 12.36 ms +3.96% -11.17% -1.86%
typeWithTopToolbar 15.98 ms +2.38% -12.52% 15.32 ms +9.4% -6.01% 4.31%
typeContainer 5.74 ms +4.88% -6.97% 5.85 ms +6.67% -1.54% -1.88%
focus 68.35 ms +3.17% -5.72% 69.62 ms +4.4% -2.46% -1.82%
firstFocus 148.51 ms +0% -0% 156.17 ms +0% -0% -4.9%
selectAll 228.7 ms +1.42% -0.75% 230.1 ms +4.24% -0.99% -0.61%
undo 18.54 ms +7.07% -7.12% 19.48 ms +2.16% -3.9% -4.83%
listViewOpen 44.88 ms +16.4% -6.73% 44.28 ms +2.82% -13.55% 1.36%
inserterOpen 26.18 ms +2.25% -1.64% 25.96 ms +11.48% -9.24% 0.85%
inserterHover 7.59 ms +7.11% -7.64% 8.06 ms +7.57% -8.56% -5.83%
inserterSearch 6.19 ms +8.56% -4.04% 6.27 ms +5.1% -2.87% -1.28%
loadPatterns 405.45 ms +2.93% -4.8% 438.79 ms +1.91% -4% -7.6%
wpTotal 258.52 ms +2.86% -0.89% 248.89 ms +2.8% -7.83% 3.87%
wpMemoryUsage 14.77 MB +0% -0% 14.74 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric f8a0b0c trunk % Change
serverResponse 323.45 ms +3.09% -3.81% 309.39 ms +6.31% -8.83% 4.54%
firstPaint 300.78 ms +9.17% -7.57% 258.59 ms +20.5% -8.04% 16.32%
domContentLoaded 744.52 ms +1.31% -1.86% 707.7 ms +2.01% -2.73% 5.2%
loaded 745.52 ms +1.34% -1.87% 708.47 ms +2.04% -2.73% 5.23%
firstContentfulPaint 435.45 ms +1.68% -2.58% 412.13 ms +2.99% -4.09% 5.66%
firstBlock 2232.58 ms +0.94% -2.52% 2075.71 ms +0.84% -1.85% 7.56%
type 17.58 ms +4.32% -12.06% 14.14 ms +2.76% -7.21% 24.33%
navigate 100.48 ms +11.91% -5.61% 86.51 ms +14.72% -6.18% 16.15%
loadPatterns 1217.86 ms +3.46% -8.75% 1056.28 ms +8.51% -13.9% 15.3%
loadPages 956.33 ms +4.85% -0.78% 1031.58 ms +2.39% -1.81% -7.29%
wpTotal 315.12 ms +3.08% -3.91% 301.16 ms +6.46% -9.1% 4.64%
wpMemoryUsage 12.79 MB +0% -0% 12.75 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

349c93f Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page Two') with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-172-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-172-label" aria-describedby="view-list-0-172-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:146:49
Page List converts to Navigation Links with entity bindings in /test/e2e/specs/editor/blocks/navigation.spec.js, passed after 1 failed attempt.
Error: expect(locator).toContainText(expected) failed

Locator: getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
Expected substring: "test-page-1"
Received string:    "Link to:Cat/catPagePublished"
Timeout: 5000ms

Call log:
  - Expect "toContainText" getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ }) with timeout 5000ms
  - waiting for getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
    14 × locator resolved to <button type="button" aria-expanded="false" aria-haspopup="dialog" class="components-button link-preview-button is-next-40px-default-size is-secondary">…</button>
       - unexpected value "Link to:Cat/catPagePublished"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation.spec.js:1949:31
Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
a navigation superseded by the traversal discharges to idle in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
SyntaxError: Unexpected token 'o', "not hydrated" is not valid JSON
    at readLog (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:28:14)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:47:24
    at waitForLogLength (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:46:2)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:693:5
does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
keeps Category and Search fields stable when switching categories at 1280px in ltr @WebKit in /test/e2e/specs/site-editor/font-library.spec.js, passed after 2 failed attempts.
Test timeout of 100000ms exceeded.
Test timeout of 100000ms exceeded.
should place the caret at the click position when clicking a block that is not selected in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  Array [
    Object {
      "attributes": Object {
-       "content": "First!",
+       "content": "First",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:952:41
should select by dragging into nested block in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 2 failed attempts.
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 0

  Array [
    1,
-   2,
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:569:5
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 0

  Array [
    1,
-   2,
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:569:5

349c93f Run

@dknauss

dknauss commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Tested on WordPress 7.1.4 / PHP 8.3, running this branch's WP_Style_Engine side by side with trunk's on 11 block style inputs: string and numeric line height, numeric font weight and font size, string and numeric padding, border width/style/colour, a per-side border, numeric min height, a background image URL and a preset colour. The compiled CSS was identical in every case. Numeric values were already dropped on trunk, so the new is_string() checks don't remove any output.

store_css_rule() with a whitespace-only selector is a fatal error on trunk (Call to a member function add_declarations() on null), and returns quietly with this PR.

@westonruter
westonruter marked this pull request as ready for review November 9, 2026 22:47
* @covers ::gutenberg_style_engine_get_styles
*/
public function test_should_omit_non_string_values_from_declarations() {
$block_styles = array(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as WordPress/wordpress-develop#15823 (comment)

Maybe add border.top.width: 5 to cover the individual properties for that style?

optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could you amend the PR with what you had in mind?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No probs. It's a tiny change to the test. Feel free to revert.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, I realized my original comment wasn't clear at all. Probably should have got Claude to write it :trollface:

border sides run through get_individual_property_css_declarations(), which this PR changes so just a cheap way to test the string omission.

@westonruter
westonruter enabled auto-merge (squash) November 10, 2026 07:08
@westonruter
westonruter merged commit 8b9444a into trunk Nov 10, 2026
88 of 92 checks passed
@westonruter
westonruter deleted the fix/phpstan-style-engine-types branch November 10, 2026 07:50
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 10, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
… errors when storing rules (WordPress#86468)

* Style Engine: Link docblock references to BLOCK_STYLE_DEFINITIONS_METADATA

Wrap the docblock mentions of the constant in
`{@see self::BLOCK_STYLE_DEFINITIONS_METADATA}` so the developer docs
link to it. `self::` keeps the reference valid after the build renames
the class with the `_Gutenberg` suffix.

Also qualify the mention in the inline comment in `get_classnames()`
and align its asterisks.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Style Engine: Add a PHPStan type for style definitions

Add a `Style_Definition` PHPStan type alias to `WP_Style_Engine`,
describing one entry of `BLOCK_STYLE_DEFINITIONS_METADATA`, and use it
for the constant and for every method that receives a definition. This
gives PHPStan the shapes of `property_keys`, `path`, `css_vars`,
`classnames`, and `value_func`.

Document the remaining raw style value parameters as `mixed`, since
`parse_block_styles()` passes whatever is found at the definition's
`path`, and the parsers already check its type. Also correct the
`classnames` entry of the `parse_block_styles()` return value, which is
an array rather than a space-separated string, matching core.

With the types in place, a few small code changes keep the analysis
sound without changing behavior for valid definitions:

* Read the sibling definition in
  `get_individual_property_css_declarations()` from the constant
  directly, instead of through `_wp_array_get()`, which loses its type.
* Return early from `get_css_declarations()` when a definition has
  neither a callable `value_func` nor `property_keys`, rather than
  reading an undefined index.
* Only build a `url()` value in `get_url_or_value_css_declaration()`
  when the value is an array with a string `url`.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Style Engine: Avoid a fatal error for a whitespace-only selector

`WP_Style_Engine::store_css_rule()` rejects an empty selector, but
`WP_Style_Engine_CSS_Rules_Store::add_rule()` trims the selector and
returns nothing when the result is empty. A selector made only of
whitespace therefore passed the first check and then called
`add_declarations()` on null, which is a fatal error. It is reachable
from `wp_style_engine_get_stylesheet_from_css_rules()` when a `context`
is passed.

Skip storing the rule when no store or rule is returned, and declare the
method's `void` return type.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Style Engine: Only return string values as CSS declarations

`get_css_declarations()` and `get_individual_property_css_declarations()`
are documented to return `string[]`, but they passed raw block style
values through unchanged, so a numeric value such as `textColumns: 2` or
a padding side of `5` ended up in the declarations as an integer.
`WP_Style_Engine_CSS_Declarations::add_declaration()` already drops
non-string values, so they never reached the compiled CSS; they only
leaked into the `declarations` array returned by
`wp_style_engine_get_styles()`.

Skip non-string values in both methods, so the return type holds. The
compiled CSS is unchanged.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Add this PR to the Style Engine backport changelog entry

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Style Engine: Cover non-string individual border declarations

---------

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: dknauss <dpknauss@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Style Engine /packages/style-engine [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants