DEV Community

What is the Virtual DOM? (Let's build it!)

Siddharth on June 02, 2021

You might have heard of the Virtual DOM (and also the Shadow DOM). You may have even used it (JSX is basically sugar for the VDOM). If you want to ...
Collapse
 
alimansoorcreate profile image
Syed Ali Mansoor

This is such a great article! I had trouble understanding the VDOM but you made it really clear and simple to follow. Looking forward to the next part! ✌️

Collapse
 
siddharthshyniben profile image
Siddharth

Thanks! The next part might come out in 2 days

Collapse
 
sargalias profile image
Spyros Argalias

Hey, I enjoyed the article. I also agree with the points you raised. Thanks for the good content :).

Nevertheless, I just want to point some things out that I feel are minor issues in the article.

In the first snippet of code presented. The tests don't seem fair. For the object, i is being set every time, not appended to. However, for innerHTML, i is being appended. This makes the measurement far slower. This is both because of layout thrashing, but also because the resulting string is huge (2,890 digits long). However, the main point still applies. When I tested just setting the value innerHTML, it was about 20 times slower than the operation on the object.

Also, the code snippet with the function generateList doesn't seem to work. I tried created sufficient HTML for it to run, but got a few errors.

Anyway, I still enjoyed the article overall. Keep it up :).

Collapse
 
siddharthshyniben profile image
Siddharth

I was just looking for a quick and easy way to show you stuff and I didn't actually take the time to test it too much. Thanks for pointing those out!

Collapse
 
sargalias profile image
Spyros Argalias

Yeah I gotcha. That's all good, as I said I still think it's a great article :). Yeah I was nitpicking a bit because I like actually running through the examples for more clarity :)

Thread Thread
 
siddharthshyniben profile image
Siddharth

Me too, but not on my articles 😂

Collapse
 
rajatetc profile image
Rajat Gupta

Very insightful! Waiting for the next part.

Collapse
 
siddharthshyniben profile image
Siddharth

Thanks! The next part might come out in 2 days or maybe tomorrow

Collapse
 
siddharthshyniben profile image
Siddharth

Look at these reactions, I am absolutely mind blown("!".repeat(Number.MAX_SAFE_INTEGER))

(I could do that forever)

Collapse
 
madza profile image
Madza

How do you like Svelte's aproach, avoiding it entirely? 👀

Collapse
 
chrisczopp profile image
chris-czopp

Yeah, Solid also uses build-time DOM diffing so we have at least two projects which prove it can be done. I think Virtual DOM did loads of good for the industry like popularised declarative UI development. However, if the runtime housekeeping like DOM diffing can be done at build-time, then I think it's no-brainer to consider these tools.

Collapse
 
madza profile image
Madza

Good take 👍

Collapse
 
siddharthshyniben profile image
Siddharth • Edited

I've never got the time to check it out, but I will in the (I hope) near future.

Update: WOW! Svelte has got a really good idea.

Collapse
 
profesorval profile image
Aaron Professorval

Great article!

Collapse
 
timhuang profile image
Timothy Huang

Performance is important. Thank you.

Collapse
 
siddharthshyniben profile image
Siddharth

The second part is out! (Was out earlier but I forgot to make it a series 😅)