News for hackers. Stuff that matters.
Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @05:35PM (#27169245)
>In my opinion, React made a revolution with hooks and contexts

I agree with your overall point 100%, but to be honest nothing in React was / is innovative except for the virtual DOM diffing, but even that is becoming increasingly irrelevant as apps are moving towards more and more reactive architecture. React made a huge impact on web dev and deservingly so, but all of the other ideas have been implemented and used on the web before.

Of course it's great that React is bringing some of these good ideas to mainstream, but they've been there way before they have been distributed along with a VDOM algo.

Re:Modern Javascript: Everything you missed over the last 10... by madeofpalk on Saturday May 15, 2021 @07:38PM (#27169940)
> nothing in React was / is innovative except for the virtual DOM diffing

Maybe there wasn't much academically innovative in React, but it certainly brought declarative, functional UI programming to the masses. Its innovation was in making that as easy and accessible as possible with a tiny API.

I feel saying React wasn't innovative is so dismissive and ignores the massive paradigm shift that's happened in web development because of it.

Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @07:42PM (#27169959)
100% true.

But I'm not even talking about academic really. There were plenty of people who didn't buy into the "MVC/jQuery/templates" thing, and we were writing apps into production for actual customers. I've never been taught academically, but I realized that writing my DOM operations as declaratively as possible made my code much easier to maintain. So I started creating and updating my DOM in JS way before React, when it was considered "heresy" by people who didn't know better. And there were plenty of programmers like me, who never got academically trained or looking up category theory. They had just shot themselves in the foot with the silly MVC stuff too many times to care anymore about what other programmers think.

For me, and people like me React was a GODSEND. We started immediately hyping it, but there was huge resistance early on to adopt it. React was a great improvement from the status quo. But then later on we realized that people started using it as a framework just like they had with "templates+jquery+backbone+whatever" and although the DOM things are a bit easier now, many people don't understand any better why or how React is good and when it's bad to use...

Re:Modern Javascript: Everything you missed over the last 10... by 8note on Saturday May 15, 2021 @07:52PM (#27170009)
I think the innovation comes from making it easy to do. Its been transformative for how people write UI code as a result

Its innovative in the same way as the iPhone was. All of the concepts existed before, but nobody made them practical and cheap

Re:Modern Javascript: Everything you missed over the last 10... by miralize on Saturday May 15, 2021 @09:21PM (#27170411)
On that point, I think the next innovation to come to front end development is to declaratively think about states using finite state machines & statecharts.

A concept that also has existed before, but with XState, I think a lot of developers will latch onto this paradigm.

The ability to think or plan a feature/apps states in the beginning rather than imperitavely or as an afterthought during development is really valuable. And perhaps if we're dealing with something more visual at the beginning, its easier to demonstrate what will happen if I click "X". and then it becomes easier to spec out & to involve PMs/designers and QA.

Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @07:59PM (#27170046)
I suppose. It just feels weird that the post was highlighting hooks and context, while VDOM was omitted. VDOM was easily the biggest thing in my opinion. I had never seen anything like it and it worked wonderfully. It's not to say that everything else in React is bad, it's more like everything else pales in comparison to how huge VDOM was when it was introduced.

Kinda like hyping iPhones innovation without ever mentioning touch screens.

Re:Modern Javascript: Everything you missed over the last 10... by Mogzol on Saturday May 15, 2021 @11:58PM (#27171097)
I read it more as talking about a revolution within React. Hooks and context are (relatively) new features that do "revolutionize" how you write components. That's not to say VDOM isn't important, it just isn't anything new, it's been a part of React since the beginning.
Re:Modern Javascript: Everything you missed over the last 10... by madeofpalk on Saturday May 15, 2021 @07:47PM (#27169982)
I'm so confused by what you're saying all over this thread, apart from "React is something that exists, and I modified the DOM before it existed". Okay?
Re:Modern Javascript: Everything you missed over the last 10... by varrock on Sunday May 16, 2021 @02:42AM (#27171710)
> many people don't understand any better why or how React is good and when it's bad to use...

Your comment was very insightful, but I feel like you've left me on a cliffhanger. I'm someone who got into the industry right when React was reaching enterprise levels, so I missed out on what came before it. I got my job, was told to learn React, and have gone from there.

Is there any way you might be able to expand on the problems you were solving with your declarative approach, why it was useful, and how you think React should be used in modern day web development?

Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @06:30AM (#27172653)
One these problems usually:

- application is in one state and the UI is in another state

- jQuery operations mutating the DOM causing weird edge cases after several user interactions

- the template language (handlebars, mustache etc.) was getting in the way because it lacked the expressivity of javascript

- application state was split all over the place between Models, Views and Controllers. instead, if you put as much state as possible in a single place in your application, it's much easier to just create declarative functions that take in an immutable state and output a DOM node object: `(state object) => DOMNode`

Right now I'd use React only for projects that require it as legacy or as a part of a framework. If you want to get things done quick, Next.js is pretty good framework for greenfield projects that uses React under the hood and I don't mind it being there too much. But similar things to React can be achieved with Svelte or Lit without having to ship and manage a VDOM implementation or JSX with its quirks (e.g. className).

So in summary, I'd stay away from all features of React other than VDOM, and even skip that if possible. And as a general rule, don't use any frameworks unless you can say why your project specifically really needs it. Surprisingly much can be done with basic HTML, JS and CSS. People who say "just use X" are trying to force simple answers to a field that is inherently complex and needs good judgment on which tools to use and when not to use them.

Re:Modern Javascript: Everything you missed over the last 10... by thealig on Sunday May 16, 2021 @07:33AM (#27172942)
I have experienced working on a messy application codebase (jQuery + Knockout.js) which was 7-8 years old and seemingly was hastily made by on contract of another company. Had to refactor it to ES6 (dynamic imports) -needless to say it was a big pain with unpredictable barely any performance improvement as compared to refactoring on another codebase.

jQuery is a good tool for simple one page applications but not designed for complex web apps. It is harder to code cleanly in it as compared to React.

Re:Modern Javascript: Everything you missed over the last 10... by Oddskar on Sunday May 16, 2021 @08:17AM (#27173155)
I'll bite. What part of React has really been innovative?

Because it seems to me that around the time React really gained popularity there were lots of options that did largely the same thing. Knockout, Ember etc.

Personally I only see it as the real proof that VDom could work for large applications.

Re:Modern Javascript: Everything you missed over the last 10... by ketzo on Saturday May 15, 2021 @06:45PM (#27169668)
Well, isn't there something a little "revolutionary" about mainstream adoption of cutting-edge techniques?

After all, like you suggest, things like functional programming and monads have existed for quite some time. The thing that makes React special is how rabidly people adopted it, and continue to adopt their major updates.

Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @06:54PM (#27169710)
>Well, isn't there something a little "revolutionary" about mainstream adoption of cutting-edge techniques?

Taking the example of hooks, React has hooks because it was released with a bunch other stuff in addition to the VDOM, people started using those things as a (poor) framework, shot themselves in the foot repeatedly and finally hooks had to be introduced as a fix on top of that.

Calling that band-aid "revolutionary" or cutting edge technology, kind of sounds wrong. They never would have been there and wouldn't have been needed if it weren't for the bloated original release.

But of course, even if that band-aid makes people think differently about building apps, it's all good. That's why I mentioned in the post that it's a great thing. But calling it "revolutionary" when a large fraction of programmers have been doing it that way for ages is a bit of a stretch.

Re:Modern Javascript: Everything you missed over the last 10... by warent on Saturday May 15, 2021 @05:57PM (#27169395)
> but all of the other ideas have been implemented and used on the web before.

Is this true? I've worked in web dev for like 6 yrs now and React has provided a significant number of concepts and technologies I'd never seen before and still dont see elsewhere.

For example, JSX. Yes, it originated in php but React was its first time being implemented in the frontend.

Also the concept of hooks and functional components. The fact that you explicitly define side-effects in the render of a function, with memoization or execution dependent on arbitrary state, is a new invention as far as I'm concerned.

Re:Modern Javascript: Everything you missed over the last 10... by tppiotrowski on Saturday May 15, 2021 @07:03PM (#27169754)
Honestly, the separation of concerns movement where content writers do HTML, designers do CSS and programmers do Javascript, all with with minimal overlap, set web development back a good 10 years. React was a wake up call that the three are intertwined so closely that you cannot think about them in isolation.

One of the early criticisms of React was: “You can’t do HTML in Javascript. You shouldn’t be styling in JS! That violates the separation of concerns.” React skyrocketed productivity and allowed scaling without spaghetti. That’s why it won.

CSSZenGarden was fun, but how many companies seriously did redesigns by just swapping a style sheet? Only repeat the dogma if it makes sense....

Re:Modern Javascript: Everything you missed over the last 10... by sircastor on Saturday May 15, 2021 @09:13PM (#27170378)
HTML in JavaScript still feels wrong to me and I still hate JSX. The Vue and Svelte approach to simply having the HTML in the same file was much more digestible.

I think React won because it had a more gradual learning curve than Angular and a didn’t drastically change between versions.

And the idea that HTML/CSS/JS are non-isolated is over-thinking it. It only applies to the world of Webapps. HTML can be published and served all day without CSS or JavaScript. And you can do a lot with HTML and CSS alone.

Re:Modern Javascript: Everything you missed over the last 10... by kentor on Sunday May 16, 2021 @02:28AM (#27171658)
Why hate JSX? There are lots of benefits to it, like debuggability and variable scoping rules are exactly those of javascript. Templating languages, on the otherhand, are not debuggable and have awkward scoping rules. And, they always feel broken in one way or another.

JSX is not magical which is what I appreciate the most about it.

Re:Modern Javascript: Everything you missed over the last 10... by graftak on Sunday May 16, 2021 @03:57AM (#27172001)
Don’t forget proper and full typescript support. Going back to vue (2) after doing tsx was like going back to jquery; loads more context switching and mistakes.

The ability to type `children` alone makes a world of difference.

Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @06:05PM (#27169443)
Yes, yes and yes. All of these concepts are variations of what has been done before in a number of ways. Mostly by "FP academics" who "live in fantasy land", until everyone else starts using them too.

Transpiling, hooks and components have all been done (and done better) before React came along, but often they were laughed out as esoteric toys that have nothing to with "real programming". It's just hard to teach these concepts until you actually use them, and it's hard to get people to use these concepts unless they are included in something else that you need.

The same happened early with React, both JSX and VDOM were laughed at by many developers because "they looked stupid" to people who didn't understand them and were used to one way of doing things. MVC+jQuery+templates was the flavour of the day.

Same thing with TypeScript, FRP and so on.

Most likely, whatever concept is gaining momentum today, it's an exact or approximate copy, or in rare cases a novel remix of what has been researched 10-20 years ago, and used in production for 5 years before you heard about it on HN

These people who like to apply category theory etc. in programming have heard this mocking of their work as stupid esoteric fantasy (and then seeing them become mainstream later) so often that they literally called one of their specs "Fantasy Land" https://github.com/fantasyland/fantasy-land

There's still lot of work to be done. JavaScript doesn't even have proper immutable data structures natively, which would be a REAL low hanging fruit.

Re:Modern Javascript: Everything you missed over the last 10... by ZephyrBlu on Saturday May 15, 2021 @07:13PM (#27169800)
I'm very curious what the better, academic version of VDOM, hooks and components that has already been done looks like in comparison to React.
Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @07:19PM (#27169837)
Svelte does reactive UI without a VDOM at all. Every DOM operation flows from declarative instructions based on the state of the application, without a need for VDOM or hooks.

The compiler is quite mature and used by countless apps in production right now.

https://svelte.dev/

I've been using it myself and it doesn't feel academic at all. The Svelte Kit toolkit, a successor to the Sapper frameworks is also ready to use but it's not 1.0 yet so might be a bit unstable. But if you're worried about having to figure things out then you can use Sapper+Svelte or just Svelte just fine, and they're very robust and well documented.

Re:Modern Javascript: Everything you missed over the last 10... by ZephyrBlu on Saturday May 15, 2021 @07:28PM (#27169877)
I know what Svelte is. Svelte wasn't done before React or by "FP academics" though, which is what you said in the comment I replied to.
Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @07:34PM (#27169915)
As I said, the VDOM was novel. However, unidirectional data flow, lenses and FRP with RxJs all predate React. There was also Elm which was a full framework that was based on these concepts, and ClojureScript with its whole ecosystem that did things a bit differently. Though most people who do utilise functional programming concepts prefer not to use a framework but pick-and-choose libraries that do the job for that specific project. That means that the field was (and is) very scattered, and there's no single "React but better and made earlier". Because React is a unique combination of tools. But each of those tools have been done in one form or another many times, except for the VDOM, which I believe was novel.

On another note, a React component in FP is just any regular old JS function with a signature: `(state) => HTML string`. React is such a simple concept that it wouldn't have needed any sort of library, if it weren't for the performance and DOM reset issues.

Re:Modern Javascript: Everything you missed over the last 10... by dmitriid on Saturday May 15, 2021 @09:16PM (#27170394)
> However, unidirectional data flow, lenses and FRP with RxJs all predate React.

They may predate React, but React made them easy.

Good luck explaining how lenses work.

Rx? it took the author of RxJava months to understand the concept. And he had the author of Rx.net there to explain stuff to him. [1]

> there's no single "React but better and made earlier".

Yes. And that is precisely the point

[1] https://twitter.com/dmitriid/status/811561007504093184

Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @06:40AM (#27172706)
Well that's why said

> React made a huge impact on web dev and deservingly so

The VDOM was revolutionary, no question about it. The comment I was replying to didn't even mention it.

Re:Modern Javascript: Everything you missed over the last 10... by dmitriid on Sunday May 16, 2021 @07:07AM (#27172823)
Your original comment was literally this, emphasis mine:

--- start quote ---

All of these concepts are variations of what has been done before in a number of ways. Mostly by "FP academics" who "live in fantasy land", until everyone else starts using them too.

Transpiling, hooks and components have all been done (and done better) before React came along

--- end quote ---

When asked about the emphasized part, you mentioned Svelte for some reason. When called out on that, you went and listed a bunch of things, ... none of which are really better, and are quite esoteric. To the point that it took the authors of some implementations months to understand the concepts.

React (pre-hooks) could be picked up in less than a day, and just worked. Re-creating React concepts from scratch was a three-page tutorial.

Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @09:19AM (#27173523)
If you judge technologies based on a single anecdote you've heard on the internet then I don't think this conversation serves any purpose. I don't know what bone you have to pick with any technology other than React, but achieving declarative DOM manipulation pre-React was as simple as `(state) => $('<div>').innerText(state.message)` with the plain old jQuery. That was definitely easier than learning React, and by building a component structure with vanilla javascript functions, you could have all the functionality and expressiveness of JSX without a compile step or external libraries.

Of course this would cause problems that I've described in this thread before (scroll/form state resets, performance problems etc.), so the VDOM was the missing piece of the puzzle. Overall the concept of declarative UI was incredibly simple and predated React, but the VDOM was a great thing that solved the problems people were having with declarative DOM manipulation. If React had shipped just with the VDOM implementation, it wouldn't have needed to expand into a full-fledged framework and introduce a bunch of band-aids on top it. React deservedly skyrocketed, and the VDOM was an incredible thing to introduce at the time, but every part of React is quickly becoming outdated as more FP concepts from the past are introduced into the mainstream.

So all in all, React shaked things up in a good way, and finally people are ready to move on to make their apps actually reactive and taking a serious look on things that have been "academic" before.

Re:Modern Javascript: Everything you missed over the last 10... by dmitriid on Sunday May 16, 2021 @12:25PM (#27174737)
> If you judge technologies based on a single anecdote you've heard on the internet

I don't

> I don't know what bone you have to pick with any technology other than React

I don't have a bone to pick.

> but achieving declarative DOM manipulation pre-React was as simple as

Yes, it was possibly achievable. Did anyone achieve it? You claimed that evertyhing React has was done better before React. When asked about examples, you answered first with Svelte (which appeared after React), and then with disparate technologies which are are at best esoteric and at worst extremely complex.

> That was definitely easier than learning React, and by building a component structure with vanilla javascript functions, you could have all the functionality and expressiveness of JSX without a compile step or external libraries.

You probably could, but did you? Oh, wait, you didn't. The hot tech du jour when React was released were knockout.js and backbone.js.

And, once again, the etirety of "learning React" took less than a day. And "building a component structure using vanilla javascript functions" was literally a three-page tutorial if you wanted it.

Compare this to Rx that you gave as an example of something "better than React". The author of the original Rx.Net sat by the author of RxJava, and it still took the author of RxJava several months to understand the concept. Lens, another of your examples, is esoteric even in Haskell.

But sure, "everything was done better before React came along" :-\

> React shaked things up in a good way

Indeed, it did.

Funnily enough, you start with "Transpiling, hooks and components have all been done (and done better) before React came along" and then continue with "there's no single 'React but better and made earlier'."

Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @12:31PM (#27174798)
>You probably could, but did you? Oh, wait, you didn't. The hot tech du jour when React was released were knockout.js and backbone.js.

I did. It's kind of funny to hear that you cannot even entertain the idea that people actually did declarative UIs before React with plain old vanilla JS, because that was my bread and butter back in the day. That's precisely how I did frontend until React came along, and so did many others. We sometimes sprinkled in some CoffeeScript to get nicer function syntax, before () => {} and babel existed, but it wasn't necessary if we wanted to avoid a compile step.

Just because some frameworks were prevalent at the time didn't mean that everyone used them. Large portion of seasoned developers rejected all frameworks and still do today. They had shot themselves in the foot with MVC/"trying to do everything" -frameworks enough times to learn that not all answers come from a single framework that encompasses your whole application. This is nothing new or esoteric, and still today a good lesson to learn for new developers. Instead many people continue to use "the standard" framework, fighting against it when it fails to fit the domain logic of their app, and waiting for a new framework to arrive to save the day. Frameworks have gotten much more flexible about this today, but React wasn't anything revolutionary on the framework side of things.

It's not as simple as "React bad/React good". A framework/library can be good in certain aspects and bad in others. I loved React when it came out, because of the VDOM. Wasn't a fan of everything else though, and especially not a fan of how it was used as "the new standard framework to tightly couple your application into". This is not a contradiction, it's just non black-and-white thinking.

Re:Modern Javascript: Everything you missed over the last 10... by dmitriid on Sunday May 16, 2021 @01:04PM (#27175105)
> I did. It's kind of funny to hear that you cannot even entertain the idea that people actually did declarative UIs before React with plain old vanilla JS

By you I meant "collective you". I don't care what individual developers did that no one knows about.

> Just because some frameworks were prevalent at the time didn't mean that everyone used them.

    define: prevalent

    1 : generally or widely accepted, practiced, or favored : widespread

    2 : being in ascendancy : dominant
> Large portion .. upto ... flexible about this today

Bears little to no relevance on the discussion

> React wasn't anything revolutionary on the framework side of things.

Except, it was. It upended the prevalent way of doing things and ushered in a new prevalent way of doing things.

    define: reovultionary

    1 c : constituting or bringing about a major or fundamental change
I did bring about a fundamental change: the prevalent way of doing things on the web changed.

> It's not as simple as "React bad/React good".

Of course it's not. But we're not discussing whether it's bad or good.

> it's just non black-and-white thinking.

So far your "non black and white thinking" is "everything React has was done better befroe React, but I can't show anything to prove this except some disparate things that are both complex and esoteric, and I can also go on a prolonged discourse about how some developers don't use frameworks and may have done things a la React before React".

Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @01:30PM (#27175349)
I already told you what I did and several developers did before React to combat the same problems the React addressed, but somehow you seem to dismiss all of it. If you don't want to believe it, that's fine. I know what kind of code I wrote before React, your ramblings won't change it. Have a good day.
Re:Modern Javascript: Everything you missed over the last 10... by atatatat on Sunday May 16, 2021 @01:55PM (#27175579)
This disagreement is related to discussing different things:

What devs can implement on their own beyond frameworks, and what frameworks mean to how the community as a whole operates.

"Defaults matter."

Re:Modern Javascript: Everything you missed over the last 10... by lmeyerov on Saturday May 15, 2021 @09:51PM (#27170556)
I remember it a bit differently

for context, I wrote the first web frp+vdom and helped inspire the creation of rxLinq and related systems, and we even did a whacky thing back then that predicted Parse/Firebase/redux/graphql/falcor, including some basic features they still don't have (should have spun out a startup instead of getting a PhD!). our group even did the first lenses for the web, though that one ended up much less usable. I think we did all that around 2003, while the alternatives were PrototypeJS, jQuery, and a couple other more sugar-level things

however.... react with hooks, jsx, and the various css modes nowadays is pretty awesome, and eliminates most of the needs for streams. main lack there is more for rich animation, than web apps. graphql, redux, and friends are all still clearly clunky technologies with limited shelf lives, so I'd focus more there than react for basic abstractions

at the same time, nowadays I think more about synthesis, ml, end-to-end GPU computing (actually proposed that back then too!) and other more powerful ideas than revisiting frp/lenses/etc...

Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @06:38AM (#27172697)
Then I stand corrected. :) Maybe I wasn't looking hard enough earlier.
Re:Modern Javascript: Everything you missed over the last 10... by kaba0 on Sunday May 16, 2021 @04:14AM (#27172074)
How is the vdom novel? Any retention mode GUI does that, hell the DOM itself does that. It’s only novel in that they reimplemented it in “user-land”, because of the performance shortcoming of the DOM.
Re:Modern Javascript: Everything you missed over the last 10... by antris on Sunday May 16, 2021 @06:38AM (#27172691)
It was novel because you couldn't refresh the whole DOM based on your application state without user experience suffering, before VDOM diffing came along.
Re:Modern Javascript: Everything you missed over the last 10... by randompwd on Sunday May 16, 2021 @06:56AM (#27172779)
And they still had to execute the DOM operations anyway so I feel scepticism of React was warranted.

When the complex reality of JS applications was reached in React, React shortcoming became more and more apparent.

There's no free lunch.

The easier to mentally digest appeal of 'redraw the whole thing every-time'* was fantastic but performance was always going to take a massive hit past an easily reached point.

* The difference this time was the diff engine was going to be smarter than before but it was not good enough.

Re:Modern Javascript: Everything you missed over the last 10... by jb1991 on Sunday May 16, 2021 @01:25AM (#27171427)
> all predate React. There was also Elm

No, React was first. It was in production, if internally, for more than a year before Elm came onto the scene.

Re:Modern Javascript: Everything you missed over the last 10... by eurasiantiger on Saturday May 15, 2021 @07:00PM (#27169740)
The esotericity is not in the expressible semantics, but in the syntax.
Re:Modern Javascript: Everything you missed over the last 10... by nextaccountic on Sunday May 16, 2021 @08:55AM (#27173381)
I think the Opa language was doing JSX-like code in the frontend before JSX http://opalang.org/

Both Opa and JSX were created in 2011. Opa had other innovations as well, such having the same code base run on both client and server (like Next.js). Unfortunately it didn't get traction and was abandoned by the creators.

Re:Modern Javascript: Everything you missed over the last 10... by hajile on Saturday May 15, 2021 @08:14PM (#27170113)
JSX as syntax goes back to ES4 and the E4X specification (though the function aspect goes back to php as far as I know).
Re:Modern Javascript: Everything you missed over the last 10... by ptx on Saturday May 15, 2021 @06:46PM (#27169675)
> virtual DOM diffing ... is becoming increasingly irrelevant as apps are moving towards more and more reactive architecture

Could you expand on this? What was it that necessitated DOM diffing before, and which architectural changes are making it irrelevant?

Re:Modern Javascript: Everything you missed over the last 10... by antris on Saturday May 15, 2021 @07:04PM (#27169755)
State and DOM being mutated all over the code base was the norm before React. In many apps, state was a thing that was spread out all over the code and could be mutated by any part of the code. And a DOM was another global state on top of that, that had to be kept in sync with the data of the application. Otherwise users would be shown a state that wasn't representative of the actual state of the application. People did this with careful DOM modification code, trying to always remember to set, reset add and delete DOM nodes correctly. Of course, this caused many bugs and sometimes huge performance issues.

If you tried to solve this problem by redrawing the DOM every time your app state changed somewhere in the code, the browser would freeze and all your form elements would be defocused on every update, scroll states would be reset etc. etc.

React solved this by the diff algorithm and doing surgical updates of the dom based on the components state. It does this by manually reading the state, keeping a virtual DOM in its memory and doing diff calculations.

But if your whole app is reactive by design, there's no need to read the app state, doing diffing or figuring out which DOM node to update which one not to update. The DOM update operations flow naturally by the declarations given by the programmer. Frameworks such as Svelte are moving into this direction and they're already seeing quite significant performance improvements compared to VDOM implementations.

Re:Modern Javascript: Everything you missed over the last 10... by atom_arranger on Saturday May 15, 2021 @08:08PM (#27170094)
The best part about React is declarative rendering, you tell React what the DOM should look like, it makes it so. React does this using a virtual representation of the DOM, but this is an implementation detail.

If you can do declarative rendering without keeping a virtual representation of the DOM and diffing it against the real DOM then "the virtual DOM is overhead" (https://svelte.dev/blog/virtual-dom-is-pure-overhead).