Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn when phx-update="stream" is missing #3645

Merged
merged 1 commit into from
Jan 25, 2025
Merged

warn when phx-update="stream" is missing #3645

merged 1 commit into from
Jan 25, 2025

Conversation

SteffenDE
Copy link
Collaborator

This logs an error to the JS console when debug mode is enabled to warn users when they forgot to add phx-update="stream" to the direct parent of an inserted stream item.

@SteffenDE
Copy link
Collaborator Author

Note that we could also warn in LiveViewTest (I have the code lying around to do it):

warning: The stream container with id "users" is missing the phx-update="stream" attribute.

    <div id="users"><div id="users-1" data-count="0">
       chris
       <button phx-click="delete" phx-value-id="users-1">delete</button><button phx-click="update" phx-value-id="users-1">update</button><button phx-click="move-to-first" phx-value-id="users-1">make first</button><button phx-click="move-to-last" phx-value-id="users-1">make last</button><button phx-click="move" phx-value-id="users-1" phx-value-name="moved" phx-value-at="1">
         move
       </button><button phx-click="[[&quot;hide&quot;,{&quot;to&quot;:&quot;#users-1&quot;}]]">JS Hide</button></div><div id="users-2" data-count="0">
       callan
       <button phx-click="delete" phx-value-id="users-2">delete</button><button phx-click="update" phx-value-id="users-2">update</button><button phx-click="move-to-first" phx-value-id="users-2">make first</button><button phx-click="move-to-last" phx-value-id="users-2">make last</button><button phx-click="move" phx-value-id="users-2" phx-value-name="moved" phx-value-at="1">
         move
       </button><button phx-click="[[&quot;hide&quot;,{&quot;to&quot;:&quot;#users-2&quot;}]]">JS Hide</button></div></div>


LiveView needs this attribute to properly patch items on the client.

  (elixir 1.19.0-dev) lib/enum.ex:992: anonymous fn/3 in Enum.each/2
  (elixir 1.19.0-dev) lib/enum.ex:4511: anonymous fn/3 in Enum.each/2
  (elixir 1.19.0-dev) lib/enum.ex:4964: Enumerable.List.reduce/3
  (elixir 1.19.0-dev) lib/enum.ex:4511: Enum.each/2
  (phoenix_live_view 1.0.2) lib/phoenix_live_view/test/dom.ex:356: Phoenix.LiveViewTest.DOM.patch_id/4
  (phoenix_live_view 1.0.2) lib/phoenix_live_view/test/client_proxy.ex:656: Phoenix.LiveViewTest.ClientProxy.patch_view/4
  (phoenix_live_view 1.0.2) lib/phoenix_live_view/test/client_proxy.ex:156: Phoenix.LiveViewTest.ClientProxy.init/1
  (stdlib 6.1.2) gen_server.erl:2229: :gen_server.init_it/2
  (stdlib 6.1.2) gen_server.erl:2184: :gen_server.init_it/6
  (stdlib 6.1.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3

but the stacktrace is not very helpful.

This logs an error to the JS console when debug mode is enabled to warn
users when they forgot to add phx-update="stream" to the direct parent of
an inserted stream item.
@SteffenDE SteffenDE merged commit 3e86911 into main Jan 25, 2025
16 checks passed
@SteffenDE SteffenDE deleted the sd-stream-warning branch January 25, 2025 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants