-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phoenix error when passing c &live_component/1
into a default slot
#254
Comments
c &live_component/1
into a default slotc &live_component/1
into a default slot
Thank you for the thorough big report! Can you share your temple config? |
Thanks for taking a look at this @mhanberg. It was tough to describe with any brevity! For configuring Temple in this Phoenix project, I have these entries in defmodule Cc.MixProject do
use Mix.Project
def project do
[
app: :cc,
...
compilers: [:temple] ++ Mix.compilers(),
...
]
end
defp deps do
[
...
{:temple, "~> 0.14.0"},
...
]
end
end this line at the bottom of config :temple, engine: Phoenix.LiveView.Engine and these lines in defmodule CcWeb do
...
defp html_helpers do
quote do
...
import Temple
import Phoenix.LiveView.TagEngine, only: [component: 3, inner_block: 2]
end
end
end (probably obvious, but the I had run into this #201, so a few of these things were pulled from the instructive PR linked there (georgevanderson/temple_liveview#1). But I'll be the first to admit I'm lacking in context/knowledge here – can't say I have a strong understanding of the purpose behind each line above. |
What version of LiveView are you using? |
Sorry - should have included the whole file, or even better, made a public repo. Did that now: https://github.com/evnp/phoenix-sandbox/blob/main/mix.exs Current version of LiveView (which I should update, by the looks of it) is: {:phoenix_live_view, "~> 1.0.0-rc.6", override: true}, |
I've been meaning to figure out single-file phoenix apps with phoenix-playground. Using that, have put together some minimal examples in case they're helpful: Repro of the issue (live component rendered with Temple inside a modal): Working version (live component rendered with Temple outside of a modal): |
I think there might be some kind of optimization that HEEx is doing compared to what temple does. for both, when you compile a component, it ends up being a call to a "component/3" function, and if you have slots, they are basically like function clauses. so in your example, the live component is surrounded by a function, which is what the docs say you can't do. heex does the same thing tho, which leads me to believe they must have something that declares its a "tag" (ie component) and not a normal function call. i'll investigate with the live view team |
First off, want to say I've loved working with Temple – what an incredibly beautiful DSL for expressing template structure and logic! I'm not sure if the situation described below is intended to be supported or not; I realize Temple isn't tightly coupled with Phoenix.
Describe the bug
Passing
c &live_component/1
into a default slot causes this error:Passing a function component in the same way works fine.
Rendering with HEEx instead and passing the live component through a default slot also works fine.
To Reproduce
I have this live component:
and this "control" function component:
In a normal live view, I want to pass the live component into a standard Phoenix modal (from default generated
core_components.ex
):Trying to render this, Phoenix throws the error above:
If I replace the live component with the functional component, things work as expected:
Screen.Recording.2024-12-14.at.12.12.31.PM.mov
If I replace the temple code in the parent live view with HEEx, things also work as expected, with the live component rendering successfully into the modal's default slot:
Screen.Recording.2024-12-14.at.12.19.03.PM.mov
Expected behavior
Ideally, this Temple code in a live view should successfully render a modal with content in the default slot from a live component:
Screenshots
Please see screenshots/recordings inlined above for clarity
Desktop (please complete the following information):
{:temple, "~> 0.14.0"}
Additional context
I imagine live components represent a complex set of factors to integrate well with – my impression overall is that even the Phoenix docs recommend avoiding them if at all possible in favor of simpler function components. I'm just wondering if this is a use case that Temple intends to support? It feels like a rough edge at the moment (I can work around it with an intermediate modal component that uses HEEx instead of Temple, but that's not ideal).
The text was updated successfully, but these errors were encountered: