Skip to content

[TwigComponent] Fix LiveComponent namespace mapping #1772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

smnandre
Copy link
Member

@smnandre smnandre commented Apr 23, 2024

I believe this modification fix #1754

Original problem

If you render a template @Acme/dashboard.html.twig, embedded Components (live or twig) referenced wrong template (dashboard.html.twig here), making LiveComponent impossible to rerender (this file beeing not referenced in the TemplateMap).

This behaviour was introduced in #1082 (and worked then). But i'm convinced all the work/changes made by Ryan to fix the embed bug (#1247 and related) made this obselete (and in this particular situation even originates a bug)

All tests are green, and i'd like to test it more heavily... but before that : do you think this is a bug fix or is there some kind of BC break here?

Copy link
Contributor

@WebMamba WebMamba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't think this is a BC break but a fix to a bug

Copy link
Member

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think bug also.

@smnandre smnandre force-pushed the twig/fix-namespace-template-mapping branch from 4269528 to 0514f59 Compare April 24, 2024 22:19
@@ -11,21 +11,24 @@

namespace Symfony\UX\TwigComponent\Twig;

/**
* @internal
*/
final class TemplateNameParser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class still necessary?

It's not parsing a template name anymore, but just validating the template name, which already happens in Twig\Loader\FilesystemLoader::parseName (in all scenarios in this class, it's just returning the name as-is, so it's just duplicating the validation logic from FilesystemLoader)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we cannot remove it because BC i guess.. @kbond ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this class internal so let's remove if not required anymore.

@smnandre
Copy link
Member Author

Ready to merge (confirmed to fix the original issue #1754 (comment) ) when you want guys ☺️

@kbond kbond force-pushed the twig/fix-namespace-template-mapping branch from d68cc3c to bb76055 Compare April 25, 2024 14:47
@kbond
Copy link
Member

kbond commented Apr 25, 2024

Thanks Simon.

@kbond kbond merged commit b54be75 into symfony:2.x Apr 25, 2024
6 of 7 checks passed
@melbings
Copy link

Thank you, everyone!

@sneakyvv
Copy link
Contributor

Hi Simon (@smnandre),

It seems it does introduce a BC break, because my templates are no longer found now :\

I'll investigate why this is happening, but since the namespace is no longer stripped (https://github.com/symfony/ux/pull/1772/files#diff-13fd1de1f292494959041e77eee8b739859160fb2f7da4290d278c9bdcdcb907L28). It cannot be found with the template name including the namespace.

However... perhaps it should be in the template map WITH a namespace....
which I also talked about in #1082 & #1070, but then assumed that the map was correct in stripping the namespace... I'm investigating whether this is correct or not now.

@sneakyvv
Copy link
Contributor

I went down to the TemplateIterator code, and it seems that my "fix" in #1070 was not correct.

Shopware, in which I'm using Live components, is stripping the namespace in its decorated version of the template iterator.
Don't know why, but it obviously goes against the normal usage of namespaces 😞

So to conclude: the TemplateNameParser is indeed obsolete now. I'll create a new PR to remove it!

smnandre added a commit that referenced this pull request Jan 25, 2025
…yvv)

This PR was merged into the 2.x branch.

Discussion
----------

[TwigComponent] Remove obsolete TemplateNameParser

It no longer parses (and should not have been stripping namespaces as it did before)

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| Issues        |
| License       | MIT

As discussed in #1772 (comment), the code added in #1070 (& expanded in #1082) was not needed (even incorrect, based upon a decorator TemplateIterator of Shopware).

Commits
-------

99cb909 Remove obsolete TemplateNameParser
symfony-splitter pushed a commit to symfony/ux-twig-component that referenced this pull request Jan 25, 2025
…yvv)

This PR was merged into the 2.x branch.

Discussion
----------

[TwigComponent] Remove obsolete TemplateNameParser

It no longer parses (and should not have been stripping namespaces as it did before)

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| Issues        |
| License       | MIT

As discussed in symfony/ux#1772 (comment), the code added in #1070 (& expanded in #1082) was not needed (even incorrect, based upon a decorator TemplateIterator of Shopware).

Commits
-------

99cb909ad Remove obsolete TemplateNameParser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LiveComponent] Live component will not render depending on Twig invocation syntax
7 participants