It looks like with
0.5 the direction for handling events in components is to make sure they’re targeted explicitly using
phx-target , otherwise the event gets sent to the parent LiveView. Having tested this, it makes sense in terms of ensuring that events aren’t sent to the wrong handler, but the
phx-target approach is a little cumbersome right now as it’s necessary for the component to keep track of its own
id then make sure to explicitly set the DOM ID of a rendered element and set the
phx-target for element events. I feel like the use case wherein a given stateful component handles its own events by default is more typical.
With the current approach, the assumption also seems to be that LiveViews and LiveComponents are tightly coupled, and that a typical use case is for a stateful component to defer to a parent live view to handle events. Having played around with it, I think it would make more sense to pass events up to the nearest stateful component by default, with the ability to target a given component or the parent live view using
phx-target if needed. If there’s no stateful component between the element that emitted the event and the parent live view, then the live view handles the event. I’d be interested to get your thoughts on this approach, if it’s something you’d be interested in using for the next release then I’d be happy to help out.