kraleppa

kraleppa

LiveStash - persisting LiveView state across WebSocket reconnections

Hi everyone,

We’ve just released LiveStash, a library designed to handle the issue of losing Phoenix LiveView state during WebSocket reconnects.

LiveStash was created to fill the gap between URL parameters and full database persistence. It allows you to “stash” specific assigns and recover them automatically when the user reconnects.

The library currently supports two strategies:

  • ETS Adapter: Keeps the state on the server for minimal network overhead.
  • Browser Memory: Offloads the state to the client, allowing it to survive full server redeploys.

We go into more detail regarding the technical implementation and the distributed systems challenges in our blog post here: The Problem of Reconnects in Phoenix LiveView

Check out the demo and our repo - we’d love to hear your thoughts!
GitHub:

https://github.com/software-mansion-labs/live-stash

Demo:

Most Liked

kraleppa

kraleppa

Hi everyone,

We just released v0.3.0 of LiveStash. This update brings two heavy-lifting features for distributed apps and better DX:

  • Redis Adapter: State lives securely in Redis, while the browser only holds a lightweight reference.
  • Opt-in Automatic Stashing: LiveStash detects changes in stashed assigns and updates them automatically (no need for explicit stash/1 calls anymore).

If you have any questions feel free to reply here, create an issue, or start a new thread on GitHub discussions.

wegorz13

wegorz13

Hi everyone,

I’m happy to share that today we released LiveStash v0.2.0!

We took your feedback to heart and we’re excited to introduce the suggested improvements. This version introduces breaking changes to our main stash API, with the goal of making it simpler, more declarative, and more fault-tolerant.

Here is what is new and changed in v0.2.0:

  • Declarative assigns API (Breaking): We removed stash_assigns/2 in favor of stash/1. Assigns that should be persisted must now be declared directly in the use macro options.

  • TTL unit update (Breaking): Changed the TTL configuration to use seconds instead of milliseconds.

  • Configuration validation: We added validation for user config to improve API correctness and fail fast on invalid inputs.

If you have any questions, ideas, or bug reports, feel free to reply here, create an issue, or start a new thread on GitHub discussions. Let us know how the new API feels!

derek-zhou

derek-zhou

I’ve tried something similar before, however, I am concerned that there could be possible race condition between save and restore, thus perpetual a corrupt state. The client could reconnect so fast, and spin up a new Liveview process before the old one was killed. So, for a brief moment, you could have 2 LV processes, representing the same session, even from the same browser tab.

Where Next?

Popular in Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
mattludwigs
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 10954 107
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement