Skip to content

(PoC) UI PHP components: Render @wordpress/ui components on PHP admin screens - #84714

Closed
juanfra wants to merge 19 commits into
trunkfrom
try/84036-ui-components-php
Closed

juanfra wants to merge 19 commits into
trunkfrom
try/84036-ui-components-php

Conversation

@juanfra

@juanfra juanfra commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

What?

See #84036.

A draft to explore rendering @wordpress/ui components on PHP admin screens, starting with a Button subset. Everything is behind the gutenberg-ui-php-components experiment. Not meant to merge as is. The goal is to test and explore the direction, I'd love some feedback on the approach.

Why?

PHP rendered admin screens use their own set of elements that have been componentized and now part of the design system. This initiative tries keeping React as the only implementation and reusing its output in PHP, so that we can consume it outside Gutenberg.

How?

The proposed approach was shared here. Changes from this PR:

  • At build time, Button is rendered with React for every combination of its variant props (variant, tone, size, booleans), with placeholders for free-form props like the label. The renders are saved as snapshots in packages/ui/build-php/manifest.php.
  • The CSS modules React uses are compiled into packages/ui/build-php/style.css, with the same class names React gets at runtime.
  • gutenberg_get_ui_component( 'button', $props ) validates the props, picks the matching snapshot, escapes and fills in the text, and enqueues the stylesheet.
  • The PHP contract is the component name and its props. A props lock and deprecations keep PHP callers working when React changes. Markup and class names aren't part of the contract. The props lock and deprecations moved to (PoC) UI PHP components: Add a props contract, deprecations and translations #84903 in 0e80315, to keep this PR to the essentials.
  • Following @ciampo's feedback on the issue, the PHP Button is a subset with no JavaScript. disabled uses the native attribute, so the browser blocks activation, and an e2e test checks that it can't be focused or activated. loading is left out for now, because React announces it from an effect.
  • build-php/ ships in the npm package, so core could sync it the way it syncs icons. Happy to hold that back until the approach settles.

This is a large draft PR, so I intentionally pushed commits in an order that could make it easier to look at:

  1. 6a9023f Build: export a way to compile CSS modules to a plain stylesheet (@wordpress/build). The only change to existing build code, with no change to its output. Everything else outside the experiment is plumbing: ignores, CI artifacts and the release file list.
  2. d80a180 UI build step: generate the static stylesheet and the snapshots from php/<name>/component.json.
  3. cc89a53 Button: its component.json and snapshot. This is all it takes to add a component.
  4. 5cd7221 PHP rendering: gutenberg_get_ui_component(), prop validation, and the PHPUnit parity tests.
  5. 01598d5 Contract: the props lock and deprecations. Moved to (PoC) UI PHP components: Add a props contract, deprecations and translations #84903 in 0e80315.
  6. 372c1d2 Preview page and visual check.

The commits after these are fixes on top of the steps. Happy to split any of these into separate PRs if that's easier to review.

Testing Instructions

  1. Run npm run build.
  2. Go to Settings > Experiments and enable "UI components for PHP screens".
  3. Go to Tools > UI Components.
  4. Check that the Button on the classic settings form looks like the design system Button, next to a classic button.
  5. In the examples table, check that each PHP render looks the same as React's.

Automated checks:

  • npm run test:unit:php:base -- --filter Gutenberg_UI_Components_Test (PHP output matches React for every example, prop validation, escaping~~, deprecations~~)
  • npm run test:e2e -- test/e2e/specs/admin/ui-components-php.spec.js (each example rendered by PHP with the PHP stylesheet, screenshotted against React's static markup with every stylesheet in the package, so a stylesheet missing from the PHP build shows up, and checks that a disabled PHP button can't be focused or activated)

Testing Instructions for Keyboard

On Tools > UI Components, Tab to the PHP-rendered Button. It should show the design system's focus ring, and Enter or Space should activate it, like the classic button next to it.

Use of AI Tools

I used Claude Code to help prototype and write parts of this code. I reviewed and tested all of it.

Moves the CSS module compilation into `compileCss()` and adds `compileStyleFile()`, exported from `@wordpress/build/compile-style`. A package can then emit its styles in another form, such as a static stylesheet for server-rendered markup, with the same scoped class names as the JavaScript build. No change to existing output.
Adds `bin/build-php.mjs`, which runs after the package build. It compiles the package's CSS modules into `build-php/style.css`, with the same class names as the JavaScript build, and renders each component declared in `php/<name>/component.json` for every combination of its variant props into `build-php/manifest.php`. The generated folder is ignored, cleaned, shipped in the plugin zip and passed to the PHP tests.
Declares Button's PHP props and how they map to the React component in `php/button/component.json`. `php/button/snapshot.html` is committed so reviewers see the markup PHP renders, and changes to it when React changes.
Adds `gutenberg_get_ui_component()` behind the `gutenberg-ui-php-components` experiment. It loads the generated manifest, validates the props against the component's schema, picks the matching snapshot, escapes and fills in the text, translates strings React translated, and enqueues the stylesheet. PHPUnit checks that every example renders the same markup as React.
`contract.lock.json` records each component's props as of the last release, and the build fails if one is removed or changes type without a deprecation. Deprecations map renamed props and values to their replacements with a `_deprecated_argument()` notice.
Tools → UI Components shows Button on a classic settings screen and every example next to React's render. A Playwright test screenshots both and compares them pixel by pixel.
…napshots

The build passed `disabled={ false }` to Button, which overrode its `disabled ?? loading` default, so the loading PHP button stayed clickable while React's was disabled. False booleans are now left out of the element, as a React caller would leave them out. Regenerates the Button snapshot and the contract lock's markup fingerprint.
`rest_validate_value_from_schema()` accepts `1`, `'1'` and `'true'` for a boolean, but the snapshot key expected a real boolean, so those values rendered nothing. Validated props are now sanitized from the schema too.
React blocks a disabled Button with Base UI's JavaScript and announces loading with `speak()` from an effect, and a snapshot carries neither. The PHP Button keeps `disabled` as the native attribute, so the browser blocks activation, and an end-to-end test checks it can't be focused or activated. `loading` is removed until there's a way to run its announcement on PHP screens. The README now lists what PHP components support and how their content is escaped.
@juanfra juanfra added [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible [Package] UI /packages/ui labels Oct 14, 2026
@github-actions github-actions Bot added the [Package] wp-build /packages/wp-build label Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

📦 Bundle size

Size Change: 0 B

Total Size: 8.96 MB

df7dc7c Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 961a5bf trunk % Change
timeToFirstByte 53.15 ms +11.19% -2.73% 53.5 ms +10.28% -2.62% -0.65%
largestContentfulPaint 92 ms +4.35% -4.35% 90 ms +11.11% -2.22% 2.22%
lcpMinusTtfb 37.1 ms +17.65% -9.16% 35.9 ms +20.61% -5.29% 3.34%
wpBeforeTemplate 28.67 ms +15.38% -2.06% 28.62 ms +10.66% -1.54% 0.17%
wpTemplate 20.76 ms +3.81% -4.34% 21.08 ms +5.74% -4.36% -1.52%
wpTotal 49.57 ms +11.42% -3.05% 49.85 ms +10.93% -2.73% -0.56%
wpMemoryUsage 7.64 MB +0% -0% 7.61 MB +0% -0% 0.46%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 961a5bf trunk % Change
timeToFirstByte 41.25 ms +8% -1.33% 41.05 ms +5.97% -1.34% 0.49%
largestContentfulPaint 92 ms +4.35% -4.35% 88 ms +4.55% -0% 4.55%
lcpMinusTtfb 49.3 ms +3.25% -3.65% 47.5 ms +2.42% -0.42% 3.79%
wpBeforeTemplate 26.4 ms +4.7% -1.29% 26.4 ms +2.92% -0.91% 0%
wpTemplate 11.93 ms +4.19% -1.17% 11.81 ms +5% -0.68% 1.02%
wpTotal 38.48 ms +8.52% -1.9% 38.36 ms +5.74% -1.36% 0.31%
wpMemoryUsage 6.21 MB +0% -0% 6.18 MB +0% -0% 0.59%
wpDbQueries 9 +0% -0% 9 +0% -0% 0%

media-processing

Metric 961a5bf trunk % Change
mediaProcessingJpeg 404.1 ms +1.59% -0.39% 402.69 ms +0.59% -0.9% 0.35%
mediaProcessingAvif 6043.11 ms +0.08% -0.19% 6059.27 ms +0.4% -0.11% -0.27%
mediaProcessingJpegToAvif 4171.51 ms +0.2% -0.08% 4167.73 ms +0.11% -0.09% 0.09%

media-upload

Metric 961a5bf trunk % Change
jpegUploadProcessing 1437.82 ms +37.54% -1.64% 1413.37 ms +1.56% -0.49% 1.73%
pngUploadProcessing 196.2 ms +12.5% -12.91% 193.08 ms +31.11% -6.56% 1.62%
largeJpegUploadProcessing 1415.12 ms +0.66% -0.6% 1403.11 ms +0.1% -0.49% 0.86%
multipleImageUploadProcessing 1570.56 ms +7.66% -1.14% 1542.28 ms +1.13% -0.57% 1.83%

post-editor

Metric 961a5bf trunk % Change
serverResponse 500.59 ms +5.65% -10.92% 491 ms +2.5% -6.05% 1.95%
firstPaint 437.83 ms +16.21% -42.63% 266.91 ms +89.08% -17.74% 64.04%
domContentLoaded 1189.87 ms +2.55% -2.02% 1179.98 ms +1.77% -2.06% 0.84%
loaded 1191.07 ms +2.53% -2.03% 1181.34 ms +1.76% -2.06% 0.82%
firstContentfulPaint 511.77 ms +2.76% -3.53% 514.62 ms +2.91% -6.64% -0.55%
firstBlock 3524.79 ms +0.46% -0.81% 3476.11 ms +0.92% -0.73% 1.4%
type 17.25 ms +4.06% -2.61% 17.32 ms +2.02% -2.54% -0.4%
typeWithoutInspector 17.51 ms +6% -1.94% 17.22 ms +4.47% -4.41% 1.68%
typeWithTopToolbar 22.72 ms +8.89% -12.19% 22.12 ms +7.14% -5.52% 2.71%
typeContainer 8.7 ms +15.98% -5.98% 8.9 ms +6.52% -5.51% -2.25%
focus 116.06 ms +18.42% -3.85% 117.07 ms +3.56% -12.99% -0.86%
firstFocus 212.71 ms +0% -0% 214.92 ms +0% -0% -1.03%
selectAll 567.02 ms +4.37% -1.59% 548.26 ms +0.51% -0.54% 3.42%
listViewOpen 77.52 ms +8.9% -5.13% 75.65 ms +6.69% -8.05% 2.47%
inserterOpen 38.69 ms +5.92% -3.83% 39.63 ms +3.91% -10.35% -2.37%
inserterHover 11.43 ms +8.49% -10.5% 10.62 ms +9.04% -6.87% 7.63%
inserterSearch 7.94 ms +14.61% -3.27% 8.02 ms +4.36% -2% -1%
loadPatterns 606.6 ms +2.18% -0.5% 602.91 ms +2.72% -3.12% 0.61%
wpTotal 490.02 ms +5.62% -11.02% 481.18 ms +2.17% -6.09% 1.84%
wpMemoryUsage 13.59 MB +0% -0% 13.55 MB +0% -0% 0.28%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric 961a5bf trunk % Change
serverResponse 285.41 ms +2.6% -6.07% 291.74 ms +2.21% -2.21% -2.17%
firstPaint 213.04 ms +68.43% -13.2% 243.23 ms +54.67% -22.97% -12.41%
domContentLoaded 862.79 ms +1.51% -4.5% 919.6 ms +2.66% -7.27% -6.18%
loaded 863.55 ms +1.5% -4.51% 920.76 ms +2.61% -7.3% -6.21%
firstContentfulPaint 369.05 ms +3.55% -2.77% 398.24 ms +1.93% -3.1% -7.33%
firstBlock 3141.06 ms +5.14% -3.42% 3422.1 ms +0.44% -4.53% -8.21%
type 16.18 ms +4.94% -6.49% 16.36 ms +2.02% -3.24% -1.1%
navigate 91.35 ms +5.77% -7.99% 86.4 ms +10.31% -1.86% 5.73%
loadPatterns 1064.95 ms +1.01% -5.83% 1077.68 ms +17.57% -9.36% -1.18%
loadPages 1043.47 ms +3.21% -3.51% 1073.57 ms +0.48% -0.72% -2.8%
wpTotal 278.33 ms +2.51% -6.28% 283.76 ms +2.45% -2.03% -1.91%
wpMemoryUsage 12.63 MB +0% -0% 12.59 MB +0% -0% 0.3%
wpDbQueries 44 +2.27% -0% 44.5 +1.12% -1.12% -1.12%

df7dc7c 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.

Regression: updating a specific option will only change its value and will not corrupt others in /test/e2e/specs/editor/various/core-settings.spec.js, passed after 1 failed attempt.
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

  Array [
    "rewrite_rules",
-   "SERIALIZED DATA",
+   "",
  ]
    at forEach (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/core-settings.spec.js:46:26)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/core-settings.spec.js:43:35
drags a multi-selection from anywhere inside it in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
TypeError: Cannot read properties of null (reading 'y')
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:824:57
    at dragSelectionBelowLanding (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:823:3)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:844:3
keeps the blocks selected after dropping a multi-selection in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
TypeError: Cannot read properties of null (reading 'y')
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:824:57
    at dragSelectionBelowLanding (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:823:3)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:908:3

df7dc7c Run

# Conflicts:
#	.github/workflows/unit-test.yml

@ciampo ciampo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few non-blocking comments

// HTML props are printed as is; callers escape what they pass.
$html .= $value;
} else {
$html .= esc_html( $value );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A plain-text label containing &amp; displays as & here, while React preserves the literal label. Could we preserve existing entity spellings in text and ordinary attribute slots, with a regression case for their parsed values?

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.

Good catch! Added a method to escape like react now, so entities stay literal. ec96867

Comment thread packages/ui/bin/php/contracts.mjs Outdated
}

for ( const [ prop, schema ] of Object.entries( current ) ) {
if ( schema.required && ! released[ prop ]?.required ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Renaming required label to required text still fails this check even when a deprecation preserves existing calls. Could the required-prop check account for that mapping and cover this rename?

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.

Makes sense! Updated the check here 135a735

'packages/block-serialization-default-parser/*.php',
'packages/icons/src/manifest.php',
'packages/icons/src/library/*.svg',
'packages/ui/build-php/manifest.php',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The archive includes the preview page but omits its example data and comparison stylesheet, so the Examples table is empty and the React sample view emits a missing-file warning. Could we ship those assets with the page or register the preview only when they're available?

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.

Good catch, didn't notice this with the local build. It should be working now, just tested it on the playground link d1f1ab6

@juanfra juanfra changed the title PoC: Render @wordpress/ui components on PHP admin screens (PoC) UI PHP components: Render @wordpress/ui components on PHP admin screens Oct 16, 2026
@juanfra
juanfra added this pull request to stack #84904 October 16, 2026 09:03
@juanfra

juanfra commented Oct 16, 2026

Copy link
Copy Markdown
Member Author

Following the feedback here and on #84036, I split things up so this PR keeps only the essential behaviors, and the rest can be reviewed on its own:

Happy to adjust the split if a different one is easier to review.

@juanfra

juanfra commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews here! I've narrowed it down into a smaller base in #85756, with a different approach but with the markup generated from React at build time as a draft on top of it (#85759), so both can be compared on the same component and tests.

I shared an updated proposal on the issue with what changed and why. Closing this one in favor of those.

@juanfra juanfra closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Package] wp-build /packages/wp-build [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants