Hi,
I have a weird problem with Phoenix Liveview, after upgrading to the latest version. Liveview sends a diff with null values.
I have the following template :
#These lists are assigned in the socket
#rows = [%{id: 1, user_name: "user1" },%{id: 2, user_name: "user2" }]
#cols = [:id,:user_name]
def render(assigns) do
~L"""
<button phx-click="replace_users" phx-value="all" type="button" class="btn btn-link">Replace Users</button>
<table>
<thead>
<tr><th>ID</th><th>Username</th></tr>
</thead>
<tbody>
<%= for row <- @rows do %>
<tr>
<%= for col <- @cols do %>
<td><%= Map.get(row,col) %></td>
<% end %>
<% end %>
</tr>
</tbody>
</table>
"""
end
def handle_event("replace_users", _ , socket) do
rows = [%{id: 2, user_name: "user2" },%{id: 3, user_name: "user3" }]
{:noreply, assign(socket, rows: rows)}
end
The first render works fine but when I click on “Replace users”, the diff sent by Liveview contains
4: {response: {diff: {0: {d: [[null], [null]]}}}, status: "ok"}
response: {diff: {0: {d: [[null], [null]]}}}
diff: {0: {d: [[null], [null]]}}
0: {d: [[null], [null]]}
d: [[null], [null]]
0: [null]
1: [null]
status: "ok"
But it works fine if I replace
<%= for col <- @cols do %>
<td><%= Map.get(row,col) %></td>
<% end %>
BY
<td><%= Map.get(row,:id) %></td>
<td><%= Map.get(row,:user_name) %></td>
Am I missing something? Is it a Liveview bug? The first render is ok, but if I go through the list of the keys after the click on “Replace users”, it doesn’t work and Liveview sends a diff with null values.
Thanks for your help.