Skip to content

Commit cedbca5

Browse files
committed
Fix duplicate key in map warning
Closes #3912
1 parent f1e3839 commit cedbca5

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

lib/phoenix_live_view/engine.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,6 @@ defmodule Phoenix.LiveView.Engine do
791791
{_assign, :all} -> []
792792
{_assign, keys} -> keys
793793
end)
794-
|> Enum.uniq()
795794

796795
quote do
797796
unquote(__MODULE__).to_component_static(
@@ -866,6 +865,7 @@ defmodule Phoenix.LiveView.Engine do
866865
_ ->
867866
[]
868867
end)
868+
|> Enum.uniq()
869869
end
870870

871871
@doc false

test/phoenix_live_view/diff_test.exs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -983,13 +983,17 @@ defmodule Phoenix.LiveView.DiffTest do
983983
<div>
984984
<ul>
985985
<li :for={item <- @items}>
986-
{item.price}
986+
<%!--
987+
we deliberately access two fields here, because we had a bug that caused warnings
988+
https://github.com/phoenixframework/phoenix_live_view/issues/3912
989+
--%>
990+
{item.name} {item.price}
987991
</li>
988992
</ul>
989993
990994
<ul>
991995
<.li :for={item <- @items}>
992-
{item.price}
996+
{item.name} {item.price}
993997
</.li>
994998
</ul>
995999
</div>
@@ -998,39 +1002,46 @@ defmodule Phoenix.LiveView.DiffTest do
9981002

9991003
test "vars_changed" do
10001004
# This came up in issue https://github.com/phoenixframework/phoenix_live_view/issues/3906
1001-
assigns = %{socket: %Socket{}, items: [%{price: 0}], item: %{price: 0}}
1005+
assigns = %{
1006+
socket: %Socket{},
1007+
items: [%{price: 0, name: "First"}],
1008+
item: %{name: "First", price: 0}
1009+
}
10021010

10031011
{full_render, fingerprints, components} =
10041012
render(comprehension_with_and_without_component(assigns))
10051013

10061014
assert full_render == %{
1007-
0 => %{s: 0, k: %{0 => %{0 => "0"}, :kc => 1}},
1015+
0 => %{k: %{0 => %{0 => "First", 1 => "0"}, :kc => 1}, s: 0},
1016+
1 => %{
1017+
k: %{
1018+
0 => %{0 => %{0 => %{0 => "First", :s => 1, 1 => "0"}, :r => 1, :s => 2}},
1019+
:kc => 1
1020+
},
1021+
s: 3
1022+
},
10081023
:p => %{
1009-
0 => ["<li>\n ", "\n </li>"],
1010-
1 => ["\n ", "\n "],
1024+
0 => ["<li>\n ", " ", "\n </li>"],
1025+
1 => ["\n ", " ", "\n "],
10111026
2 => ["<li>", "</li>"],
10121027
3 => ["", ""],
10131028
4 => ["<div>\n <ul>\n ", "\n </ul>\n\n <ul>\n ", "\n </ul>\n</div>"]
10141029
},
1015-
:s => 4,
1016-
1 => %{
1017-
s: 3,
1018-
k: %{0 => %{0 => %{0 => %{0 => "0", :s => 1}, :s => 2, :r => 1}}, :kc => 1}
1019-
},
1020-
:r => 1
1030+
:r => 1,
1031+
:s => 4
10211032
}
10221033

10231034
assigns =
10241035
assigns
1025-
|> Map.put(:items, [%{price: 1}])
1036+
|> Map.put(:items, [%{name: "First", price: 1}])
10261037
|> Map.put(:__changed__, %{items: true})
10271038

10281039
{full_render, _fingerprints, _components} =
10291040
render(comprehension_with_and_without_component(assigns), fingerprints, components)
10301041

10311042
assert full_render == %{
1032-
0 => %{k: %{0 => %{0 => "1"}, :kc => 1}},
1033-
1 => %{k: %{0 => %{0 => %{0 => %{0 => "1"}}}, :kc => 1}}
1043+
0 => %{k: %{0 => %{1 => "1"}, :kc => 1}},
1044+
1 => %{k: %{0 => %{0 => %{0 => %{1 => "1"}}}, :kc => 1}}
10341045
}
10351046
end
10361047
end

0 commit comments

Comments
 (0)