Hi all, I’m trying to upgrade an old project LV14 up to LV16 at least.
One of the warnings is implicit assigns in live_component do-blocks is deprecated
With an example; which I think is a brilliant helping step.
However in the case, I have a bit of a mental block on how to tackle it with the code as is. Here is an example, rightly or wrongly there is a modal component that wraps another component.
<%= live_component HillWeb.ModalComponent, id: ComponentID.modal, session_id: @session_id do %>
<%= live_component HillWeb.MeasurementsComponent, id: :measurement_modal, session_id: @session_id, modal_data: @modal_data, path_info: [""] %>
<% end %>
I can’t quite figure out how to upgrade this to avoid implicit assigns in do-blocks. Anyone give me a clue on the missing step?
2 Likes
I’m running into this same issue, I have something like:
def render(assigns) do
~L"""
<%= live_component FormGroupComponent, f: @f, field: @field, label: @label, group_classes: @group_classes do %>
<%
options = assigns
|> Map.get(:other_options, [])
|> Keyword.merge([class: control_classes(@f, @field, @select_classes)])
%>
<%= select @f, @field, @options, options %>
<% end %>
"""
end
Based on the warning message if I add:
<% f -> %>
just below the live_component do
block, without changing anything else, the warning goes away. I don’t understand why, or what this is specifically asking me to do. I’d like a bit more understanding of this before I commit anything.
1 Like
I ended up jumping to 0.17 and then solving it via a code block like this:
<.live_component
module={DemoWeb.ModalComponent}
id={ComponentID.modal()}
session_id={@session_id}
>
<.live_component
module={DemoWeb.MeasurementsComponent}
id={:window_modal}
session_id={@session_id}
modal_data={@modal_data}
path_info={[""]}
/>
</.live_component>
That works for us now. But I did essentially give up at 0.16 and getting a clean compile. Glad I pushed onto 0.17 it’s feeling worth it now a few weeks later. HTH.