Using gettext with the component below results in a error on the client (no logs on the server):
defmodule MyAppWeb.ComponentLive do
use Phoenix.LiveView
import MyAppWeb.Gettext
def render(assigns) do
~L"""
<%= if @state == :fetched do %>
<%= for message <- @messages do %>
<div><%= message %></div>
<% end %>
<% else %>
<div><%= gettext "Loading..." %></div>
<% end %>
"""
end
def mount(session, socket) do
Process.send_after(self(), :fetch_messages, 1000)
{:ok, assign(socket, :state, :loading)}
end
def handle_info(:fetch_messages, socket) do
{:noreply,
socket
|> assign(:messages, ["Hello", "There"])
|> assign(:state, :fetched)
}
end
end
After one second, this error is shown:

If I replace the gettext call with a static div (<div>Loading...</div>) it works correctly.
I'm not sure, but this seems like an issue with DOM diffing on the client. This was the simplest component to reproduce this issue, but I'm glad to help with more information if you guys need it :green_heart:
Oh, and before I forget, thanks for the great work on LiveView!
I think this issue is not related to Gettext.
I encountered the same problem with the following .leex template:
<%= if @selected_team == :none do %>
<ul>
<%= for team <- @teams do %>
<li>
<a phx-click="select_team" phx-value="<%= team.id %>"><%= team.name %></a>
</li>
<% end %>
</ul>
<% else %>
<h1><%= @selected_team.name %></h1>
<div><a phx-click="select_team" phx-value="">List of teams</a></div>
<% end %>
Somewhat peculiarly, rewriting the above code as follows will eliminate the error.
<% style = if @selected_team == :none, do: "", else: "display: none" %>
<ul style="<%= style %>">
<%= for team <- @teams do %>
<li>
<a phx-click="select_team" phx-value="<%= team.id %>"><%= team.name %></a>
</li>
<% end %>
</ul>
<%= if @selected_team != :none do %>
<h1><%= @selected_team.name %></h1>
<div><a phx-click="select_team" phx-value="">List of teams</a></div>
<% end %>
I also ran into this with gettext. Simple work-around was to add a if true do conditional around it.
Seems to be an issue with if-else. I encountered the same issue and was able to resolve it by replacing the if-else with a single if and a single unless (for the else).
Can somebody proviide a minimal app that reproduces this?
https://github.com/oskarkook/live_view_repro
The pattern I'm seeing is that this happens when for is inside an if-else and the if condition changes.
Thanks, it seems like a bug on JS side after all.
Fixed via #305