phoenixframework / phoenix_live_view

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

`render_component/3` emits a warning (`expected a module`) when given an anonymous function. #3297

Closed jbcaprell closed 3 weeks ago

jbcaprell commented 3 weeks ago

Environment

Behavior

Running this test:

  import Phoenix.LiveViewTest

  test "icon/1" do
    render_component(&HelloWeb.CoreComponents.icon/1, %{name: "hero-x-mark-solid"})
  end

… emits a warning:

....    warning: expected a module (an atom) when invoking __live__/0 in expression:

        component.__live__()

    where "component" (context Phoenix.LiveViewTest) was given the type:

        # type: fun()
        # from: test/hello_web/controllers/page_controller_test.exs:12
        component = &HelloWeb.CoreComponents.icon/1

    hint: "var.field" (without parentheses) means "var" is a map() while "var.fun()" (with parentheses) means "var" is an atom()

    │
 12 │     render_component(&HelloWeb.CoreComponents.icon/1, %{name: "hero-x-mark-solid"})
    │     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ test/hello_web/controllers/page_controller_test.exs:12: HelloWeb.PageControllerTest."test icon/1"/1
SteffenDE commented 3 weeks ago

I believe this was fixed with https://github.com/phoenixframework/phoenix_live_view/commit/489e8de024e03976e9ae38138eec517fbd456d27 already. Can you please try {:phoenix_live_view, "~> 1.0.0-rc.0"} or {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", branch: "main", override: true}?

jbcaprell commented 3 weeks ago

Sure enough, you’re right!