aymanosman
See this GitHub issue Passing a slot via attributes emits a warning (but still works) · Issue #3399 · phoenixframework/phoenix_live_view · GitHub.
Currently, it is possible to pass along a slot argument to another component, but not without the compiler emitting a warning.
The warning looks like this:
warning: undefined attribute "loading" for component Phoenix.Component.async_result/1
│
133 │ I am a wrapper <.async_result assign={@assign} loading={@loading} inner_block={@inner_block} />
And here is an example of code that will induce the warning.
attr :assign, :any
slot :loading
slot :inner_block
def wrap_async_result(assigns) do
~H"""
<div>
I am a wrapper <.async_result assign={@assign} loading={@loading} inner_block={@inner_block} />
</div>
"""
end
<.wrap_async_result assign={AsyncResult.loading()}>
<:loading>Loading...</:loading>
Finished
</.wrap_async_result>
Assuming attributes and slots will always share the same “namespace” (so there could not be an attribute and slot with the same name defined on a component), it seems useful to be able to pass a slot via attributes.
Are there any downsides I’m not considering?
Trending in Proposals: Ideas
I recently learned about this API and was surprised there’s no explicit support for it in the the Phoenix.
Example use cases:
A webs...
New
I’m a bit in a fuzz about this topic. I’ve worked out some sort of Dropbox feature for a specific client. This feature allows him to uplo...
New
Other Trending Topics
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
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
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
The coupling. This might not matter much for like
inner_block, but all other slots can have their own set of attributes, which can be validated by the compiler, be documented and so on. All that doesn’t really work well if you can pass those slots to further components as is. Conceptually a slots really belongs to the component it’s rendered within, not some child component of it.Instead the wrapper can explicitly render slots for the subcomponent based on it’s own slots.
aymanosman
Your example should be…
…since
@loadingis also a slot.I agree that coupling is something to consider when components call other
components. But consider a function calling another function and passing through
arguments — this also introduces coupling, yet it’s natural in many cases.
As for checking and validation not working well, that seems more like a current
limitation of the compiler rather than an inherent conceptual issue with slots
being passed along. I was hoping to open up a discussion about the development
complexity this might introduce and weigh that against the potential benefits.
On the conceptual side, saying that slots belong strictly to the component
they’re rendered within feels a bit rigid to me. It’s similar to saying that
arguments strictly belong to a function and shouldn’t be passed to others.