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
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
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/2in favor ofstash/1. Assigns that should be persisted must now be declared directly in theusemacro 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
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.
Popular in Announcing
Other popular topics
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









