You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
0 commit comments