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

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 14206 119
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_orde...
New
RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 12673 134
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
sbs
Only 650 LOC, wrote for fun :slight_smile: https://github.com/sunboshan/qrcode
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
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
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

We're in Beta

About us Mission Statement