-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #1093 [TwigComponent][LiveComponent] Fix DataModelPropsSubscriber…
… for embedded components (sneakyvv) This PR was squashed before being merged into the 2.x branch. Discussion ---------- [TwigComponent][LiveComponent] Fix DataModelPropsSubscriber for embedded components | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | | License | MIT ### Reproduce ``` {# components/A.html.twig #} <B> {# content doesn't matter, as long as it's an embedded component #} </B> ``` ``` {# components/B.html.twig #} <C data-model="X"/> ``` (given a component B with a prop X) With this setup the `DataModelPropsSubscriber::preMount()` would result in an error "_Can't get a way to read the property "X" in class "A"_". An even simpler setup ``` {# anyTemplate.html.twig #} <A> {# A is already embedded #} </A> ``` Will result in "_You can only pass "data-model" when rendering a component when you're rendering inside of a parent component._" Whether the data-model attribute is deep inside template B or already in template A doesn't matter. The thing is that during rendering of A, which is now embedded, there's no component on the stack. ### Problem Self-closing component are rendered via `ComponentRenderer::createAndRender()`. Embedded components are rendered via `ComponentRenderer::embeddedContext()` + `Template::display()`. Both push the component being rendered on the `ComponentStack`, and pop it again at the end of the `ComponentRender` functions. During the rendering of C, B is already been popped from the stack, and therefore the `DataModelPropsSubscriber` doesn't have a way to find the parent component context. And it incorrectly uses component A, which is still on the component stack (while it should be linked to B). ### Solution The rendering of an embedded component is only really done after the `Template::display()` execution. Therefore the component can only be removed when BOTH are done. Commits ------- 6933040 [TwigComponent][LiveComponent] Fix DataModelPropsSubscriber for embedded components
- Loading branch information
Showing
12 changed files
with
166 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/LiveComponent/tests/Fixtures/Component/InputComponent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Component; | ||
|
||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; | ||
|
||
/** | ||
* @author Bart Vanderstukken <[email protected]> | ||
*/ | ||
#[AsTwigComponent('input_component')] | ||
final class InputComponent | ||
{ | ||
} |
24 changes: 24 additions & 0 deletions
24
src/LiveComponent/tests/Fixtures/Component/ParentComponentDataModel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Component; | ||
|
||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
|
||
/** | ||
* @author Bart Vanderstukken <[email protected]> | ||
*/ | ||
#[AsLiveComponent('parent_component_data_model')] | ||
final class ParentComponentDataModel | ||
{ | ||
use DefaultActionTrait; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/LiveComponent/tests/Fixtures/Component/ParentComponentDataModel2.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Component; | ||
|
||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\LiveComponent\Attribute\LiveProp; | ||
use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
|
||
/** | ||
* @author Bart Vanderstukken <[email protected]> | ||
*/ | ||
#[AsLiveComponent('parent_component_data_model_2')] | ||
final class ParentComponentDataModel2 | ||
{ | ||
use DefaultActionTrait; | ||
|
||
#[LiveProp(writable: true)] public string $content; | ||
} |
1 change: 1 addition & 0 deletions
1
src/LiveComponent/tests/Fixtures/templates/components/input_component.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<input{{ attributes }} /> |
2 changes: 2 additions & 0 deletions
2
src/LiveComponent/tests/Fixtures/templates/components/parent_component_data_model.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% component parent_component_data_model_2 with { content: 'default content on mount' } %} | ||
{% endcomponent %} |
2 changes: 2 additions & 0 deletions
2
...LiveComponent/tests/Fixtures/templates/components/parent_component_data_model_2.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{ component('textarea_component', { dataModel: 'content' }) }} | ||
{% component input_component with { dataModel: 'content' } %}{% endcomponent %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters