It seems like phx-target takes precedence over the target: option, so manually pushing each distinct event should resolve the issue. (Tested on my end and it works at least! )
The given id is not automatically used as the DOM ID. If you want to set a DOM ID, it is your responsibility to do so when rendering:
defmodule UserComponent do
use Phoenix.LiveComponent
def render(assigns) do
~H"""
<div id={"user-#{@id}"} class="user">
<%= @user.name %>
</div>
"""
end
end
(You can verify by checking the browser devtools - LiveView will log a client-side error if the target ID doesn’t exist, i.e. nothing found matching the phx-target selector "#some-id".)