sjolicoeur

sjolicoeur

Hello,

full disclosure I am still very new to elixir and phoenix and liveview.

I am trying to transform a liveview controller and it’s. *.leex template into a component. The controller was auto generated with mix phx.gen.live and I am trying to turn the :show controller into a re-usable component that can be embedded in other views.

The first of which was to insert it into page_live.html.leex which according to the docs should work when

<%# live_render(@socket, ChatDemo.ChatRoomLive.Show, id: "ChatWindow", session: %{"id" => "07593216-b033-40e1-8c03-f32aa7375dec"} ) %>

But I get a no match of right hand side value: :not_mounted_at_router and somehow the debug page doesn’t show the expected content for session. I know it does require an :id in the params.

the controller works as a standalone, but not when rendered in another *.leex, is it possible to write a mount function that will work with live_render ? What am I doing wrong? or miss understanding?

the router entry:

  scope "/", DemoWeb do
    pipe_through [:browser, :admin_view]
    live "/message/:id", MessageLive.Show, :show
    live "/message/:id/show/edit", MessageLive.Show, :edit
  end

the liveview render call

<%= live_render(@socket, DemoWeb.ChatRoomLive.Show, id: "ChatWindow", session:  %{"id" => "07593216-b033-40e1-8c03-f32aa7375dec"} ) %>

the code seems to fail here

@impl true
  def mount(params, session, socket) do
    %{"id" => id} = params # FAILS HERE, but session only contains the csrf token
    if connected?(socket), do: Chat.subscribe()
    messages = Chat.list_message_for_chat_room(id)
    {:ok, socket
          |> assign(:messages, messages)
          |> assign(:message, %DemoWeb.Chat.Message{})
    }
  end

Showing Posts 1 to 3

APB9785

APB9785

Creator of ECSx

Which docs are you reading? From Phoenix.LiveComponent:

A component can be invoked as:

<%= live_component @socket, HeroComponent, content: @content %>
sjolicoeur

sjolicoeur OP

Yes, that was the page I was reading from… I managed to get further by commenting out my handle_params function. the logs had raised the issue it seems, but not the web based error.

Removing the handle_params fixed my issue. Also is @myself only possible to use in a live_component?

APB9785

APB9785

Creator of ECSx

From Phoenix.LiveComponent - Targeting Component Events:

If you want to send the event to yourself, you can simply use the @myself assign, which is an internal unique reference to the component instance

Note @myself is not set for stateless components, as they cannot receive events.

So yes, @myself is specific to stateful components.

As for handle_params/3, this function is not for LiveComponents to handle events, it is for the parent LiveView to handle URL parameters. LiveComponent events are handled with handle_event/3 - either in the LiveView (if the component is stateless), or in the component itself (if the component is stateful AND the event has phx-target="<%= @myself %>")

Looking through the mount/3 function in the OP, I think there is also a lack of context here that might make it difficult to troubleshoot this issue. You’re talking about a LiveComponent, but mount/3 is the mount for LiveViews (components use mount/1). If you’re still having trouble, please share the full repository so we can see how the LC is interacting with the parent LV.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews