tmbb

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:

  1. User requests a page. The server sends a DOM with name = ""
  2. User types “My name”. The server receives an event. The server sends a new DOM with name = "My Name"
  3. The user types “Another Name”
  4. 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
  5. The server receives name = "Another Name"
  6. 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.

First 10 of 18 Posts Switch mode

LostKobrakai

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

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

tmbb OP

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

peerreynders

This really sounds more like something RxJS is used for:

  • Whenever input changes, reset client side UI rendering to reflect that data has not been validated.
  • As input state changes, dispatch validation requests to the server.
  • Upon validation response the client verifies that the validated data matches the current input data (client based correlation id would be faster) - and only when it matches, the UI renders client side with validation errors or success.

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

tmbb OP

That might actually work. It sounds like a very limited form of Operational Transformation that might be useful in practice

OvermindDL1

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

tmbb OP

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

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

tmbb OP

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

tmbb OP

Does your approach with mutation watchers work with general render functions?

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
mudasobwa
While I am working on the Language Agnostic Code Audit SaaS, which uses MetaAST (spoiler: I am expecting it to be in a good shape for ann...
New

We're in Beta

About us Mission Statement