Warning: phx-update="append" is deprecated, please use streams instead

Hi all,

Is this just a case of switching to stream() in my LV? Will try, just confused as it’s a phx-hook.

warning: phx-update="append" is deprecated, please use streams instead
Warning:   lib/sentrypeer_web/live/customer_nodes_live/overview.html.heex:30: SentrypeerWeb.CustomerNodesLive.Overview.render/1

Thanks.

The supported options for phx-update went from:

The following phx-update values are supported:

  • replace - the default operation. Replaces the element with the contents
  • ignore - ignores updates to the DOM regardless of new content changes
  • append - append the new DOM contents instead of replacing
  • prepend - prepend the new DOM contents instead of replacing

in v0.18.11 to the following in v0.18.12:

The following phx-update values are supported:

  • replace - the default operation. Replaces the element with the contents
  • stream - supports stream operations. Streams are used to manage large collections in the UI without having to store the collection on the server
  • ignore - ignores updates to the DOM regardless of new content changes

Basically, the append and prepend options were consolidated into a stream option. This is because streams offers more flexibility and lets us to choose to append or prepend to a collection when calling stream_insert/4. It defaults to append, but can be set to prepend by specifying the :at option as 0.

So instead of setting @node_probes as a socket assign, you’d stream it instead. Similarly, you’d want to stream_insert/4 rather than updating it as a socket assign. To finish off, you’d update the template to use phx-update="stream" as well as the streamed collection e.g. <div :for={{dom_id, node_probe} <- @streams.node_probes} id={dom_id}>.

6 Likes

Thank you very much! This is so kind of you to provide such a complete answer. Pointing me to those docs (which I forgot to search) would have been more than enough!

1 Like