deadego
Trying to drop a specific stream from a socket in LV via.
{_, socket} =
pop_in(socket.assigns.streams[filter_string])
{_, socket} =
pop_in(socket.assigns.streams.__configured__[filter_string])
{:noreply, socket}
But get
[error] GenServer #PID<0.1919.0> terminating
** (KeyError) key "test" not found in: %{__changed__: MapSet.new([]), __configured__: %{}, __ref__: 1}
:erlang.map_get("test", %{__changed__: MapSet.new([]), __configured__: %{}, __ref__: 1})
(elixir 1.18.3) lib/map.ex:318: Map.update!/3
(phoenix_live_view 1.0.9) lib/phoenix_component.ex:1447: Phoenix.Component.update/3
(phoenix_live_view 1.0.9) lib/phoenix_live_view/lifecycle.ex:223: anonymous fn/2 in Phoenix.LiveView.Lifecycle.after_render/1
(phoenix_live_view 1.0.9) lib/phoenix_live_view/lifecycle.ex:237: Phoenix.LiveView.Lifecycle.reduce_socket/3
(phoenix_live_view 1.0.9) lib/phoenix_live_view/lifecycle.ex:222: Phoenix.LiveView.Lifecycle.after_render/1
(phoenix_live_view 1.0.9) lib/phoenix_live_view/channel.ex:992: anonymous fn/4 in Phoenix.LiveView.Channel.render_diff/3
(telemetry 1.3.0) /home/dead/Dev/gale/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
(phoenix_live_view 1.0.9) lib/phoenix_live_view/channel.ex:983: Phoenix.LiveView.Channel.render_diff/3
(phoenix_live_view 1.0.9) lib/phoenix_live_view/channel.ex:819: Phoenix.LiveView.Channel.handle_changed/4
(stdlib 6.2.2) gen_server.erl:2345: :gen_server.try_handle_info/3
(stdlib 6.2.2) gen_server.erl:2433: :gen_server.handle_msg/6
(stdlib 6.2.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Message{topic: "lv:phx-GDKJG9wvY7sfv3iB", event: "event", payload: %{"event" => "delete_filter", "type" => "click", "value" => %{"filter" => "test"}}, ref: "17", join_ref: "4"}
State: %{socket: #Phoenix.LiveView.Socket<id: "phx-GDKJG9wvY7sfv3iB", endpoint: GaleWeb.Endpoint, view: GaleWeb.HomePageLive, parent_pid: nil, root_pid: #PID<0.1919.0>, router: GaleWeb.Router, assigns: %{filters: ["test"], __changed__: %{}, current_user: #Gale.Users.User<__meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: "f08b5683-2009-4b58-8a09-105e2fddb5d0", email: "asdf@asdf.com", confirmed_at: nil, inserted_at: ~U[2025-04-01 01:47:38Z], updated_at: ~U[2025-04-01 01:47:38Z], ...>, flash: %{}, filter_form: %Phoenix.HTML.Form{source: #Ecto.Changeset<action: nil, changes: %{}, errors: [], data: %{}, valid?: true, ...>, impl: Phoenix.HTML.FormData.Ecto.Changeset, id: "form", name: "form", data: %{}, action: nil, hidden: [], params: %{}, errors: [], options: [method: "post"], index: nil}, streams: %{:__changed__ => MapSet.new([]), :__configured__ => %{"test" => [dom_id: #Function<0.13511000/1 in GaleWeb.HomePageLive.handle_event/3>]}, :__ref__ => 1, "test" => %Phoenix.LiveView.LiveStream{name: "test", dom_id: #Function<0.13511000/1 in GaleWeb.HomePageLive.handle_event/3>, ref: "0", inserts: [], deletes: [], reset?: false, consumable?: false}}, live_action: :home}, transport_pid: #PID<0.1908.0>, ...>, components: {%{}, %{}, 1}, topic: "lv:phx-GDKJG9wvY7sfv3iB", serializer: Phoenix.Socket.V2.JSONSerializer, join_ref: "4", redirect_count: 0, upload_names: %{}, upload_pids: %{}}
[
I assume there is a better way?
Trending in Questions
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
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
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
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
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Maybe like this?
But I don’t really understand what You are doing with your pop_in…
deadego
https://github.com/deadego/gale/blob/main/lib/gale_web/live/home_page_live.ex#L19-L38
This will give you a better idea of what I’m dealing with.
In short I would like to remove the condition from having to check if it already had a prior stream with that key since the prior config will cry if I try to do it twice but also. Removing the stream vs just emptying it.
garrison
I don’t think streams are meant to be used dynamically like this. The docs for stream_configure/3 specifically suggest calling it in
mount/2(i.e. statically).What is the use case here? That is to say, what are the items in the streams?
deadego
this is the site https://gale.deadegos.org/
As you can see I build up filters of the bluesky jetstream feed.
I want to add remove them as I want.
Currently this works. though leaves a little cruft left over from “deleted” streams
I guess I could consolidate to one stream and just manage the one.
deadego
also I think the only reason it states that in the docs to put the config in mount is because it will error if you try to config twice, thus you will need a condition
garrison
I see, I often caution people about over-using streams but this is about as good a use-case as I can think of
From what I can tell the cause of the error you’re getting is that
assigns.streams[name]is only populated when you actually callstream/4, if I had to guess probably only within that render before it’s cleared. While the key inassigns.streams.__configured__, I assume, lasts the duration of the LiveView.I think (I did not bother to test) that
pop_in/1does not handle the missing key, butpop_in/2does. There is some language in the docs forpop_in/1suggesting the “complete path must be visible to the macro”.Does this work?
I was just using that line from the docs to demonstrate that the streams APIs are not meant to be used dynamically. Obviously you technically can, as you have demonstrated, but there is no API to clean up the dangling streams (as you have discovered).
BTW, even if you remove the stream from the server correctly there will still be some accounting left on the client to handle the streams, and if you re-use a name I would imagine you could break something in a weird way.
Consider making a feature request for better dynamic functionality.
garrison
Another approach: you could instead make a “pool” of streams (configured in
mount/2) and then dynamically assign filters to them, resetting them when the filter changes. I think this would work fine because obviously there are only so many streams you can display at once on a screen anyway.deadego
Yeah this is what I meant by consolidating to just a single long lived stream.
IE multi dimensional list
garrison
What I mean is you can allocate multiple streams, like:
And then update
:filterswhen filters are added/removed, resetting the streams as needed.By pooling the streams and re-using them you are working around the lack of delete functionality.
deadego
yeah we are saying the same thing.
Though I fear this may has a unexpected side effect