mrfrenchfries
Using a Surface.Component from a Phoenix.Component?
Hello,
We’re trying to slowly move away from Surface into using regular Phoenix components (HEEX).
However we wish to still be able to use some of the surface components we already have. Is there a way to do that?
I tried calling it as <.MySurfaceComponent.render /> from a Phoenix.Component, which works for simple surface components, but when we have more complex components, it throws an error.
For example this:
defmodule MyAppWeb.Components.TestComponent do
use Phoenix.Component
alias MyAppWeb.Surface.TestSurfaceComponent
def test_component(assigns) do
~H"""
<div>
<div>lv_component</div>
<.another_component />
<TestSurfaceComponent.render myprop="myprop" />
</div>
"""
end
def another_component(assigns) do
~H"""
<div>
another_component
</div>
"""
end
end
defmodule MyAppWeb.Surface.AnotherSurfaceComponent do
use Surface.Component
def render(assigns) do
~F"""
<div>another surface component</div>
"""
end
end
defmodule MyAppWeb.Surface.TestSurfaceComponent do
use Surface.Component
alias MyAppWeb.Surface.AnotherSurfaceComponent
prop myprop, :string
def render(assigns) do
~F"""
<div>
<div>surface_component {@myprop}</div>
<AnotherSurfaceComponent />
</div>
"""
end
end
Crashes with:
[error] GenServer #PID<0.1365.0> terminating
** (KeyError) key :__context__ not found in: %{__changed__: nil, __caller_scope_id__: nil, myprop: "myprop"}
(my_app 0.1.0) lib/my_app_web/components/test_component.ex:37: anonymous fn/2 in MyAppWeb.Surface.TestSurfaceComponent."render (overridable 1)"/1
(my_app 0.1.0) /Users/ricardo/XUKU/my_app/lib/my_app_web/components/test_component.ex:10: MyAppWeb.Components.TestComponent.test_component/1
(elixir 1.15.2) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.3) lib/phoenix_live_view/diff.ex:384: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.3) lib/phoenix_live_view/diff.ex:538: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.15.2) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.3) lib/phoenix_live_view/diff.ex:384: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.3) lib/phoenix_live_view/diff.ex:136: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.19.3) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.19.3) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.19.3) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.7.6) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
(my_app 0.1.0) deps/plug/lib/plug/error_handler.ex:80: MyAppWeb.Router.call/2
(my_app 0.1.0) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.plug_builder_call/2
(my_app 0.1.0) deps/plug/lib/plug/debugger.ex:136: MyAppWeb.Endpoint."call (overridable 3)"/2
(my_app 0.1.0) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.call/2
(phoenix 1.7.6) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(bandit 1.0.0-pre.10) lib/bandit/pipeline.ex:116: Bandit.Pipeline.call_plug/2
Last message: {:continue, :handle_connection}
State: {%ThousandIsland.Socket{socket: #Port<0.60>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.3603920085.2461532163.4417>, start_time: -576460726155188000, start_metadata: %{remote_port: 58973, remote_address: {127, 0, 0, 1}, telemetry_span_context: #Reference<0.3603920085.2461532163.4417>, parent_telemetry_span_context: #Reference<0.3603920085.2461270018.260616>}}}, %{opts: %{websocket: [], http_1: [], http_2: []}, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {MyAppWeb.Endpoint, []}}, handler_module: Bandit.InitialHandler, http_1_enabled: true, http_2_enabled: true, websocket_enabled: true}}}
Most Liked
cmo
Using Surface components in vanilla Phoenix templates is partially supported but usually not recommended
1
Popular in Questions
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







