React Developer Experience Revisited

The React developer experience is better, but it's still not good

I'm returning to the world of React development after a hiatus of several years. When I last did any serious React development, hooks were the shiny new thing on the block and now they've well-and-truly set in.

The good news is that hooks seem to have replaced redux as the state management approach du jour, which means that how state gets from x to y is at least borderline comprehensible, but the down side is that the virtual DOM hierarchy, which was already pretty terrible, has gotten crazy.

this is the React website home page viewed in the React dev tools

The preceding image is of the React home page with React Dev Tools open. The arrow shows the SelectionProvider wrapped around the top-left-most widget on the screen.

I picked this because (a) it's not my employer's highly confidential code and (b) I wouldn't want to be accused of cherry-picking a particularly gnarly piece of code written by non-genius-level-React-engineers.

So this is the code that the React team chooses to show off to the world and it's a page which doesn't do a whole heck of a lot.

Each of those things in the virtual DOM represents code that someone has to write, test, and maintain. And when they maintain that code they have to find, read, and grok the code around it. When you look at this, you're looking at wasted development effort up-front and compounded into the future.

this blog in the elements panel

Above, by comparison, is this blog displayed in the elements panel. There's no virtual DOM because with xinjs the DOM is the DOM is the DOM.

I don't know how long hooks-based apps last. In my experience Redux-based apps become incomprehensible to maintainers within three years. Maybe hooks apps last a bit longer.

Navigating a Codebase

One of the problems with React development has always been a high noise-to-signal ratio in developer tools. E.g. in the debugger you tend to discover your functions are deeply nested in anonymous wrappers that do things I for one don't understand. (But hey, at least it's not Angular, amirite?!)

Similarly, your DOM nodes are wrapped in lots of DOM nodes that tend to do fairly comprehensible things (e.g. I assume a SelectionProvider holds selection state for a widget, which is totally awesome and not something you wouldn't need to bother with if you just used the DOM APIs). So while it's not quite as bad as trying to figure out the execution stack of an event handler it's not ideal that just figuring out where in this huge mess the thing you're pointing at is and then finding your way to the thing you're actually interested in reminds me of trying to find traps and treasure in old school CRPGs by waving the mouse around and waiting for the cursor to flicker.

Generally, when you're trying to fix an issue in the user interface, either you know exactly where the code is or you don't. If you don't you might search for some unusual text in the UI. Failing that you might look for (say) a class-name or a component-name as a clue.

Just look at this garbage (here I can't use the React example because their symbols have been intentionally obfuscated):

material ui select widget partially displayed in React Dev Tools

There is virtually no useful information in this sea of genericity. I find it hilarious that the React Dev Tools hierarchy has minimized the indentation level just to avoid having the hierarchy totally disappear to the right.

And what is it we're looking at here? We're looking at a small part of the language select widget that allows the user to pick the UI language for this app.

xin-locale-picker in the DOM

Last Thursday evening, after seeing a minor problem in the language menu of the app I was working on, I decided to see how hard it would be to implement all of this nicely in xinjs-ui, so I did. The resulting widget is shown in action above.

Now, I haven't fully dislclosed the hierarchy inside this example, because I don't have to. The stuff I disclosed in React Dev Tools was the bare minimum needed to find what I was looking for.

But the code is nice, right?

No. No it isn't. The elements you're seeing in the xinjs-ui example directly map onto the code that creates them:

fooBar(bazLurhmann())

Generates:

<foo-bar>
  <baz-luhrmann></baz-luhrmann>
</foo-bar>

When I try to find the source code for Locale it's helpfully in one of god-knows-how-many files named index.tsx.

We already know that xinjs lets you write dramatically more compact code than React, but that if you want to code in React then react-xinjs lets you write more compact and maintainable code than React does (by making hooks far more powerful). But I hadn't seen this effect compounded exponentially in mature production code.

As I am quite fond of saying, I've never known something that is complex for simple cases become simple for complex cases. There are some examples in Math, e.g. using log tables to do multiplication and division, but it's very easy to demonstrate the simplification.

Back in the glory days of redux, I once spent two days trying to fix a typo in a user-interface, with considerable help from members of the five-person team that was responsible for the app. Sure, it's tough getting up to speed on a new code-base, but I never actually fixed the typo. At least with this codebase I was able to solve the problem in just an hour or so.

So, in my opinion, the React-with-hooks developer experience is better than React-with-redux, but it's still pretty bad.

— Tonio Loewald,