tfwright / live_admin

Low-config admin UI for Phoenix apps, built on LiveView
MIT License
251 stars 22 forks source link

ID collisions for embedded schemas #40

Closed Rio517 closed 1 year ago

Rio517 commented 1 year ago

Describe the bug It seems that embedded schemas that call LiveAdmin.Components.Container.Form.ArrayInput create ID collisions. I tried 0.8.0 and current main.

Relevant Resource schema

schema "profiles" do
    embeds_many(:work_experiences, WorkExperience, on_replace: :delete)
end

Embedded schema:

  embedded_schema do
    field :skills, {:array, :string}, default: []
  end

Error message:

** (RuntimeError) found duplicate ID :skills for component LiveAdmin.Components.Container.Form.ArrayInput when rendering template
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/diff.ex:635: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (stdlib 4.3) maps.erl:411: :maps.fold_1/3
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/diff.ex:628: Phoenix.LiveView.Diff.render_pending_components/6
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:833: Phoenix.LiveView.Channel.render_diff/3
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:469: Phoenix.LiveView.Channel.mount_handle_params_result/3
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:1041: Phoenix.LiveView.Channel.verified_mount/8
    (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:59: Phoenix.LiveView.Channel.handle_info/2
    (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
    (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {Phoenix.Channel, %{"params" => %{"_csrf_token" => "GAsPMxpgZxoTPQoafxBnFGMBAhczVBE9YZZVkMWuFK977iJn0tAzKyxo", "_mounts" => 0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GlyLkxpdmVBZG1pbi5Db21wb25lbnRzLkNvbnRhaW5lcm4GAJYch92IAWIAAVGA.cqEG4kB-N3WCDaHpPDrWMRE2W4P-M2KuYXpVqJDozvc", "static" => "SFMyNTY.g2gDaAJhBXQAAAADZAAKYXNzaWduX25ld2pkAAVmbGFzaHQAAAAAZAACaWRtAAAAFHBoeC1GMnFtUHVQMXlNWV9DZ1FHbgYAlhyH3YgBYgABUYA.y1Mwg0fi1uBvB3mOANqEN7Ia3RtyKEo7H5OebWAe8X8", "url" => "http://local.wunderwork.io:4000/min-admin/petal_pro_prospects_prospect/edit/1"}, {#PID<0.1873.0>, #Reference<0.3783962687.1405878278.173945>}, %Phoenix.Socket{assigns: %{}, channel: Phoenix.LiveView.Channel, channel_pid: nil, endpoint: PetalProWeb.Endpoint, handler: Phoenix.LiveView.Socket, id: "users_sessions:etD_rWtW5t2B0rJOxzPEjxFPkDCFQl9CNomicZwPu2U=", joined: false, join_ref: "4", private: %{connect_info: %{session: %{"_csrf_token" => "AQUeq-0oUv3-Hy-zSuCmx-iR", "live_socket_id" => "users_sessions:etD_rWtW5t2B0rJOxzPEjxFPkDCFQl9CNomicZwPu2U=", "locale" => "en", "user_token" => <<122, 208, 255, 173, 107, 86, 230, 221, 129, 210, 178, 78, 199, 51, 196, 143, 17, 79, 144, 48, 133, 66, 95, 66, 54, 137, 162, 113, 156, 15, 187, ...>>}, user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}}, pubsub_server: PetalPro.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "lv:phx-F2qmPuP1yMY_CgQG", transport: :websocket, transport_pid: #PID<0.1873.0>}}
State: #Reference<0.3783962687.1405878278.173948>
[error] an exception was raised:
    ** (RuntimeError) found duplicate ID :skills for component LiveAdmin.Components.Container.Form.ArrayInput when rendering template
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/diff.ex:635: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
        (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (stdlib 4.3) maps.erl:411: :maps.fold_1/3
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/diff.ex:628: Phoenix.LiveView.Diff.render_pending_components/6
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:833: Phoenix.LiveView.Channel.render_diff/3
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:469: Phoenix.LiveView.Channel.mount_handle_params_result/3
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:1041: Phoenix.LiveView.Channel.verified_mount/8
        (phoenix_live_view 0.19.2) lib/phoenix_live_view/channel.ex:59: Phoenix.LiveView.Channel.handle_info/2
        (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
        (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
        (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
tfwright commented 1 year ago

I need a bit more information to troubleshoot this. Can you include information about specific steps to reproduce the error?

tfwright commented 1 year ago

I actually reproduced this while working on https://github.com/tfwright/live_admin/pull/41 and fixed it in that PR