And that's it!
This requires a bit more work than the
localStorage version, but it feels more elegant to me.
Instead of rendering a page with empty session data and re-rendering it when we've loaded the data from the client, we've got the data from the very first render – even the static render that LiveView does before establishing a websocket and doing updates over the wire.
Using a database like this is conceptually very similar to having a database-backed session store, but LiveView accesses this store outside the HTTP request/response cycle. I suspect changing Phoenix to a database-backed session store and then accessing that from LiveView would be more complex than this solution, but I'd love to see it.
I'm still very new to LiveView and would love feedback and alternative solutions. Please write a comment below or on Twitter!