phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.02k stars 907 forks source link

Map assigns together with inner content in component causes "no function clause matching in Keyword.put/3" #1064

Closed henrik closed 4 years ago

henrik commented 4 years ago

Actual behavior

The combo of an inner content block and map (instead of keyword) assigns causes a cryptic "no function clause matching in Keyword.put/3".

Saw this in an error report by supernintendo in the Slack.

Repro below.

Changing the map to keywords, or skipping the inner content block, makes the error go away.

I suspect this is the offending code: https://github.com/phoenixframework/phoenix_live_view/blob/03b5e697d45f614188aa88094fdc680c6811c997/lib/phoenix_live_view/helpers.ex#L233-L240

Expected behavior

No error. Accepting the map as assigns.

Repro

defmodule RemitWeb.DebugLive do
  use Phoenix.LiveView

  @impl true
  def render(assigns) do
    ~L"""
    <%= live_component @socket, ListComponent, %{foo: "bar"} do %>
      <p>inner</p>
    <% end %>
    """
  end

  @impl true
  def mount(_params, _session, socket) do
    {:ok, socket}
  end
end

defmodule ListComponent do
  use Phoenix.LiveComponent

  @impl true
  def render(assigns) do
    ~L"""
    <p>outer</p>
    <%= @inner_content.(hello: "world") %>
    """
  end

  @impl true
  def mount(socket) do
    {:ok, socket}
  end
end
henrik commented 4 years ago

I'm assuming here that a map is allowed – but my impression from other code is that it is. Or if it's not, perhaps we could catch that with a better error.

henrik commented 4 years ago

❤️