dmitriid

dmitriid

Stream_insert removes all items from stream

I have a weird issue that I cannot figure out:

I have a basic setup where on mount I retrieve items, and add them to the stream:

    case Event.all_events() do
      {:ok, events} ->
        {:ok,
         socket
         |> stream_configure(:events, dom_id: &"event-#{&1.id}")
         |> stream(:events, events)}

      {:error, _} ->
        {:ok, handle_forbidden_error(socket)}
    end

I’m also subscribed to a PubSub, so when an event is updated, I insert/update it into stream:

  def handle_info(%{topic: "event:updated:status", payload: %{data: data}}, socket) do
    user = socket.assigns.current_user

    case data.user_id == user.id or user.role == "admin" do
      true ->
        {:noreply,
         socket
         |> stream_insert(:events, data, at: 0)}

      false ->
        {:noreply, socket}
    end
  end

For some reason, when I insert the item, all items from the stream disappear, and only this one item is added. If the item already exists on the page, same thing: all items are removed, the item is updated (or a new one is inserted?).

Doesn’t matter if I use at: N or not.

Edit:

Versions:

      {:phoenix_live_view, "~> 1.0"},

      {:phoenix, "~> 1.7.10"},
      {:phoenix_ecto, "~> 4.5"},
      {:ecto_sql, "~> 3.12"},
      {:ecto, "~> 3.12"},

Marked As Solved

t0t0

t0t0

Hi,

do you have phx-update="stream" on the parent HTML tag in your template?

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New

We're in Beta

About us Mission Statement