Skip to content

[TwigComponent] Fix loadTemplate deprecation for Twig >= 3.21 #2713

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
May 16, 2025

Conversation

smnandre
Copy link
Member

@smnandre smnandre commented May 6, 2025

@Kocal
Copy link
Member

Kocal commented May 6, 2025

Are failing checks for LiveComponent https://github.com/symfony/ux/actions/runs/14850493570/job/41693042531?pr=2713 are related to your changes?

@smnandre
Copy link
Member Author

smnandre commented May 6, 2025

They are, but because they are hardcoded values.. that is dependending on internal code in TwigComponent.

Let's try to fix this later this week and we will merge this MR then.

->string($this->getAttribute('embedded_index'))
->raw(')');
} else {
// @deprecated since Twig 3.20
Copy link
Member

Choose a reason for hiding this comment

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

Either the comment should say deprecated since Twig 3.21 (or `compat for Twig <= 3.20 instead), or the version_id check is using the wrong version.

@Kocal Kocal force-pushed the fix/load-template-deprecations branch 3 times, most recently from ba75bd4 to 0839eea Compare May 15, 2025 20:55
@Kocal
Copy link
Member

Kocal commented May 15, 2025

I wasn't able to locally reproduce the errors from CI https://github.com/symfony/ux/actions/runs/15055025384/job/42318841525?pr=2713

1) Symfony\UX\LiveComponent\Tests\Integration\EventListener\DataModelPropsSubscriberTest::testDataModelPropsAreAvailableInEmbeddedComponents
Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("Call to undefined method __TwigTemplate_18a043059dae08abfc5bc95f85ec1668::load()").

/home/runner/work/ux/ux/src/LiveComponent/tests/Fixtures/templates/components/parent_component_data_model.html.twig:1
/home/runner/work/ux/ux/src/LiveComponent/vendor/twig/twig/src/Template.php:354
/home/runner/work/ux/ux/src/LiveComponent/vendor/twig/twig/src/Template.php:369
/home/runner/work/ux/ux/src/TwigComponent/src/ComponentRenderer.php:77
/home/runner/work/ux/ux/src/TwigComponent/src/ComponentRenderer.php:56
/home/runner/work/ux/ux/src/LiveComponent/tests/Integration/EventListener/DataModelPropsSubscriberTest.php:52

I've changed the condition to method_exists and tests are passing again https://github.com/symfony/ux/actions/runs/15055235144/job/42319532430?pr=2713

@Kocal Kocal force-pushed the fix/load-template-deprecations branch from c912fc2 to 52fb47c Compare May 15, 2025 21:14
@Kocal Kocal requested review from kbond and stof May 15, 2025 21:16
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels May 15, 2025
@smnandre
Copy link
Member Author

Let's not force-push / squash on previous commits when working on same PR, because that's hard to review then 😅

@Kocal Kocal force-pushed the fix/load-template-deprecations branch from 52fb47c to 3ed77b2 Compare May 16, 2025 08:05
@Kocal Kocal force-pushed the fix/load-template-deprecations branch from 3ed77b2 to 3df2c96 Compare May 16, 2025 08:37
@Kocal
Copy link
Member

Kocal commented May 16, 2025

Thanks Simon.

@Kocal Kocal merged commit d4c48be into symfony:2.x May 16, 2025
85 of 86 checks passed
@Kocal Kocal deleted the fix/load-template-deprecations branch May 16, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Reviewed Has been reviewed by a maintainer TwigComponent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ComponentNode uses $this->loadTemplate which is deprecated in Twig 3.20.0
5 participants