Skip to content

[LiveComponent] Execute model:set hook even for props changed on the server #1212

@weaverryan

Description

@weaverryan

Currently, the model:set JS hook is only triggered if a model is changed by something on the client-side - e.g. a user types into an input or the user has a <button data-model="foo" data-value="bar" data-action="live#update">.

But, if the user triggers a LiveAction, and in that code, we change the value of a prop in PHP, the model:set hook is NOT called. This was done originally... only slightly on purpose: it was more code to add this feature, so I waited until it came up. Now it has, via a user on Slack.

I think it makes sense to trigger this whenever a prop changes for any reason. We DO have a spot where the props from the server are used to update the client-side props - https://github.com/symfony/ux/blob/2.x/src/LiveComponent/assets/src/Component/ValueStore.ts#L107 - it might require some sort of diff to detect any changes, then trigger the hook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions