Repository navigation
Conversation
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.
🤖 PR meta 🤖📦 Bundle sizeSize Change: 0 B Total Size: 8.96 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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
|
# Conflicts: # .github/workflows/unit-test.yml
| // HTML props are printed as is; callers escape what they pass. | ||
| $html .= $value; | ||
| } else { | ||
| $html .= esc_html( $value ); |
There was a problem hiding this comment.
A plain-text label containing & 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?
There was a problem hiding this comment.
Good catch! Added a method to escape like react now, so entities stay literal. ec96867
| } | ||
|
|
||
| for ( const [ prop, schema ] of Object.entries( current ) ) { | ||
| if ( schema.required && ! released[ prop ]?.required ) { |
There was a problem hiding this comment.
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?
| 'packages/block-serialization-default-parser/*.php', | ||
| 'packages/icons/src/manifest.php', | ||
| 'packages/icons/src/library/*.svg', | ||
| 'packages/ui/build-php/manifest.php', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Good catch, didn't notice this with the local build. It should be working now, just tested it on the playground link d1f1ab6
…ample when its styles exist.
Keeps this PR to the essential behaviors. The build now fails if a translated string reaches the markup instead of being translated in PHP. The removed code, including the fix for renaming a required prop, comes back in a follow-up PR.
|
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. |
|
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. |
What?
See #84036.
A draft to explore rendering
@wordpress/uicomponents on PHP admin screens, starting with a Button subset. Everything is behind thegutenberg-ui-php-componentsexperiment. 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:
variant,tone,size, booleans), with placeholders for free-form props like the label. The renders are saved as snapshots inpackages/ui/build-php/manifest.php.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.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.disableduses the native attribute, so the browser blocks activation, and an e2e test checks that it can't be focused or activated.loadingis 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:
@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.php/<name>/component.json.component.jsonand snapshot. This is all it takes to add a component.gutenberg_get_ui_component(), prop validation, and the PHPUnit parity tests.01598d5 Contract: the props lock and deprecations.Moved to (PoC) UI PHP components: Add a props contract, deprecations and translations #84903 in 0e80315.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
npm run build.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.