by jchw · 1y ago · 0 comments
I am predominantly not a frontend dev, but when I do do frontend work, (and I don't avoid it by any means,) I have been using React for the past... 10 years now? And while some sentiment has been moving towards Svelte, by the time Svelte overtakes React, it will have been in production for just as long probably. And Angular might eventually run out of steam, but it's been around even longer than React, if you want to count the Angular1 and Angular2+ days together. So honestly I think this is out-of-date logic. While frontend dev moves fast, it really isn't that bad. Pick boring choices and you get boring results.
I think this is true but also misses some aspects. Take Angular as an example. Angular1 and 2 cannot be compared at all, they were basically nothing alike except for the name. This burned many developers. But Angular itself is also changing quite drastically. Not as severe as with the shift from v1 to Angular2, but still severely enough that it would require some major re-adjusting. Everything is moving to standalone components, new template syntax, signals, etc.
Similar things can be said about React. React hat a major paradigm shift with the advent of functional components and hooks. They were compatible, but very different from another.
And the same thing kind of applies for less specific paradigms. First everything was SSR, then we went full steam into Single Page Apps only to return back to SSR but only partial SSR with Hydration, etc.
Angular took a while longer to become more stable. React considered all of its early releases to be 0.x releases, until (I believe) 0.14 -> 15.0, at which point I'd certainly consider React fairly stable. Angular, meanwhile, was kinda unstable until I'd say around v4. Which to be honest, was still a while ago (Google says 2017) but it does bear mentioning.
> React hat a major paradigm shift with the advent of functional components and hooks. They were compatible, but very different from another.
The thing is, functional components are not new. They were a part of React 10 years ago, before React was formally considered stable. I do think hooks came a bit later, but it wasn't that much later. I know that many early React clones supported stateless functional components pretty early on.
And yes, compatibility is key. You can continue to use class components indefinitely. I don't think they have any plans to deprecate them any time soon.
It's still small incompatibilities adding up. It's still work.
If you keep your dependency list short and make boring choices, your app may not still build with modern dependencies after 10 years of neglect. However, it will almost certainly not need to be entirely rewritten, either.
I think learning the fundamentals is good and people should learn to acquire less dependencies, but going as far as to say you may as well not use a framework because it will be gone in five years... I think that is hyperbolic.
8 years ago create-react-app was new and Next.js v2 was on webpack 3. The former is now obsolete and Next is radically different. And hooks released in 2019
It's so simple to work with. Built a simple stock allocation app and what surprised me most was the bundle size... 9kb (gzip). That's better than any other framework I am aware of. That's even smaller than htmx which is somewhat "anti-js"
Likewise, there haven't really been any major API changes in React lately either, but if you want it to be automated, they ship react-codemods which will handle a surprising amount of edge cases for you when upgrading.
If you're going to choose third party packages for something, at least vet that they have good support, are backed by a developer or entity that has been around for a while, and that the library itself is sufficiently mature.
I think the strong focus on backwards compatibility is what helped ClojureScript (and CLJS libraries we used) stay largely unchanged, but we had plenty of "React code" that wasn't changed at all between 2013 and 2022 since it met business requirements and "just worked".
Unfortunately, I don't work there anymore, but I don't see why it'd be impossible to build the early version of that frontend today. Recently, I've been using TypeScript for frontend, and the codebase is still surviving major upgrades to React, TypeScript, and the various libraries we use.
However, I will admit that the pace at which libraries release is extremely fast compared to other ecosystems I'm familiar with (Clojure, Java, Rust, etc.).
As far as a React program from 2015, the maintenance required to get it working in modern React probably wouldn't be all that bad. The biggest transition in React's existence was the move from createClass to ECMAScript 2015 classes. React predates the existence of ECMAScript 2015 classes, having been released in 2013, but once they were available React 13 (2015) they were pretty quickly adopted for reasons obvious. So I'd expect a project from 10 years ago to probably still be using ECMAScript 2015 classes. If not, that transition is mostly mechanical. Definitely a few other potential compatibility breaks over the years, but they're all documented. None of them are going to require a full application rewrite.
Can you build a project from 10 years ago, using 10 year old React? Well, yeah, if you want to. You'll need to use an old version of Node.js most likely, but npm still has all of the old packages.
I also do frontend as my day job, and it's extremely hard to get any old react project to work with current tooling. The migration work basically amounts to a total rewrite and that's the issue with react.
Sure if you were using just react that is okay, but how many frontend projects are JUST using react? The issue with react has always been the community surrounding it. Library recommendations that use to be "best practices" get churned into the next thing marketers want to push.
It's very wasteful in our community because we are just tilting at windmills rather than focusing on the harder problems we have to collectively sell. We should start shunning tools that enable this churn, not all frontend communities are like this either but the popular ones seem to be.
Go is a great example. Once Go hit 1.0, it gained very strong compatibility guarantees. Go has two properties that make it much better in terms of ecosystem stability than JS was:
- The Go standard library. For a long time JS lacked very basic functionality in its standard library. Go has a very nice standard library that not only covers essential algorithms and data structures, but also standard I/O interfaces, implementations of popular protocols and file formats, and a full cryptography suite. 10 years ago, JavaScript lacked much of this, so you often had to "roll your own". Today JS has standard modules, WebCrypto, the File System API, IndexedDB, bigint, ES Maps and Sets, and more. The problem is much alleviated.
- Go has an ethos of minimal dependencies, a la the famous Go proverb, "A little copying is better than a little dependency." JavaScript had virtually the opposite attitude; they were pushing for making every small thing a module. This was a terrible idea, and it has led to the unfortunate reality that your dependency trees in Node.JS grow uncontrollably. This has been somewhat alleviated, though there are still many projects with out-of-control module trees.
Mind you also, that React prior to v15 was also considered pre-1.0; the last relatively big transition (to ES classes) happened in v13, which was actually v0.13 at the time.
But come on. The quote I took issue with was:
> Whatever framework you choose will be obsolete in 5 years.
This is an exaggeration. Undoutedly the JS ecosystem is not as stable as the Go one, but I don't think dropping all frameworks because the ecosystem moves kind of fast is the right answer. There's a measure in the middle.
Webpack existed 10 years ago, and that was after Browserify had already existed for a bit, too. The era of bundling was already in full swing in 2015, and React gained support for ES Classes, too.
React wasn't really terribly usable without bundling. Prior to bundling, there were multiple competing adhoc module systems, but obviously this wasn't fantastic for a variety of reasons. AngularJS 1.0 was great in part because the dependency injection system kind of took care of a lot of trouble; you could have a workflow in Gulp/Grunt concatting your JS together, and the order didn't really matter a ton since dependency injection would largely handle it.
React moved relatively quickly in the first few years, but 10 years ago was already not the very beginning of React. It was starting to mature by that point.
Luck played a role, but if you were well versed in the ecosystem at the time (read: worked professionally in more than one framework), the others all had well known trajectories, limitations, or issues. Angular was just fine; Knockout was eaten by Angular. Ember was way too rigid and magical. jQuery was great but not a framework, more like a lodash. Backbone was really cool but incomplete and didn't help enough. In a way its the best one to compare too, because React was also minimal, but not incomplete - instead the part it did, it did better than you would on your own, then let you do whatever you want with everything else - I think they marked as "The V in MVC" at the time. It was both really powerful, simple, and easy to pick up especially if you were using a lot of jQuery or vanilla js at the time. Its the only one since jQuery that felt like it was simply adding useful stuff, and not taking anything away; I wasn't at all surprised to see it stick as well as jQuery, and for the others to fade. You'd be lucky to outright choose it out of ignorance.
React had that which I believe is the reason why they won. There are other "better" iteration after that but they don't inherently solve a big problem.