Skip to content

Conversation

FabienSalles
Copy link

@FabienSalles FabienSalles commented Oct 17, 2025

Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? no
License MIT

In my project I don't use attributes like #[AsLiveComponent] in order to declare services and live components but I use yaml files (not my choice).
It works fine for all my services but live components are not well supported because we have to add extra parameters.

With #[AsLiveComponent] attribute, we have default values for :

  • the route metadata : 'ux_live_component'
  • and the url reference type metadata UrlGeneratorInterface::ABSOLUTE_PATH

We also add controller.service_arguments tag in LiveComponentExtension class.

But if we don't use this attribute and we want to use another type of service declaration, we have to add all this information :

services: MyServiceClass: tags: - name: twig.component live: true route: ux_live_component url_reference_type: 1 - name: controller.service_arguments

If we do not, we have errors likes theses :

An exception has been thrown during the rendering of a template ("Symfony\Component\Routing\Router::generate(): Argument #1 ($name) must be of type string, null given, called in /app/vendor/symfony/ux-live-component/src/Util/LiveControllerAttributesCreator.php on line 63") 
An exception has been thrown during the rendering of a template ("Symfony\Component\Routing\Router::generate(): Argument #3 ($referenceType) must be of type int, null given, called in /app/vendor/symfony/ux-live-component/src/Util/LiveControllerAttributesCreator.php on line 63") 
The controller for URI "/_components/my_customer_live_component" is not callable: Controller "MyCustomLiveComponentClass" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"? 

These errors do not exist for php attribute declaration so I made this PR to have the same behavior regardless of how the live component is declared

@carsonbot carsonbot added Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed labels Oct 17, 2025
@FabienSalles FabienSalles force-pushed the feat/add-default-parameters-to-none-atttributes-declaration branch from b5dd556 to d6c45ba Compare October 17, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed

2 participants