Virtual DOM and me

It’s complicated

I have mixed feelings about virtual DOM. I get it: it’s cool, it’s different, it’s everywhere, it’s pure, it’s hipster. Thing is it’s not how the DOM works and that’s the issue for me.

You see, DOM is mutable. If you want to have static layouts and switch between them virtual DOM is ok. That’s just not enough for me. I started with Flash in 1999 and I like interactions, animations, tailor-made components and nice little details. I also want to control what’s happening, when and how. Virtual DOM doesn’t let me do all that the way I want. It gets in the way.

When you want to have some 3rd party component like Google Maps, things get even more complicated. You need some 4th party dependency to handle virtual DOM to mutable DOM conversion. Or be mutable and save the reference to the component, cross fingers and hope virtual DOM doesn’t mess things up.

Also to prevent virtual DOM doing extra work, you need keys everywhere. In the mutable world you don’t need them, because things stay where you put them. And for example by saving references to a lookup table you can reorder really easily. You can even control which parts of the component are static and which not. With virtual DOM you need to do it with a hack (shouldComponentUpdate or whatever).

What if you want to have a fadeout animation? What if another update comes before the transition ends? How would virtual DOM know where to put that element between the states? Yes, again there’s 3rd party dependencies, but you’ll end up with fatigue after some dozen of them. And if you want to have something more customized, you’re screwed. You don’t need to think those kind of things with the mutable DOM.

You can even make pure updates with the mutable DOM if you want. Check out my tiny UI library RE:DOM for example. It doesn’t use virtual DOM. Still it’s super fast, easy to use and you can always rerender components if you want, but separate which parts are static and which dynamic. You can even use RE:DOM in the server, with NO:DOM.

Virtual DOM might work for some, but it’s not for me. There, I’ve said it.