mononym

mononym

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?

Showing Posts 1 to 5

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.

azyzz228

azyzz228

i have the same issue. but in my case. page renders, stream elements are also rendered, but then they disappear.

my mount sets live_action based on one field, then i have handle_params like this:

  def handle_params(params, _url, socket) do
    {:noreply, apply_action(socket, socket.assigns.live_action, params)}
  end
 defp apply_action(socket, :active, _params) do
    if connected?(socket),
      do:
        Phoenix.PubSub.subscribe(
          Yetkazuv.PubSub,
          "restaurant-#{socket.assigns.vendor_restaurant.id}"
        )

    orders = socket.assigns.vendor_restaurant |> Delivery.list_restaurant_new_orders()
    new_orders_count = Enum.count(orders)

    socket
    |> stream(:orders, orders)
    |> assign(:new_orders_count, new_orders_count)
  end
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.

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"}.

anes

anes

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews