I have the following component in my project:
defmodule UI.Icons do
use Phoenix.Component
attr :rest, :global
def loading(assigns) do
~H"""
<svg ... {@rest}>
...
</svg>
"""
end
end
I want to instantiate it with a custom attribute like this:
<UI.Icons.loading ui-loading />
This will generate the following warning:
warning: undefined attribute "ui-loading" for component UI.Icons.loading/1
│
59 │ ui-loading
│ ~~~~~~~~~~
│
└─ lib/ui_web/ui/button.ex:59: (file)
No problem, based on this documentation I can just add a prefix to the global prefixes or to the global attr option :include
for this component like this:
use Phoenix.Component, global_prefixes: ~w(ui-)
Or
attr :rest, :global, include: ~w(ui-)
Either way doesn’t work, it still gives me the same warning.
The only way that I found to make the warning go away was to add
use Phoenix.Component, global_prefixes: ~w(ui-)
To the component that would instantiate the UI.Icons.load
component inside its render function.
Is this behavior expected? Seems kinda off to me, I would expect that I would need to see this inside the component module/attr itself and not outside the same way I do with other custom attributes that are not prefixes.