Skip to content

[TwigComponents] Using FQCN to load component leads to component being loaded anonymously #3195

@janopae

Description

@janopae

According to the docs, you can use both, the actual class name and a special : syntax to load a twig component. This worked until da0537d:

Internally, the ComponentFactory would use the : syntax to store config per component, but it also has a $this->classMap, which maps the actual class name to the : version. Before doing anything, the ComponentFactory would ask the classMap to resolve the loaded component name, only then it would proceed with loading.

This changed in da0537d: Now, it first tries to load the component with the provided name directly, and if that doesn't work, it will load the component anonymously (which means: the class will be ignored, only the Twig template will be loaded).

There is still code that uses the classMap, but that will only be executed if the template can't be loaded anonymously. Which I think will never happen, because any component has a Twig template? At least, it will never happen if the component has a Twig template, because unlike ComponentFactory after da0537d, ComponentTemplateFinder is able to resolve FQCNs.

It turned out I was wrong about Twig always being able to load a template for an FQCN: It is only able to load a template anonymously for the FQCN if the template path equals the FQCN (with backslashes replaced with slashes and ignoring the file extension). This is the case for all templates in my project, but I think it is not for the Symfony default. Because this issue only occurs in that case, it is not easy to reproduce. I created a reproducer in this repo: https://github.com/janopae/reproduce-symfony-ux-540

So essentially, identifying the component by class name now leads to the class being ignored. Given the tags containing da0537d, this affects all versions from 2.20.0 to 2.31.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions