On the Utility of Phoenix LiveView
jclem.net
jclem.net
My biggest complaint is that if your server restarts for any reason (say, a rolling restart), you currently lose all state that was on the server[0]. There appears to be some kind of workaround for forms currently, but for anything more complex, I would need to write JS in order to attempt to not have my page get reset to the default view. So if I need to write JS already, I may as well just write JS (or something that transpiles or JS/WASM) to have fewer moving parts.
[0] https://elixirforum.com/t/liveview-and-rolling-restarts/2397...
We are going to formalize the idea of a "stash" to send back up client state on reconnect, which would remove the need for this JS entirely. It is also worth noting that if someone packaged up that 20 line gist into a JS package, your application or anyone else could do `<form ... phx-hook="SavedForm">`, so "need to write JS anyway so might as well write a JS app" isn't quite accurate because it's a tiny escape hatch that doesn't require throwing away or rewriting any feature. Writing 20 lines of JS to keep shipping LV features is much different than rewriting an entire application in JS. I would actually argue the fact you have the escape hatch in this scenario is one of the merits of the library. Anyways, I hope we can keep you around once other features continue to land :)
For what it's worth, I very much appreciate the work you and everyone involved has done for LV (and more generally, Phoenix).
Secondly, has there been any discussion for supporting server side draining or moving the process to another node?
For some stuff this will matter (the test was a game, which isn't what I'd use LiveView for in production), but for others, where data has to go to the server anyhow- the delay is there, even if my nice JS frontend disguises how long it takes.
I'd like to think Edge Compute could be used.
At the end of the day we're up against the speed of light and our options are limited.
My last "problem" is less of a problem with LV and more of a contraint of my system. I cannot guarantee that everyone using this application will have network access 100% of the time. So for a certain subset of my users, LV would not be ideal.
The author, Caleb Porzio (https://calebporzio.com/), was inspired by Phoenix LiveView to build something something like this for his preferred language/framework.
> 4. PHP re-renders the Blade template and sends back the HTML
I’m curious if it does serverside diffing too. From the LiveView talks it sounds like it sends tiny diffs across the wire rather than a lot of html each time.
On his blog, he posted some videos earlier this year about the process of coming up with what eventually became Livewire, as well as a bunch of discussion on his podcast No Plans To Merge.
Has anybody with lots of React experience made that switch? How is it going?
Plus, it’s fast. Rather it feels faster than it should be. Perhaps since instead of waiting for JS to retrieve data, parse it, and render, and then update, you just need the JS to update the DOM once the data arrives. Of course my vue pages were using REST endpoints for data so perhaps a websocketed vue page would feel more responsive.
LiveView still has a bit of maturing to do, but I’m really enjoying it. I’m really bullish that writing dashboards, admin pages, internal corporate tools can all be done an order of magnitude easier with LiveView or similar while still scaling decently.
Soon we're starting another project, and we'll go with Phoenix (which we're already using as a backend and GraphQL server) with LiveView sprinkled here and there where we need better interactivity.
A small thread including my own experience here: https://twitter.com/dmitriid/status/1153586545426862080 It’s fairly obvious, but is worth mentioning.
- because LiveViews are stateful, we don't have to refetch/reload the state we need on every "request". Things like current_user, current organization, preferences, etc. So what we lose in memory load, we gain in reduced DB and system load, caching strategies, etc
- because LiveViews are stateful with change-tracking, we actually can send less data than the best hand-written SPA/JSON application you could write. So what we lose in memory load, we gain in reduced latency and overall data on the wire.
Direct link to data-on-the-wire example from my keynote for those curious: https://youtu.be/txk4WAlabvI?t=873
Let's say in a chat app with a Redux setup I'd maintain channel users, messages, own profile details etc. in the app's own local state. With LiveView I'd only need to store the user specific stuff in this user's own state. Some of which I'd store in the socket.assigns of Phoenix Channels subscriptions even now with a conventional Redux setup.
It’s parsing the entire Markdown content on each key press right now, which is definitely suboptimal for a product but fine for my needs.
It should certainly be possible to make this more efficient by either doing some smarter diffing of the in-progress document or using an operation-based update mechanism.
LiveView doesn’t yet have event debouncing built in, but it’s in the works, I believe, and that would help, as well.
That said, it’s currently fast enough writing a post of this length that while writing, I notice no significant lag in the live updates. By the time I stop typing and look at the preview, it’s up to date.
Using LiveView, of course, requires taking round trip latency for your users into account. It currently won’t work well for some use cases where optimistic UI updates may help hide some latency. I think I read something about there being some optimistic updating in the works for LiveView, though, long-term, but I’m not sure how it’ll be done.