r/javascript • • Jun 16 '17

Adopting React.js seems risky for long-term projects

https://rosenfeld.herokuapp.com/en/articles/2017-06-16-adopting-react-js-seems-risky-for-long-term-projects
33 Upvotes

44 comments sorted by

63

u/BenjiSponge Jun 16 '17

TL;DR: Because React officially takes the stance that any component's .render function can be called whenever (which is why you're supposed to avoid side-effects in .render functions), you can't guarantee that a stateful DOM element managed by something less "clean" than React won't just be re-rendered. So third-party code could be destroyed by a change in the React algorithm.

I had a similar issue with this when I was considering using React on a site with ads. NFL created a component for this that relies on shouldComponentUpdate, which /u/rrosenfeld notes is not a great solution.


On a personal note, I think the conclusion drawn is a bit sensationalist. If you're making a library that relies on this, you're passing risk down to the users. If you're making an application that relies on this, there's nothing forcing you to upgrade React, breaking your app. React v15 will always have the same reconciliation algorithm, and it will always be compatible with all the libraries you currently rely on (at their current versions). Tons of long-term projects use very old versions of technologies.

Further, I'd give it a nearly 0% chance that React will upgrade the reconciliation algorithm to re-render more often than it does now, especially violating shouldComponentUpdate. And even if they do, they will definitely include a new way to handle this. It's too common a usecase to just say "Well, you should have read the philosophy documentation; we're not given you a migration path".


Granted... working third-party code into React is absolutely not fun. If your application is going to rely on a lot of vendor code mucking around with your DOM, you should probably skip it anyways.

14

u/[deleted] Jun 16 '17

Because React officially takes the stance that any component's .render function can be called whenever (which is why you're supposed to avoid side-effects in .render functions), you can't guarantee that a stateful DOM element managed by something less "clean" than React won't just be re-rendered. So third-party code could be destroyed by a change in the React algorithm.

The way I use React is at the component level. I.e. I have my own controller logic updating a myriad of hybrid components, and some of them happen to be React.

This approach doesn't have the issue the author is complaining about, and seems especially non-risky for long-term projects, because I can always change the rendering library/approach for any specific component without anything breaking.

So this seems to confirm my approach: don't let React (or any other framework) consume your entire app, let it sit at the component level and use your own controllers.

2

u/rrrosenfeld Jun 17 '17

Let me talk about an specific case where React would help me. I currently have to manage a complex dynamic nested tree containing states, buttons and components such as autocomplete, date-pickers and range sliders to name a few. Managing that tree state by hand is complex, hard to maintain and bug prone. If I could manage with something that would free me of having to manage the DOM manually, that would be great. It could be React, Inferno, Preact, Knockout.js, Angular, Vue, whatever. But it needs to render pretty quickly and VDOM based solutions seem to lead towards faster initial rendering, which is more important to me than the update speed. However, I should be able to change that tree component while keeping the autocomplete, date-picker and slider components, for example. At least for the first steps, so that I don't have to rewrite everything at once. What I mean is that some components behave between the application and other components.

2

u/BenjiSponge Jun 17 '17

Coming back to this, you could cache the autocomplete requests in redux (or component state, really). If you do work with iframes or particularly messy things, this is a concern. But all of the examples you've given (I think) are just stateful components.

1

u/rrrosenfeld Jun 17 '17

Fortunately I won't need to worry about this, since the React team has stated that the diff algorithm won't be ignored in the sense that while they could call render() in all components, that doesn't mean they could remount all components if the VDOM tree didn't change completely. When the user requests to open the menu they will naturally expect some delay, so I'm not worry about that. I'm worry about having to recreate the menu because React would decide to remount that component whenever they wanted, when the user wouldn't be expecting, which is fortunately not the case, even for future releases.

8

u/Reashu Jun 17 '17

Hear hear. React is a tool, not your master.

3

u/campbeln Jun 17 '17

I've started to move this way with Angular 1.x; Use it for UI/binding and nothing more. 'Course this is in preparation in moving to Vue or React while giving my boss the good argument of "we only need to change a small percentage of code". I've mostly had this approach from the beginning as I've long developed my App logic in a single global var, a'la YUI (at least that's where I learned the technique from).

I've never been a fan of "the Angular wayTM". Using it in this way allows me to (in theory) change out Angular (e.g. the UI/binding stuff) about as easily as switching a Db. Course I guess we'll have to see how it actually goes :)

4

u/rrrosenfeld Jun 16 '17

I understand how you are more confident on React than I am and I respect that. However I didn't quite follow you on this sentence:

'you can't guarantee that a stateful DOM element managed by something less "clean" than React won't just be re-rendered.'

Would you mind defining what a "clean" component would be and how some third-party component would be less "clean" than React? It seems to me that basically any stateful non React component would suffer from this.

I understand you think the conclusion is sensacionalist since you trust React won't change the reconciliation algorithm without providing a good path. But suggesting that we should keep using ancient versions in long running projects is not really a good suggestion. We shouldn't call an application a legacy one if it's being constantly improved, which also means we usually want to be up to date with the libraries we use, to get bug fixes, speed ups, up-to-date documentation in the website and so on. We have been using jQuery forever but that doesn't mean we still use jQuery 1.x. We're on latest jQuery despite the application being over 6 years old, and it's constantly changing. I don't think relying on an old version of React forever is an acceptable solution, that's why I value the philosophy behind a project so much. If the major goal of some big project, such as Angular, React or Rails is to serve Google/Facebook/Basecamp then you're in a bad situation if those companies change their goals and they become incompatible with your own goals... I don't really see the conclusion as sensacionalist. I'm indeed really worried about it. I can't get aboard unless I understand React will consider integrating to third-party components a top 1 priority by always providing some means to use them in a reliable way.

5

u/BenjiSponge Jun 16 '17

I definitely see where your concern is, and I would also like to point out that I respect your opinion very significantly, as you're both well-reasoned and more experienced than I am. I'm just calling it like I see it, so to speak. =)


With regard to the first question, I'm simply referring to a piece of the DOM that is managed by something that will essentially get "messed up" by re-rendering. It's essentially the problem you're referring to. So a "clean" component might be something that just gets rendered to a string, or a navbar that gets rendered as pure DOM while third-party code lives elsewhere on the page, changing it on scroll events. "Unclean" components might be ads (which hold auctions every time they're rendered, so re-rendering the div means you lost the creative and have to run another auction if you want anything to show up) or really anything in an <iframe>. I'm sure you know what I mean, as it's what you're writing about.


I agree with you that it's not a great solution to suggest that you resign yourself to sticking with the current version forever. I would argue that it's not as bad as you'd think it is (again, nothing is going to stop working), and you can't really prevent it anyways. There have been no promises made that jQuery 4 is going to be backwards compatible (as far as I know), but you still feel confident enough to stick with jQuery 3, right?

But more importantly than it not being terrible if that does happen... well, it's not going to happen. I understand your lack of trust for Facebook, but I do believe it is at least slightly misguided. You say that if Facebook's goals differ from your own goals, they will likely not support features that support your own goals. This may be true, but it doesn't actually have basis in history. I'm sure there are other examples of this, but off the top of my head I can think of the fact that React DOM can render to string, despite the fact that Facebook doesn't actually use that (not sure how it does its server rendering, but they've openly said they don't use React server rendering). The React team has consistently proven that they consider rendering to string a priority, despite offering (AFAIK) no direct benefits to Facebook. In fact, distinguishing React as a reconciliation algorithm and separating it from its render target is a pretty large investment for relatively little payoff (for Facebook). Loads of people use React for render targets that aren't native mobile and aren't web, but Facebook doesn't.

React is also not just Facebook. It's open source with external contributors both to its core and its ecosystem, so you've got people with vested interest able to make genuine contributions. You've even got competing, 100% compatible projects with similar but different reconciliation algorithms (Preact, Inferno). You can largely switch freely between these projects with different Babel plugins and codemods.

Champions of React (NFL being one of them, as shown in my last comment) rely on certain behavior quirks. If the React team decides to break these quirks, you will be in the company of bigger organizations.

Lastly... this particular quirk that you're concerned about is almost definitely never going to change. Or, if it does, it will probably change for the better. I really think the philosophy exists as guidance for programmers to encourage them to program declaratively rather than to preclude developers from using them if they can't program that declaratively.

I do agree, however, that they should take an official stance on how to deal with this kind of thing, because it is a very common concern.

3

u/rrrosenfeld Jun 17 '17

Regarding "clean" components, it seems you would consider as "unclean" every component that can't restore an exact state upon initialization. I wouldn't call that "unclean" because it seems like it was badly written, which isn't usually the case. They were written based on regular assumptions which VDOM based solution end up breaking without necessarily providing an escape hatch. For example, if your autocomplete component options are populated from some XHR request, than reinitializing it would force that XHR to be requested again which could introduce a noticeable delay. It doesn't mean the component is not "clean". It just doesn't work well if something would be constantly removing it and recreating it.

I understand your lack of trust for Facebook

It's not Facebook I don't trust. It's the future of React implementation based on its documentation actually. I don't like to depend on any framework built to support any company's product only, it doesn't matter what product/company it is. But since there are many React compatible libraries out there, this is not something I'm really worried about. But since React is the reference implementation, if the alternatives would follow React's changes in the implementation, than I'd have the same problem. That's why I also asked Preact and Inferno authors about what they think about this.

I've been using jQuery forever and I know its team is very concerned about compatibility breakages. That's very unlikely to change because it's part of its culture. I would probably never use Angular after they basically created another incompatible product with Angular 2. That means this could happen again with Angular 3. Indeed we can never be sure of anything but we don't take our decisions blindly either. We usually observe and try to make the best decisions based on the facts we know about. If React decides to update its documentation to point out clearly that they will always provide some means to integrate with non-react stateful components, then I may decide to trust its documentation and adopt it. But relying on jQuery and become surprised that jQuery 4 will break everything is different from relying on React when its official documentation explicitly says that shouldComponentUpdate could be considered just a hint in the future. The risks are quite different from my point of view.

You mentioned it being open-source as it this was warranty of anything. Rails is also open-sourced but it's certainly much more optimized to Basecamp's needs rather than what most of the Rails community would expect. Most Rubyists seemed to prefer RSpec at some point, but the default was something else. Most preferred jQuery at some point but Prototype was bundled by default. Many were building traditional SPA and wanted integration with Node build tools and npm, but they used to provide their own thing for a long time and promoted technologies no one was buying such as TurboLinks and so on. I mean, of course people are free to contribute but whenever there are conflicts, the company's needs usually comes first. Since Google would no longer work with Angular 1 but would prefer to use Angular 2, then why maintaing something they wouldn't use? I understand Google's concern, but I also have my own concerns because I'm not Google, or Facebook or Basecamp. I'm in a two developers team, with little resources when compared to those big companies, which means those decisions have even more impact in our product. I also hope React doesn't change in a way it would break compatibility with existing third-party components that rely on its current implementation, but I'm not sure I should invest much time on it when the documentation explicitly says it could break that compatibility without providing any guarantees regarding third-party components...

1

u/ns0 Jun 16 '17

So no anything else but react?

3

u/rrrosenfeld Jun 16 '17

It seems Inferno's author is positive about keeping the current behavior of shouldComponentUpdate, which certainly helps:

https://github.com/infernojs/inferno/issues/1127

3

u/BenjiSponge Jun 16 '17

I've always felt Inferno was superior... Guess Facebook did too considering they hired /u/trueadm

1

u/GitHubPermalinkBot Jun 16 '17

I tried to turn your GitHub links into permanent links (press "y" to do this yourself):


Shoot me a PM if you think I'm doing something wrong. To delete this, click ^here.

3

u/BenjiSponge Jun 16 '17

Ironically, this isn't that useful because if the reconciliation algorithm does change, my link will potentially be more relevant because you'll be able to see how NFL adapted to fix it. =P

22

u/acemarke Jun 17 '17

Your complaint seems to be based on a misunderstanding of how React re-renders.

As you noted, the "Integrating with Other Libraries" page says:

To prevent React from touching the DOM after mounting, we will return an empty <div/> from the render() method. The element has no properties or children, so React has no reason to update it, leaving the jQuery plugin free to manage that part of the DOM

Remember that React only compares the Virtual DOM trees returned by your component (ie, the last output from render vs the current output) to determine if any DOM changes are needed. It does not compare the render output with the actual DOM to make that decision.

Therefore, if your component's render method is simply return <div />, no matter how many times your component re-renders, React will always see that the component is trying to render one single div, and after the first render there will be no changes made whatsoever. That means that you can safely append non-React HTML nodes to that div, and React won't try to remove them. That's why you can use the pattern of initializing jQuery plugins and other DOM-manipulation-based libraries in componentDidMount, because React has done the work of creating that initial requested element, and as long as your component doesn't tell React it wants anything different, React won't make any changes.

I also don't understand your "autocomplete" example. React's defined semantics are that as long as you keep rendering a given component type in the same place in your render method, React will keep the matching component instance mounted. That's why, if you only use array indices for keys in a list and then make changes to the array contents like deleting an item, you will see already-mounted list items suddenly having their props change (because React thinks you're asking for the same component with different props than before).

I do find the note about possible changes to shouldComponentUpdate to be a bit curious, but given the size and scope of the React ecosystem, and the importance of sCU as a performance optimization, I find it very unlikely that there will be any changes to its semantics in the foreseeable future. In addition, the React team is extremely serious about maintaining compatibility and providing upgrade paths, such as releasing automated codemods to update your code to newer patterns.

Overall, while I understand your wanting to do due diligence and keep yourself from being locked-in, I think you are really over-thinking things :)

0

u/rrrosenfeld Jun 17 '17

The problem with that snippet of the documentation is that it's contradicted by this other snippet:

It is important to remember that the reconciliation algorithm is an implementation detail. React could rerender the whole app on every action; the end result would be the same.

The result won't be the same if the reconciliation altorithm changes in such a way that React would rerender the whole app, that's what I'm really complaining about. The documentation has statements that are not compatible one with another.

As long as the reconciliation algorithm would never perform unneeded DOM operations, shouldComponentUpdate is not even required in order to being able to integrate with third-party components. I mean, with the current algorithm it's possible to always integrate with third-party components but I'm worried about React saying that it could replace its algorithm so that it would re-render the whole tree and it would be still fulfilling its specifications.

I understand about React's keys for lists and I do have unique keys to use in my application, this is not my concern. I mean, I'm just fine with the current React implementation. I'm not fine with the fact that React doesn't provide any hard constraints about its reconciliation algorithm so that I could count on it for future releases.

In addition, the React team is extremely serious about maintaining compatibility

But my concern is that since it's not part of the specification, React doesn't have to worry about compatiblity in that case.

I also don't understand your "autocomplete" example.

Let me explain how things actually work in my application. Users can search for deals based on criteria created on a set of 800 or so fields structured in a nested tree component. Sometimes, some of those fields only apply under certain circumstances. So, if the Consideration Type field includes the value "Cash", then some of the fields in the tree would be displayed (or hidden). As the autocomplete menu is open, several options are displayed with a checkbox next to each of them. As those options are checked the menu remains open but the changes take place immediately as the search results reflect the new values and the fields tree state is also changed accordingly in order to hide or show other fields based on the value section for the field being edited in the autocomplete. Since setState in an ancestor element will trigger its render method, if the reconciliation algorithm changes in such a way it doesn't understand correctly that some nodes shouldn't be touched, then there's a chance that the node being edited would be removed and re-added, and in that case the user would see the autocomplete menu closing when it shouldn't. That's my concern.

12

u/acemarke Jun 17 '17

You're still kind of misunderstanding, I think.

Even if React re-rendered the entire application, as long as your render output doesn't change, then React won't alter the currently mounted components or DOM nodes. For your use case, it's not the re-rendering that's a potential concern, it's whether components might be unmounted, and they'll only be unmounted if you ask React to render something sufficiently different. "Rendering" means "return a tree of objects describing how I want the UI to look like now". It's a prerequisite for React modifying the DOM and component tree, but simply re-rendering doesn't mean it will make changes.

7

u/rrrosenfeld Jun 17 '17

You were right, /u/acemarke. React team responded in that issue:

When documentation says "re-render" it refers to calling the render method and reconciling the changes, not unmounting and mounting components. React never unmounts components unless key or type changes.

While we can't guarantee that React won't be calling render in more cases, we can pretty much guarantee that:

If component key and type doesn't change, React won't unmount the component (and destroy its state). At most, it will attempt to reconcile parts of the DOM managed by React. And you can always short-circuit that by returning just <div /> and managing its content yourself. If you manually touch the DOM that React doesn't manage (e.g. imperatively change an attribute that doesn't exist on React side), React won't blow away your changes on re-rendering.

This is pretty enough guarantee to me and I'll try to submit a PR to make that part clearer in the reconciliation documentation. I'll update my article first. Thanks :)

3

u/[deleted] Jun 17 '17

/u/acemarke I think /u/rrrosenfeld has a fair point that the reconciliation doc has this unnecessarily scary statement that "React could re-render the whole app on every action; the end result would be the same." which has a contradiction with uncontrolled (or controlled by external jQuery plugins) components in general.

If in my view tree I render a slider whose value I don't track, what happens if React decides to render my entire subtree? If the user has moved the slider from 0 to 50, and I refuse to track the value in code, what happens now? When the user sees the component again, who will move the slider back to 50 where the user left there.

This crazy example will of course never happen in production, because React does not arbitrarily make decisions and decide to make different rendering decisions, whether they say reconciliation is an implementation detail or not.

Now what I don't understand from /u/rrrosenfeld is that how can you ever trust a third-party library with this paranoiac mentality? It seems you're a bit too risk-averse, and I cannot see you taking a dependency on a library whose documentation -in my opinion- is a bit shaky. Try to use react-native and you will even see that not all props that React's views accept are undocumented and you will have to dig in their code base to implement more complex interactions.

Lastly, no one makes you update react versions. It does follow semver, so if there's a breaking change you will likely see while updating from 16 to 17 and 17 to 18 and so on. For a long term project it'd be better not to trust internals of react but write your application in a way you can test and see if things break. I've worked in a Rails 2 code base before and the team could not update to Rails 4 because they knew they would break. It happens, projects get rewritten, dumped, completely refactored, you got to take action at some point.

7

u/acemarke Jun 17 '17

I agree that the statements regarding possible changes to future behavior raise a couple questions about what might happen, but as I've already said a few times now: re-rendering is not the issue! If you have a component that wraps up a jQuery plugin, and only ever renders a single <div>, then re-rendering will not change that div or interfere with the elements the jQuery plugin has appended.

1

u/[deleted] Jun 17 '17

Maybe we have a conceptual difference when we both mention re-render. If we're talking about re-render as in calling the render method which is part of a React.Component, I absolutely agree from you.

What I understood from that "React could re-render the whole app on every action; the end result would be the same." sentence was, we will dump away your entire tree and re-create it, and you should be able to recreate it from scratch, only with the initial props given to you. As in, make sure your view tree can be represented as a function of input (props) to output (components) without outside influences. In that case I imagine that single <div> instance going away.

10

u/acemarke Jun 17 '17

Yeah, "rendering" does have a very specific meaning - calling render() :) So, when the React team talks about "re-rendering the entire app", I am about 99.99% certain they mean recursively walking down the component tree and calling render() on each component, not "blow it all away and start fresh".

As mentioned, the React team is very pragmatic, and React does have all these "escape hatches" like refs and shouldComponentUpdate explicitly so that React can interop with non-React code and skip unneeded work, as you see fit to use them for your app.

1

u/rrrosenfeld Jun 17 '17

/u/acemarke was right with regards to what the documentation meant when talking about rerendering:

https://github.com/facebook/react/issues/9926#issuecomment-309205972

I just updated my article to reflect that.

2

u/rrrosenfeld Jun 17 '17

The main issue with React documentation has been clarified already by the React team and I can now become confident enough to adopt React, I'll just answer to some statements.

Now what I don't understand from /u/rrrosenfeld is that how can you ever trust a third-party library with this paranoiac mentality?

I'm not paranoic about every component, but something like React, Angular or Knockout, or jQuery, specially if they are used all over the application, should be considered a critical part and for those cases I'm very careful before adopting such kind of technology. I can easily replace some common datepickers, sliders or autocomplete components, so I don't need to be paranoic about those, so I don't have a problem with trusting third-party libraries in general because I don't actually have to trust them. I can easily replace them if they become an issue. But how am I supposed to replace something like React if it can't play nice with other technologies? Now that I understand this is not the case, I can feel safe to adopt it knowing that I'm free to change my mind later with a feasible migration path from React if I decide to move away from it.

Lastly, no one makes you update react versions.

Indeed, but no one wants to use an ancient version forever. If the new version breaks something by mistake, it will be fixed in the next version and I can wait before upgrading. However, if the change was intentional and it no longer allows you to integrate with third-party libraries, then that means you'll have to move away from it which will cost you quite some time. If you already know this is supposed to happen, why do that? That was my point. Fortunately this wasn't the case. I just misinterpreted the docs.

I've worked in a Rails 2 code base before and the team could not update to Rails 4 because they knew they would break.

Do you see how being careful can help? You called me paranoic, but I was always scared by the way Rails upgrades everything at once. If you want to upgrade ActiveMailer or ActionPack you're also forced to upgrade ActiveRecord, which has a terrible API and often introduced backwards incompatibilities. So, very soon, I decided to use Sequel instead of ActiveRecord and that with some other cautions allowed me to be always up to date with every new Rails version. I would often update to the newest Rails release in the exact day it was released and it would often just work after a few tweaks (in several cases with no tweaks at all). But I noticed how upgrading Rails was a nightmare to many people. But the way I choose what I want to depend on (I avoided any gems that would monkey patch some of the Rails libraries, for example) allowed me to have an easy time getting up to date. The reason why I moved from Rails had nothing to do with finding it hard to upgrade it. The upgrade process was always easy on our side.

It happens, projects get rewritten, dumped, completely refactored, you got to take action at some point.

The application I currently maintain was written with Grails when I got into this project. I slowly replaced it with Rails when working around some Grails bugs that were never fixed. At some point I moved completely to Rails. It wasn't a complete rewrite in the sense things were moved one little part at a time and trying to keep the logic when it made sense and improving over it as I saw fit. I would say I was evolving the application, not rewriting it. When I moved from Rails to Roda it was even simpler to move one part at a time to Roda as most of the code would remain unchanged as it's the same language. The only migration I had to perform at once was when I decided long ago to move the MySQL database to PostgreSQL since I can't move one table at a time ;) But the code itself required minimal changes in that case. The harder part was to script the data migration itself.

My point is that proper planning pays off.

6

u/Capaj Jun 17 '17

This is scaremongering. React integrates with javascript libraries just fine-the proof is in the ecosystem which features thousands of wrapper coomponents for even the most archaic JS libs. I've used on the projects a lot of them and they always worked well. If they did not it was a bug of that react wrapper or underlying ui library, not a bug in react.

BTW this shows how few people truly know how react works, because it got so many upvotes.

1

u/rrrosenfeld Jun 17 '17

The article never suggested it doesn't integrate. It was questioning whether this would always be the case or if that just happened by chance but the situation could change if the implementation details are changed. This has been already clarified in the React issue I created on GitHub and they explained what exactly they meant by "rerendering the whole app" in their documentation. I've updated the article to reflect that.

6

u/karathos Jun 17 '17 edited Jun 17 '17

Can you see the problem with that? If I can't really rely on the reconciliation algorithm to not touch the elements React is not supposed to manage, then I have no guarantees that it would be possible to integrate React with stateful third-party components in the future.

you have no guarantee with any piece of code that you don't own. future versions of that code could deprecate the public APIs you use and you'd just have to deal with it if you wanted to update. this has happened with virtually every software library.

you should be basing these decisions off how they handle deprecation, and so far, they've been very good with getting the word out and dumping all kinds of warnings everywhere.

-2

u/rrrosenfeld Jun 17 '17

That has not been my experience with jQuery even after several years using it and upgrading it. Or with Rails. When the library goes through a deprecation phase and then they remove little used public APIs and provide another way of achieving the same, this is way more manageable than relying on some behavior which the documentation clearly tells you you shouldn't count on. While I value React's concerns with regards to deprecations, no deprecation would be needed to transform shouldComponentUpdate in a hint since the documentation explicitly says we should consider it as a hint. That's the difference.

10

u/karathos Jun 17 '17

https://api.jquery.com/category/deprecated/

this is why you are accused of being sensationalist. you are advocating that, in general, adopting react.js seems risky because the documentation is worded in an unfriendly manner to your very specific use case. my rebuttal is, every single library does this. your counter argument is, "That has not been my experience". I can appreciate that, but it clearly does happen, and somebody was affected by these deprecations.

-6

u/rrrosenfeld Jun 17 '17

I expect every great library/framework to deprecate things and provide the new path to achieve the same. This has been the case with jQuery since I started using it several years ago. This was also the case with Rails for the many years I used it. However this is different in React because the documentation explicitly tells you that you shouldn't count on its implementation without telling you how to support third-party components, that's why I'm really concerned. React doesn't actually have to deprecate any changes to what it considers an internal implementation detail. Provided you're using public API from jQuery, Rails and most big projects, chances are that you're always be offered an alternative to the deprecated API methods as well as some time to migrate your code.

For that jQuery deprecated list, they have been deprecated long ago and I haven't been using them for a long time, but they always provided the new way to achieve the old results. This is what really matters to me. I just want to know how I am supposed to support third-party stateful components with React, and React documentation doesn't tell me. Or it tells me that I could use shouldComponentUpdate and rely on the diff algorithm and how it won't touch children from an empty container, and then it will warn you that shouldComponentUpdate could be considered just a hint in future versions and that we shouldn't rely on the diff algorithm. In other words, I don't know how exactly React expects me to integrate with third-party stateful components, that's my main concern.

2

u/digdic Jun 17 '17

na your article is crap lol... every popular long running lib/framework will deprecate things get over it

1

u/rrrosenfeld Jun 17 '17

You didn't get it. In this case there's nothing to be deprecated since React doesn't officially support any method to handle third party components.

2

u/digdic Jun 17 '17

lol keep arguing semantics bud

10

u/s_tec Jun 16 '17 edited Jun 17 '17

I would like to point out that these concerns apply to any stateful React component, not just 3rd party ones.

For example, suppose I make a Counter component with up + down arrows and some local state. Then, I nest that deeply under some kind of router component. Depending on the URL, the router component will either render my Counter page or something else. What happens if I quickly change the URL, and then instantly change it back?

Intuitively, I would expect the count to be reset to 0, since the Counter component should be destroyed and then re-rendered (we left the page, after all). In reality, the count might stay the same because React batches the renders, and the diff algorithm notices that the tree still has a Counter component in the same spot. Thus, if React locks down their diff algorithm to prevent these glitches, they lose a lot of potential optimizations.

The good news (?) is that this affects everything, not just 3rd party components. There is no way on earth React would radically break their diff algorithm to the point where it randomly re-renders things - the sloppiness is so they can err in the opposite direction of doing too few renders. If their diff algorithm did stop tracking component identities one day, it would instantly break half the world (or at least the half that uses component state). I agree that more assurance would be nice, but I feel that the scale of brokenness this would create is assurance enough.

4

u/gaearon Jun 17 '17

Replied: https://github.com/facebook/react/issues/9926#issuecomment-309205972

TLDR: React makes some guarantees, but there is a tradeoff between progress and promising too much. In our experience with 30,000 components these guarantees are enough for apps, but YMMV.

-15

u/shad0proxy Jun 16 '17

Facebook patents are reason enough not to use React.

Google fucked everyone over who invested in Angular 1.

That leaves only vue.js. All aboard the vue train!

5

u/s_tec Jun 16 '17

Or use preact + preact-compat, which gives you a React-compatible API under an MIT license. Vue is a nice library, of course, but hardly the only valid option!

1

u/rrrosenfeld Jun 16 '17

I've been trying to get some hard guarantees from Preact as well:

https://github.com/developit/preact/issues/728

But until this bug is fixed, I'd have the same problem as I pointed in the article, that's why it's important for the reconciliation algorithm to have some hard constraints on how it should work:

https://github.com/developit/preact/issues/725

-7

u/shad0proxy Jun 16 '17

Vue or bust! Vue is framework for the next 10 years.

4

u/rrrosenfeld Jun 16 '17

Vue looks a lot like Knockout.js which we have been using in parts of the application for some years. But just like Knockout.js, it seems harder to create components with Vue when compared to using JSX mixed with JS code when the HTML snippets are really small. It's easier for me to get the context with both the relevant HTML and code side by side. Also, the last time I benchmarked VDOM solutions were able to perform the initial rendering much faster than Knockout.js, which is important to me. I haven't checked Vue yet, but the results might be similar to each other.

-4

u/shad0proxy Jun 16 '17

Vuex is what separates it. That and if you want to write html instead of jsx.

1

u/CarpetFibers Jun 17 '17

How did people who invested in Angular 1 get fucked over? It didn't cease to exist. It still has an active community. No one is stopping you from using it.