Anyone else having trouble with liveview phx-update/append docs?

Is anyone else having trouble with Phoenix Liveview’s phx-update? I feel like I must be doing something dumb or missing something key in the docs (https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#module-dom-patching-and-temporary-assigns).

This code doesn’t do the phx-update/append action, instead it seems to behave like it would if the phx-update term weren’t set.

defmodule LiveMessageTestWeb.TestMessage do
  use Phoenix.LiveView

  def render(assigns) do
    ~L"""
    <div id="chat-messages" phx-update="append">
      <%= for message <- @messages do %>
        <p><%= message %></p>
      <% end %>
    </div>
    """
  end

  def mount(_session, socket) do
    Process.send_after(self(), :ping, 100)
    socket = assign(socket, messages: [])
    {:ok, socket, temporary_assigns: [messages: []]}
  end

  def handle_info(:ping, socket) do
    Process.send_after(self(), :ping, 200)
    new_value = Enum.shuffle(?A..?Z) |> List.to_string
    {:noreply, assign(socket, :messages, [new_value])}
  end
end

I believe your example should work. If you are updating from an old LiveView version, make sure you rebuild your JS.

You can also give the example app a try. It has examples with phx-update: https://github.com/chrismccord/phoenix_live_view_example

thanks! I tried rebuilding the js and installing from scratch, so I have filed a bug report with the minimal setup!

Did you try the example app? Does it work there? They do work in the example for me. So what is different between them? :slight_smile:

Nevermind! I have confirmed the bug in your app. thanks for the example :smiley:

1 Like