tmbb
I’ve been looking at the possibility of implementing a server-side VDOM (Virtual Dom, like Reactjs, Vuejs, Snabbdom and onthers). The problem I see with this is the high latency of the updates, and the way it interacts with input components. Suppose you have a VDOM that returns the following (using vue-style templates):
Enter your name: <input v-model="name"></input>
<br/>
<span>Hello {{ name }}!</span>
The UI should be updated as the user types (probably debounding events, but that doesn’t change the main point).
Suppose the user types a “My Name”. The event is sent to the server, which sends the minimum delta so that the browser’s DOM is changed. But suppose now that before receiving the update, the user types “Another Name”. This can happen because latency between client and server can be arbitrarily high…
You’ll have something like this:
- User requests a page. The server sends a DOM with
name = "" - User types “My name”. The server receives an event. The server sends a new DOM with
name = "My Name" - The user types “Another Name”
- The user receives a new DOM with
name = "My Name", which overwrites the text in the input component. This is a very surprising UI change - The server receives
name = "Another Name" - The UI changes back to the previous version.
I don’t think how one can avoid this. There is a serious mismatch that will keep the client and server permanently out of sync. Althout I’ve often felt that a VDOM was superior to the approach taken by Drab (which has the concept of living assigns, and instead of re-rendering everything and diffing the result updates parts of templates that correspond to specific mutations), now I’m not so sure, because of the way the network latency messes with the input components’ updates…
I’m not aware of any widely used server-side VDOM, so I don’t know if anyone has managed to find a way around this limitation.
Trending in Discussions
Other Trending Topics
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 18 Posts
LostKobrakai
Why do you want to handle user input live on the server? The only common case I can see using something like that would be live search results.
voughtdq
What about this:
C:
{ref: "xz723", name: "My Name"}C:
{ref: "v44ns", name: "Another Name"}S:
{ref: "xz723", domNode({name: "My Name"})}C: I’m ignoring that, my ref is
"v44ns"Or even
C: I’m ignoring that, did you see what I just sent you?
{ref: "v44ns", name: "Another Name"}tmbb
I can think of other cases, such as realtime validation of form parameters, password strength checking, etc.
But these limitations apply even without “realtime” handling of keystrokes. Just suppose you type the name, press a save button and then type another name before you receive the reply from the server.
The input componenet will still revert to the previous state for a while (and then revert back)
peerreynders
This really sounds more like something RxJS is used for:
Ultimately a server-based VDOM is just way too chatty - too many, too finely grained updates need to be exchanged between the server and browser.
tmbb
That might actually work. It sounds like a very limited form of Operational Transformation that might be useful in practice
OvermindDL1
Drab is already halfway to that, it creates a pre-processed virtual dom for fast updates later. ^.^;
However, as for the latency Drab generally just disables what is being waited on until it completes (configurable of course).
tmbb
Drab seems to use “mutation watchers” which try very hard to rerender only the UI parts that depend on values that have changed.
This is very different from a VDOM in reactjs or the elm architecture in which the engine renders a new dom and diffs t against the previous one.
I don’t think you can get from Drab to a VDOM incrementally, because those are very different concepts.
OvermindDL1
Those watchers are how a vdom diff works anyway (it’s certainly how my super-fast-yet-not-optimized bucklescript-tea vdom diff’s anyway). There are lots of ways to implement vdom’s, React’s broken way is not the only way. ^.^
tmbb
I think that the problem here is latency alone, not chatinness. You can be as chatty as you want as long as you can output a DOM diff between two user events (in the limit, between 2 keystrokes). That guarantees that you’l never rever input components to the last update (because you’ll be setting the component’s input yo the value it already has).
That’s doable with local Javascript, but it’s not doable over the network.
tmbb
Does your approach with mutation watchers work with general render functions?