Symfony UX Bundle
Following the discussions at https://github.com/symfony/ux/issues/3203, let's open a new RFC for the Symfony UX Bundle!
This is something the UX team has been thinking about privately for a while, but opening a public RFC can only be beneficial (rather than volatile Slack messages or verbal discussions 😇 ).
Similar to the FrameworkBundle, the UX Bundle would allow Symfony UX packages to be automatically configured in a Symfony application.
This would have the following advantages:
- centralizing the configuration of Symfony UX packages,
- pooling certain logic, e.g., “is AssetMapper installed?”, “add this path to AssetMapper,” etc.,
- and reducing the PHP “glue” code to register a Symfony UX package in a Symfony application.
- and more
Steps
Plan for 2.X
~~I would like the UX Bundle to be available (and optional) for version 2.x.~~
~~This way, we could work on BC layers and tell users that directly registering a bundle (e.g., UxTranslatorBundle in bundles.php) is deprecated, as are the associated DependencyInjection/*.php classes.~~
~~Instead, we could suggest installing the Symfony UX Bundle.~~
~~This will require, for each UX package:~~
- ~~deprecating
*Bundle.phpand its associated classes (mainlyConfiguration.php,*Extension.php, etc.)~~ - ~~duplicating and adapting the
Configurationin the UXBundle, under the configurationux_bundle.<package>~~ - ~~duplicating the
config/services.phpand renaming themconfig/<package>.php~~ - ~~...more?~~
EDIT: let's skip this for 2.x!
Plan for X.0
For the next major version, we should:
- identify which package can be migrated to "component"
- move
config/*files - migrate and delete
*Bundle.phpand associated DependencyInjection classes - ...more?
Symfony Recipes
All Symfony recipes for Symfony UX will need to be adapted, ~if possible as soon as UX Bundle is released in 2.x.~.
Last version of 2.x recipes must be duplicated and adapter to 3.0, e.g.: configuration ux_translator will become becomes ux.translator.
Q&A
Q: What about the StimulusBundle? Should we adapt the existing the StimulusBundle, or create a new package?
A: ???
Q: When someone installs a dependency in major version X, is the recipe for major version X-1 applied? If not, we will need to duplicate our previous recipes in 3.0.
~~To investigate.~~
A: We will duplicate the recipe for UX 3.0.
Q: Did I miss something?
A: Tell me! :D
I'm strongly opposed to introducing the UX bundle in 2.x, and I'm honestly a bit shocked by this.
We agreed months ago to release 3.x first, to clear all deprecations and reduce the legacy we're carrying, and only then build new features on top of it.
For my part, I won't be submitting any new features to 2.x
The first half of this year, spent fixing old bugs and maintaining features/components I neither like nor recommend.. and handling the whole security-issues period, has taken a real toll on my mental health.
For many reasons, I now need to look forward rather than back, and I want to focus on the work I enjoy and believe in: developing new features, improving DX, integration between the UX components and outside libraries, bundle, standards.
I'm fine for no BCP layer, that would make things easier for us.
I will edit the issue description ASAP
Original description updated, we still need to figures out:
- should we create a new package for that?
- Symfony provides Bundles and Components in https://github.com/symfony/symfony, do we have some packages that can't become components but must stays bundles?
- should we create a new package for that?
Absolutely.
Stimulus wires JavaScript. UXBundle wires UX :)
2. Symfony provides Bundles and Components in https://github.com/symfony/symfony, do we have some packages that can't become components but must stays bundles?
As I see it, Toolkit maybe (depending on the install / runtime).
I guess Inspector would be one too, like WDB is.
And I have no idea regarding the react/vue/svelte/etc ones... maybe one dedicated UX\Node component would be a place / way to group them, or some UX\Bridge\* ?
But... in all manner if we follow symfony/symfony method, and to ease the transition, we should probably keep DI classes in each current packages for some time, making it easy to integrate in UX while avoiding code duplication
This would have the following advantages: centralizing the configuration of Symfony UX packages, pooling certain logic, e.g., “is AssetMapper installed?”, “add this path to AssetMapper,” etc., and reducing the PHP “glue” code to register a Symfony UX package in a Symfony application.
- enforcing global conventions/choices: preferred CSS framework or shared mount URLs across all components
- decoupling the ecosystem, acting as the UX entry point so stacks like "Turbo + Icons" can function without depending on Stimulus
- reducing composer friction by having one consistent place for “integration-level” constraints (instead of many bundles each declaring slightly different constraints)
- making upgrades clearer: one integration layer (UXBundle) rather than N bundles
- discarding the coupling that makes “Symfony UX” synonymous with “Stimulus”,
- making it possible to add a small but impactful Twig feature once and benefit everywhere (e.g. a default “unregistered filter/function” callback, or shared extension wiring)
- allowing feature packages to act as pure libraries (like symfony/mailer), removing the need for them to ship their own Bundle class
And ... providing a stable extension point in the future, offering community packages a standardized way to plug into the ecosystem via shared events and conventions.
There isn’t much choice for the rollout:
- ship UXBundle in 3.x as experimental,
- deprecate the legacy per-package bundles in 3.x (with an easy migration path),
- make UXBundle a central piece of 4.0 (the "default" integration story),
- while ensuring external projects can keep using UX packages without friction.
This is not a "tomorrow" concern (and shouldn’t become one), more a direction for the next major steps.. but a good reason to avoid heavy "bundle refactors" in 2.x that would be thrown away once the 3.x -> 4.0 path starts :)
Almost forgot one of the biggest motivation: DX.
# interactive setup (pick what you want, apply the right wiring/config)
symfony bin/console ux:install
# checks the packages json / yarn lock / importmap
symfony bin/console ux:doctor
# shows common paths + configs in one place
symfony bin/console ux:debug
Thanks for answering my questions and put all you had in mind here, that's much appreciated!
- Symfony provides Bundles and Components in symfony/symfony, do we have some packages that can't become components but must stays bundles?
As I see it, Toolkit maybe (depending on the install / runtime).
I guess Inspector would be one too, like WDB is.
👍🏻
And I have no idea regarding the react/vue/svelte/etc ones... maybe one dedicated UX\Node component would be a place / way to group them, or some UX\Bridge* ?
Mmmh, I don't know....
Actually, the more I think about it, the more I realize that all our UX packages can only be bundles. It's not as if we want Icons or Translator to be usable outside of Symfony/Symfony UX, is it?
Well, it's hard to answer your last point without giving a full presentation of "what I think UX could or should be today, next month, next year, ..."
But i'll try :) And please take the examples I'm giving in the next lines as "examples ... but not just examples" 😅
Component VS Bundle
t's not as if we want Icons or Translator to be usable outside of Symfony/Symfony UX, is it?
Many Bundle?
Outside Symfony and outside Symfony UX are not different to me. And here, I'm making a real difference between UX Vue / Svelte that are glue-code between lib and Symfony.. and are very good usage of what a Bundle can do/be.
Many Packages
We also have (and will have) other ones that are both component and bundles: UX Map is a good example, with all the VO/classes/factory we have, the location helpers, the clustering algorithms, etc.
If I tell you "Image" (thus my doubts about making it nothing more than a wrapper for CDN calls) or ... Fonts .. I do believe we have much to offer to bring quality focused components to the PHP world.
And I really do think this approach is a good one, providing standard abstractions or DX on generic needs, and as such could 100% be used by any PHP project, within Symfony app or not.
One DX
But.. more than "outside" the key part to me would be "together". LiveComponent is a good example where it has too many responsibilities at once. And it would offer central configuration (very important point), handle cross dependencies and version pinning, offer shared-common aliases/services...
A "central" bundle could allow easily bring LiveComponent / UX Form / UX Store / UX Events together, without any of the three needing to know about the other ones.
Last but not least: i'm only discussing Symfony UX official packages here..... BUT you know I'm also thinking mid-term.. And the second you introduce the notions of community packages, extensions, third-party components, etc.... :)