mononym

mononym

Stream data disappearing from liveview unexpectedly

I have a newly generated resource and affiliated LiveView components that are almost entirely “stock”, generated using Phoenix 1.7. What I have is a table populated by items that displays odd behavior as I’m working with the data, with table entries disappearing in the front end.

When I start it looks like this:

After I edit one of those entries using the pop-up modal what I see is this:

If I click on the flash message to make it go away, this is what I now see:

As stated this is almost entirely “stock” generated code. This is the save function in the form_component for the Map object:

  defp save_map(socket, :edit, map_params) do
    case Maps.update_map(socket.assigns.map, map_params) do
      {:ok, map} ->
        notify_parent({:saved, map})

        {:noreply,
         socket
         |> put_flash(:info, "Map updated successfully")
         |> push_patch(to: format_url(socket.assigns.patch, map.slug))}

      {:error, %Ecto.Changeset{} = changeset} ->
        {:noreply, assign_form(socket, changeset)}
    end
  end

The handler code for the parent receiving the message is:

  def handle_info({DionysusWeb.MapLive.FormComponent, {:saved, map}}, socket) do
    {:noreply, stream_insert(socket, :maps, map)}
  end

I have no other code modifying that stream (except for delete which isn’t being used here). This seems like fairly basic functionality so I’m wondering what exactly I’m doing wrong. Why are those table rows disappearing?

First Post!

slouchpie

slouchpie

I have encountered this same problem today.

It appears that using push_patch or <link patch={patch} causes stream entries to become an empty list.

Can you add a handle_params callback function to your Live View that does something like IO.inspect(Enum.count(socket.assigns.streams.maps))? That is what I am doing and I see the count of stream entries as “0” after the patch.

Most Liked

voughtdq

voughtdq

Ran into this problem and figured out what was going wrong, at least in my case. It’s probably mentioned in the documentation somewhere, but leaving this here for when it happens to me again in a year :crazy_face:

Basically if the stream container gets removed from the DOM, it loses the entries. So if you have something like :if={@live_action == :index} or <%= if @live_action == :index %> or whatever to hide the list, you lose those entries when it gets removed from the DOM. Instead, you need to use Phoenix.LiveView.JS.hide/1,2 or class={@live_action != :index || "hidden"}.

collectivelysuperior

collectivelysuperior

Make sure you have the required DOM attributes.. I had this behavior too until adding the phx-update=“stream” on the parent DOM container and the DOM id on each element.

Last Post!

anes

anes

In my case it was because my html container for stream elements was missing phx-update="stream" attribute.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement