LiveView/Phoenix, HTTP/WebSocket - differences and problems?

Does anyone here know of, or did any sort of experimentation or thinking in terms of either improving or building upon or writing an alternative to how LiveView and Phoenix work together?

In particular, I was wondering if someone looked at the problems of:

  1. Two separate APIs, dealing with two separate types of connections (HTTP vs WebSocket, conn vs. socket) and an attempt to unify it? Like, if I want to read or set a HTTP cookie from LV, or when I want to pass data from Plug world to LV world.

  2. Getting rid of the double rendering (and thus double data loading) behavior on mount (connected vs. not connected)?

Also, do you know of frameworks in other languages, that do similar things that LiveView does, but maybe handle the mentioned cases better in some way? If so, what are the trade-offs?

I know of Hotwire and Laravel LiveWire, but they may be others.

Would HTTP/2 HTTP/3 offer a chance to build something that does not have to deal with two different realms - one stateless and another stateful?

[EDIT]: I had a chat with AI that was quite enlightening to me. I think what I would like to have could be built using something like RabbitMQ or Kafka or Redis, but that would be an additional - and quite complex - dependency.

1 Like

This is two fold. Part of that is about the difference in security considerations between http requests and websocket requests – those can’t go away. The other is that phoenix used to not abstract websocket connection up until 1.7. @mtrudel did create and add the WebSock abstraction, so nowadays websocket connections start out like any other http/plug request up until they’re upgraded. Phoenix socket macro afaik doesn’t make use of that newly available capability yet though. This could consolidate a bunch of things.

That’s simply not possible. A browser cannot make a websocket request when you enter an url into the address bar. It makes a http request and websocket requests can only be started from JS.

But see Allow LiveViews to be adopted · Issue #3551 · phoenixframework/phoenix_live_view · GitHub on the topic of optimizing where it might be possible

4 Likes

Oh this is very interesting that this coversation is just now being had.