It sounds like you really didn’t solve your other issue. It should work and accessing the socket directly I don’t think is going to help. If you really want to try, it’s available via this.liveSocket but maybe you could post a minimal app that reproduces your issue? Based on an answer in the other thread and another recent issue you had it sounds like you are doing things a little unconventionally, which is totally fine, but it means there is a lot of missing context for people trying to help you.
I don’t know what to tell you other than you need to share more actual code for context. Just describing what you’ve done isn’t enough since something small could be wrong.
Just out of curiosity, I tried to reproduce somewhat in a brand new phoenix app. I added:
# lib/app_web/router.ex
live "/", PageLive, :index
# lib/app_web/live/page_live
defmodule AppWeb.PageLive do
use AppWeb, :live_view
@impl true
def render(assigns) do
~H"""
<div id="some-id" phx-hook="El" class="h-10 px-4 mb-2 border border-black flex items-center" />
<button phx-click={JS.dispatch("started")} class="border border-black px-4">Click me</button>
"""
end
@impl true
def handle_event("clicked", _params, socket) do
{:reply, %{message: "clicked"}, socket}
end
end
No. The root template doesn’t have access to the socket as documented here. You can use the app layout, though. There’s more info on that doc page.
Ha, thanks for the consideration but it’s cool, just update it yourself and link back here and you can mark that as the answer Just pleeeeease share more context in future questions! If we had seen you were putting this stuff in the root template it would have been solved off the bat. In any event, happy you figure it out!