Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/LiveComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,17 @@ Doctrine entity objects are a special case for ``LiveProp``::
public Post $post;
}

.. note::

If you're using entities as ``LiveProp`` and having a ``mount`` method declared in
your component, it's required to manually hydrate the corresponding prop::

public function mount(Post $post)
{
$this->post = $post;
// .. doing something
}
Comment on lines +530 to +537
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's still not right, or else I didn't understand the issue... 😅

It is not related to \Symfony\UX\TwigComponent\ComponentFactory::mount(), that removes from $data, the properties defined in mount() arguments, requiring you to manually assign the property?

Given this example

#[AsTwigComponent]
class MyComponent {
    public string $foo;
    public string $bar;

    public function mount(string $foo, string $bar) {
        $this->foo = $foo;
        // missing $this->bar = $bar;
    }
}

Calling <twig:MyComponent foo="foo" bar="bar" /> will only set foo property if I'm not wrong.

To me, it is not related to LiveComponent at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In fact I'm pretty sure it's due to the mount/postHydrate confusion.... our doc is responsible of :)


If the ``Post`` object is persisted, its dehydrated to the entity's ``id`` and then
hydrated back by querying the database. If the object is unpersisted, it's dehydrated
to an empty array, then hydrated back by creating an *empty* object
Expand Down