Skip to content
New issue

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

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

Already on GitHub? # to your account

[TwigComponent][LiveComponent] Compatibility with Twig 2.9 / use_yield #1390

Closed
1 of 3 tasks
smnandre opened this issue Jan 12, 2024 · 7 comments
Closed
1 of 3 tasks
Labels

Comments

@smnandre
Copy link
Member

smnandre commented Jan 12, 2024

See twigphp/Twig#3950 (comment)

For now i test with a local clone of the fabpot branch, and use_yield hard coded / changed in Environment class

Status

Work in progress

  • Adapt TwigComponent code 90% OK
  • Adapt LiveComponent code

Todo/Later

  • Use PrintNode/CaptureNode/etc instead of "echo"

PHPUnit log

TwigComponent failures

Time: 00:00.312, Memory: 34.00 MB

There was 1 error:

1) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testANonEmbeddedComponentCanRenderParentBlocksAsFallback

--

There were 20 failures:

1) Symfony\UX\TwigComponent\Tests\Integration\ComponentEventTest::testTemplateIsUpdatedByEventListener with data set "TWIG component tag" ('{% component "FooBar:Baz" %}{...ent %}')

src/TwigComponent/tests/Integration/ComponentEventTest.php:40

2) Symfony\UX\TwigComponent\Tests\Integration\ComponentEventTest::testTemplateIsUpdatedByEventListener with data set "HTML open-close tag" ('<twig:FooBar:Baz></twig:FooBar:Baz>')

src/TwigComponent/tests/Integration/ComponentEventTest.php:40

3) Symfony\UX\TwigComponent\Tests\Integration\ComponentExtensionTest::testCanRenderComponentWithMoreAdvancedTwigExpressions

src/TwigComponent/tests/Integration/ComponentExtensionTest.php:57

4) Symfony\UX\TwigComponent\Tests\Integration\ComponentExtensionTest::testCanRenderEmbeddedComponent

src/TwigComponent/tests/Integration/ComponentExtensionTest.php:156

5) Symfony\UX\TwigComponent\Tests\Integration\ComponentExtensionTest::testComponentPropsOverwriteContextValue

src/TwigComponent/tests/Integration/ComponentExtensionTest.php:208

6) Symfony\UX\TwigComponent\Tests\Integration\ComponentLexerTest::testComponentSyntaxOpenTags

src/TwigComponent/tests/Integration/ComponentLexerTest.php:28

7) Symfony\UX\TwigComponent\Tests\Integration\ComponentLexerTest::testComponentSyntaxCanRenderEmbeddedComponent

src/TwigComponent/tests/Integration/ComponentLexerTest.php:44

8) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testAnEmbeddedComponentHasContextAccess

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:39

9) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testABlockIsOnlyPassedOneLevelDown

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:52

10) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testABlockIsNotPassedToNestedComponents

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:62

11) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testBlockCanBeUsedWithinNestedViaTheOuterBlocks

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:77

12) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testBlockCanBeUsedViaTheOuterBlocks

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:89

13) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testBlockDefinitionsPassingDownOuterBlocksOverrideDefaultContent

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:100

14) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testDeepNesting

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:111

15) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testItCanHandleMissingOuterBlocks

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:122

16) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testPassingDownBlocksMultipleLevelsNeedsToBeDoneManually

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:135

17) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testBlockDefinitionCanAccessTheContextOfTheDestinationBlocks

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:147

18) Symfony\UX\TwigComponent\Tests\Integration\EmbeddedComponentTest::testANonEmbeddedComponentRendersOuterBlocksEmpty

src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:183
src/TwigComponent/tests/Integration/EmbeddedComponentTest.php:161

19) Symfony\UX\TwigComponent\Tests\Integration\Test\InteractsWithTwigComponentsTest::testCanRenderComponentWithSlots with data set #0 ('WithSlots')

src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php:73

20) Symfony\UX\TwigComponent\Tests\Integration\Test\InteractsWithTwigComponentsTest::testCanRenderComponentWithSlots with data set #1 ('Symfony\UX\TwigComponent\Test...hSlots')

src/TwigComponent/tests/Integration/Test/InteractsWithTwigComponentsTest.php:73

Legacy deprecation notices (4)
LiveComponent failures
Time: 00:04.753, Memory: 90.50 MB

There were 5 errors:

1) Symfony\UX\LiveComponent\Tests\Functional\EventListener\LiveComponentSubscriberTest::testItAddsEmbeddedTemplateContextToEmbeddedComponents
Behat\Mink\Exception\DriverException: There is no element matching XPath "//html"

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php:250

2) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testFormValuesRebuildAfterFormChanges
InvalidArgumentException: The current node list is empty.

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php:44

3) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testFormRemembersValidationFromInitialForm
Twig\Error\RuntimeError: Calling "Twig\YieldingTemplate::displayBlock" for block "form" is not supported as "use_yield" is set to "true" in "@LiveComponent/form_theme.html.twig".

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php:150

4) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testHandleCheckboxChanges
Twig\Error\RuntimeError: Calling "Twig\YieldingTemplate::displayBlock" for block "form_start" is not supported as "use_yield" is set to "true" in "@LiveComponent/form_theme.html.twig".

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php:200

5) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testResetForm
Twig\Error\RuntimeError: Calling "Twig\YieldingTemplate::displayBlock" for block "form_start" is not supported as "use_yield" is set to "true" in "@LiveComponent/form_theme.html.twig".


--

There were 13 failures:

1) Symfony\UX\LiveComponent\Tests\Functional\EventListener\AddLiveAttributesSubscriberTest::testItAddsIdAndFingerprintToChildComponent

src/LiveComponent/tests/Functional/EventListener/AddLiveAttributesSubscriberTest.php:115

2) Symfony\UX\LiveComponent\Tests\Functional\EventListener\InterceptChildComponentRenderSubscriberTest::testItAllowsFullChildRenderOnMissingFingerprints
2 elements matching css "ul li" found on the page, but should be 3.

src/LiveComponent/tests/Functional/EventListener/InterceptChildComponentRenderSubscriberTest.php:39

3) Symfony\UX\LiveComponent\Tests\Functional\EventListener\InterceptChildComponentRenderSubscriberTest::testItRendersEmptyElementOnMatchingFingerprintBasic
2 elements matching css "ul li" found on the page, but should be 3.

src/LiveComponent/tests/Functional/EventListener/InterceptChildComponentRenderSubscriberTest.php:52

4) Symfony\UX\LiveComponent\Tests\Functional\EventListener\InterceptChildComponentRenderSubscriberTest::testItRendersEmptyElementOnMatchingFingerprintWithCustomDataLiveId
2 elements matching css "ul li" found on the page, but should be 3.

src/LiveComponent/tests/Functional/EventListener/InterceptChildComponentRenderSubscriberTest.php:69

5) Symfony\UX\LiveComponent\Tests\Functional\EventListener\InterceptChildComponentRenderSubscriberTest::testItRendersNewPropWhenFingerprintDoesNotMatch
2 elements matching css "ul li" found on the page, but should be 3.

src/LiveComponent/tests/Functional/EventListener/InterceptChildComponentRenderSubscriberTest.php:84

6) Symfony\UX\LiveComponent\Tests\Functional\EventListener\InterceptChildComponentRenderSubscriberTest::testItUsesKeysToRenderChildrenLiveIds
2 elements matching css "ul li" found on the page, but should be 3.

src/LiveComponent/tests/Functional/EventListener/InterceptChildComponentRenderSubscriberTest.php:130

7) Symfony\UX\LiveComponent\Tests\Functional\EventListener\LiveComponentSubscriberTest::testItWorksWithNamespacedTemplateNamesForEmbeddedComponents
Element matching css ".component2" not found.

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php:271

8) Symfony\UX\LiveComponent\Tests\Functional\EventListener\LiveComponentSubscriberTest::testItUseBlocksFromEmbeddedContextUsingMultipleComponents
The text "Overridden content from component 1" was not found in the text of the element matching css "#component1".

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php:297

9) Symfony\UX\LiveComponent\Tests\Functional\EventListener\LiveComponentSubscriberTest::testItUseBlocksFromEmbeddedContextUsingMultipleComponentsWithNamespacedTemplate
The text "Overridden content from component 1" was not found in the text of the element matching css "#component1".

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php:336

10) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testLiveCollectionTypeAddButtonsByDefault
The last request threw an exception: Twig\Error\RuntimeError - Calling "Twig\YieldingTemplate::displayBlock" for block "...n "@LiveComponent/form_theme.html.twig".

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php:259

11) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testLiveCollectionTypeFieldsAddedAndRemoved
Current response status code is 400, but 422 expected.

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php:342

12) Symfony\UX\LiveComponent\Tests\Functional\Form\ComponentWithFormTest::testDataModelAttributeAutomaticallyAdded
The last request threw an exception: Twig\Error\RuntimeError - Calling "Twig\YieldingTemplate::displayBlock" for block "...n "@LiveComponent/form_theme.html.twig".

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php:402

13) Symfony\UX\LiveComponent\Tests\Integration\DataModelPropsSubscriberTest::testDataModelPropsAreAvailableInEmbeddedComponents
Failed asserting that '' contains "<textarea data-model="content">default content on mount</textarea>".

src/LiveComponent/tests/Integration/EventListener/DataModelPropsSubscriberTest.php:59

Remaining indirect deprecation notices (2)

  1x: SqliteSchemaManager::createDatabase() is deprecated. The engine will create the database file automatically. (SqliteSchemaManager.php:136 called by CreateDatabaseDoctrineCommand.php:84, https://github.com/doctrine/dbal/issues/4963, package doctrine/dbal)
    1x in LiveComponentSubscriberTest::_resetDatabase from Symfony\UX\LiveComponent\Tests\Functional\EventListener

  1x: Not configuring a schema manager factory is deprecated. Use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory which is going to be the default in DBAL 4. (Connection.php:221 called by DriverManager.php:197, https://github.com/doctrine/dbal/issues/5812, package doctrine/dbal)
    1x in LiveComponentSubscriberTest::_resetDatabase from Symfony\UX\LiveComponent\Tests\Functional\EventListener

@smnandre
Copy link
Member Author

smnandre commented Jan 14, 2024

Quick look for fixes

ComponentNode

$compiler
    ->write('if (null !== $preRendered) {')
    ->raw("\n")
    ->indent()
    ->write($compiler->getEnvironment()->useYield() ? 'yield $preRendered;' : 'echo $preRendered;')
    ->raw("\n")
    ->outdent()
    ->write('} else {')
    ->raw("\n")
    ->indent()
;
/*
 * Block 4) Render the component template
 *
 * This will actually render the child component template.
 */
$compiler->getEnvironment()->useYield() ? $compiler->raw('yield from  ') : $compiler->raw('echo ');
$compiler
    ->write('$this->loadTemplate(')
    ->string($this->getAttribute('embedded_template'))
    ->raw(', ')
    ->repr($this->getTemplateName())
    ->raw(', ')
    ->repr($this->getTemplateLine())
    ->raw(', ')
    ->string($this->getAttribute('embedded_index'))
    ->raw(')')
    ->raw('->yield($embeddedContext, $embeddedBlocks);')
    ->raw("\n");

@smnandre
Copy link
Member Author

More than 50% are easily solved by using PrintNode // i'll work on it this week-end

@smnandre
Copy link
Member Author

Only one failing left for TwigComponent (and it may be solved in Twig)

(https://github.com/smnandre/ux/tree/sa/yield-template)

We should then fix the code to use Node instead of "echo"

@smnandre smnandre changed the title [Twig] Errors with Twig 2.9 (dev) in TwigComponent & LiveComponent [TwigComponent][LiveComponent] Compatibility with Twig 2.9 / use_yield Jan 21, 2024
@smnandre
Copy link
Member Author

smnandre commented Feb 5, 2024

It's been merged on Twig side : twigphp/Twig#3950

weaverryan added a commit that referenced this issue Feb 14, 2024
…rue` for now) (smnandre)

This PR was squashed before being merged into the 2.x branch.

Discussion
----------

[Twig][Live] Skip Twig 3.9 🚒  (do not set `use_yield = true` for now)

As Symfony Twig Bridge & Twig Bundle have decided to skip Twig 3.9 for now, we should do the same, as testing and/or maintaining a compatible version would be really hard without the bundle support.

symfony/twig-bridge@2abddb1
symfony/twig-bundle@23a02ff

Update:

Twig 3.9 introduce a major change in the way templates are rendered, and to fully test/fix our compatibility, we need to wait Bridge and Bundle to allow Twig 3.9

In the meantime, please do not set "use_yield = true" as we are not ready yet.

This is something that has a major impact on TwigComponent and LiveComponent, and we'll probably need some changes on the CI / test suite to handle both modes.

---

Pull Request (compatibility - wip) : #1487 (help welcomed)
Issue: #1390
Twig PR : twigphp/Twig#3950

Commits
-------

6165384 [Twig][Live] Skip Twig 3.9 🚒  (do not set `use_yield = true` for now)
symfony-splitter pushed a commit to symfony/ux-live-component that referenced this issue Feb 14, 2024
…rue` for now) (smnandre)

This PR was squashed before being merged into the 2.x branch.

Discussion
----------

[Twig][Live] Skip Twig 3.9 🚒  (do not set `use_yield = true` for now)

As Symfony Twig Bridge & Twig Bundle have decided to skip Twig 3.9 for now, we should do the same, as testing and/or maintaining a compatible version would be really hard without the bundle support.

symfony/twig-bridge@2abddb1
symfony/twig-bundle@23a02ff

Update:

Twig 3.9 introduce a major change in the way templates are rendered, and to fully test/fix our compatibility, we need to wait Bridge and Bundle to allow Twig 3.9

In the meantime, please do not set "use_yield = true" as we are not ready yet.

This is something that has a major impact on TwigComponent and LiveComponent, and we'll probably need some changes on the CI / test suite to handle both modes.

---

Pull Request (compatibility - wip) : symfony/ux#1487 (help welcomed)
Issue: symfony/ux#1390
Twig PR : twigphp/Twig#3950

Commits
-------

61653842 [Twig][Live] Skip Twig 3.9 🚒  (do not set `use_yield = true` for now)
@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@smnandre
Copy link
Member Author

Done ;)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants