4 ms·
I'm a big Elixir fan, but unfortunately Phoenix is starting to suffer from an overuse of LiveView. LiveView is great, but it's sort of becoming the default way
by el_nahual 3y ago
I'm a big Elixir fan, but unfortunately Phoenix is starting to suffer from an overuse of LiveView.
LiveView is great, but it's sort of becoming the default way to render everything--even static pages! TFA is a good example of this, where they use a Live view to render...a static list of icons.
The problem with this is twofold:
- LiveView is not free. It seriously affects people with unstable connections, for example. It creates a new class of silent bug at the client/server interface, where the client just sees "broken" pages (instead of 500 pages).
- It adds cognitive overhead. We bloody know how to do server side rendering. We've been doing it for 30 years (!). It's a good model. Don't make me learn something else, please.
Phoenix, which is a jewel of a framework, is risking becoming an "SPA-like" framework, with a new paradigm, and a whole lot of overhead to learn, footguns you've never encountered before, bizarre failure modes, etc.
I mean, TFA even has a section where they talk abut an obscure but that "...is a doozy, so I will save you some hours of debugging."
We don't need this!
One of the things that made Phonix/Elixir great is how simple and opinionated the core team has been. Conventions are Very Strong, but not magic. Unfortunately, LiveView is so cool (it really is!) that no conventions were built around it and it's now used for everything.
IMHO LiveView should be used with a very clear heuristic:
- If the page is static, render a static page.
- If the page is dynamic, and the content changes depending on calculations happening server side, use LiveView. It truly shines here.
- If the page is dynamic, and the content changes depending on actions performed by the client, use JS.
- consoomer 3y agoI see this same issue with htmx and other takes on SSR.. just because you can dynamically update the HTML doesn't mean you should make EVERYTHING dynamic. It's okay to have normal page transitions. It's okay to do something dynamic. It's okay to to toss a little plain ol' JavaScript in there if it's simple.
- sb8244 3y agoI strongly agree with you. I'm fairly involved in Elixir, so I run a risk of catching some frustration for agreeing with you here. I get why they are going the direction they are, but I think it comes at increased complexity for beginners (that don't want to use LiveView). For example, Phoenix components (which are usable in static server-rendered controllers) live in phoenix_live_view package. All of that said, Elixir / Phoenix is the best development experience I've ever had and I have no plans to stop using it.
- anonyfox 3y agoI recently started to only use liveviews for any page. Yes, I could do a simple controller/template combo, but then after some time comes the feature request for some interactivity, and I have to convert the page to LV manually. Or something like the global navbar needs some dynamic thing, and here you go: either embed a LV in the static page or... do nothing since all pages are LV to begin with. The overhead is pretty minimal IMO, a simple LV that does nothing is a few lines of module code, not much more than a controller route. And by standardizing this (no more deadviews), pipelines/plugs can be simplified, and live_session for seamless navigation becomes much better. Phoenix Deadviews render within a few MS, but still a live_navigate is snappier.
- arcanemachiner 3y agoI agree with the GP, but I've definitely been staring down the barrel of this paradigm as well.
- jononomo 3y agoWhat is "TFA", please?
- el_nahual 3y agoInternet-shorthand for The Featured* Article--the webpage/blog post/etc being linked. Sort of like OP, GP, etc.
- zem 3y ago"the fucking article" - the classic acronym RTFM (read the fucking manual) spawned the variant RTFA in the social news era, and then the article itself became TFA by extension.
- arcanemachiner 3y agoIt's like that piece in Fantasia where the apprentice (Mickey) gains the wizard's powers, then loses control as all hell breaks loose. It's a powerful new tool, but there's a time and a place for it, and I believe that the tendency towards LiveView-everywhere should be balanced against pure practicality. I look forward to a future in which the boundaries of the paradigm are more well-understood, and the models of when and how to use these tools are more fleshed-out. Also, I agree with your heuristics. It is untenable to make a round trip to the server for things that can be done purely on the client side. Alpine.js is great for managing purely client-side stuff IMO (as are LV hooks, although I haven't used them too often), but they don't really mix well, and Alpine seems to have fallen out of favor lately with the Phoenix crowd as the complexity of people's projects starts to reveal the cracks in the paradigm. To add to your heuristics, the `phx-loading` attribute should be used when possible to notify the user that 1) yes, you made the action, and 2) we're still waiting for a response.
- Fire-Dragon-DoL 3y ago100% agree, and it's scary. By the way, did something like activeadmin pop up?
- conradfr 3y agoI kind of agree with you, and LiveView is not even 1.0 yet (it should have been before the whole components thing IMHO). I also think they kind of jump the shark with the core_components.ex tied to Tailwind.