Compiler warnings using Liveview .18.3 attr

I have upgraded my project to use Liveview .18.3 and using attr macro for function components. However, I get compiler warnings…

warning: missing required attribute "stuff" for component TestWeb.Components.test/1
warning: undefined slot "inner_block" for component TestWeb.Components.test/1
warning: undefined slot "stuff" for component TestWeb.Components.test/1

The Function Component

  attr(:value, :string, required: true)
  attr(:stuff, :list, required: true)

  def test(assigns) do
    ~H"""
    <div><%= @value %></div>
    <div>Stuff: <%= render_slot(@stuff) %></div>
    <%= render_slot(@inner_block) %>
    """
  end

In heex

  <.test value="a value">
    <:stuff>stuff'ins</:stuff>
    <div class="bg-red-300">inner stuff</div>
  </.test>

It renders fine, just issues the compiler warnings.

It works because the component and the Heex template agree on what’s passed where.

The compiler warning is because the annotations don’t match the reality. Slots should be annotated with slot, not attr.

1 Like

YES - Slot is what I needed. Did not realize there was such a thing. Thanks