Repository navigation
Conversation
…ts-php-variant-changes # Conflicts: # lib/experimental/ui-components/class-gutenberg-ui-components.php
…ts-php-variant-changes # Conflicts: # lib/experimental/ui-components/class-gutenberg-ui-components.php # packages/ui/bin/build-php.mjs # packages/ui/bin/php/snapshots.mjs # packages/ui/php/README.md # phpunit/experimental/ui-components-test.php
🤖 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
|
…ts-php-variant-changes
|
This definitely has a marked improvement on the size of the manifest itself 👏 And in general if we were to adopt this approach of automatically converting React variants to equivalent PHP output, this would likely be the direction we'd want to adopt. To the original scalability concern raised in #84036 (comment), this doesn't help in regards to the fact that we're still computing every possible combination of props for every component, and managing this as diffs introduces its own complexity too. That seems like it may be inherently necessary as part of automating conversion of components, which is what gives me pause to that direction overall, and reevaluating whether there's a direction that allows us to reuse as much as possible across PHP & JavaScript implementations to narrow the scope of maintenance burden to the thin layer that needs to be specific to each (e.g. something like a language-agnostic class variance authority for managing at least the variant -> class mapping in each context). Another thought that occurs to me is whether we can reduce complexity by reusing pieces that are already available, like Interactivity API for some aspects of the "slots" that have been introduced here. I know you've been thinking about Interactivity API in #84036 in the context of interactive components, but I also wonder if there's aspects we can leverage there for strictly the attribute binding behavior, to reduce the custom behavior we have to implement. |
|
Thanks for taking a look @aduth!
That's a fair concern, especially for components with many props like
This is close to the prototype you shared, and I looked at a similar spec at the start. I explored this other direction because I was trying to reduce the friction that changing how So there might be a middle ground. A recipe and a small PHP template like in the prototype, checked against react's renders with parity tests, instead of react reading the recipe. React stays as it is, and the PHP side stays thin. It'd be worth comparing both with the same component.
That's interesting. Something like that could replace the placeholders, and take care of escaping. I'll take a look. |
What?
Builds on #84714. Following @aduth's feedback on #84036, the build now stores one base render plus what each variant changes, instead of a snapshot per combination.
How?
The build still renders every combination with React, but keeps only the default render and the classes and attributes each variant value adds or removes. It checks that this rebuilds every combination exactly, and stores the ones it can't (for example a variant that swaps an icon) in full. PHP applies the changes with
WP_HTML_Tag_Processor.Testing Instructions
npm run buildandnpm run build:wp --workspace @wordpress/ui. The output should say "a base, 7 changes and 0 full snapshots".npm run test:unit:php:base -- --filter Gutenberg_UI_Components_Testnow compares every combination with React.Use of AI Tools
I used Claude Code to help prototype and write parts of this code. I reviewed and tested all of it.