r/reactjs • • 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
1 Upvotes

9 comments sorted by

5

u/Canenald Jun 16 '17

I understand your concerns, but some of them might be unwarranted. These days, React ecosystem is mature enough that it can provide almost any kind of component to satisfy your needs, so if you are starting a new large project you really shouldn't default to using non-React solutions. Even if there's something you really liked before you adopted React, chances are good there's a React component out there that offers similar features but offers much better maintainability and debugging experience because it keeps your whole app written in React.

There's still an issue with migrating an old app or things like Google Maps or OpenLayers that use canvas and still need to be rendered into a DOM placeholder. Concerning those, I strongly doubt React devs will simply break shouldComponentUpdate. You can never know for sure of course, but my guess is a component that renders a simple div and returns false in shouldComponentUpdate won't be affected by changes to how the return of this method is treated.

Another issue with your concerns is that the non-React component you are using as example is actually a bad component because it doesn't allow us to construct it with an initial state. It sounds like it could possibly be used as a form field. In that case, how am I supposed to use it for an edit form if I can't supply it with an initial value?

My only concern about React for large projects is how it handles forms and form fields. You can read the details here https://facebook.github.io/react/docs/uncontrolled-components.html. Basically, controlled components are the recommended way and give you a complete control over what happens with your forms, but they are largely unperformant, rerendering on every change. Uncontrolled components are more true to how DOM form fields work, but some things are more difficult to do with them. Controlled fields are fine with small forms, and for the really simple ones you can even use uncontrolled, but when you have large forms with fields that affect each other, both in terms of content and validation, it quickly becomes a real mess. It's not a reason not to adopt React, but I'd highly recommend getting to know both ways of implementing form fields and planning your implementation carefully.

0

u/rrrosenfeld Jun 16 '17

In that case, how am I supposed to use it for an edit form if I can't supply it with an initial value?

My point is that even if the company allows you to provide the initial values (it's a multiple options autocomplete) that doesn't allow the component to fully restore its state. While it's common for a component to allow one to set up the initial values I'm not aware of any that will allow you to set up the initial scroll position. It gets even worse if those values are populated through XHR which means re-rendering it will require yet another XHR request which, from a user experience point of view would impact the user severly. Imagine the user would scroll down, click on some option checkbox, and then suddenly the autocomplete box is closed and it won't be re-opened until the new XHR request finishes and after that the scroll position was completely lost. And I'm not exaggerating because I actually have a component like this implemented on top of jQuery UI autocomplete and I suspect I won't find another component that works this way among existing React components either (it's even more specialized to be honest, but it doesn't matter, as my general point is that sometimes we'll have to resort to third-party components we don't have control over and for which there aren't React replacements). Also, what happens if you want to move out of React at some point if React won't play nice with third-party components? It's important to have some hard boundaries so that it's up to the developer to decide what part to delegate to each stack.

3

u/[deleted] Jun 16 '17

I'm not sure I can take advice from someone who uses text-align: justify on mobile.

Kidding sorta. Interesting post in light of all the love for React these days.

1

u/rrrosenfeld Jun 16 '17

Yeah, I'm not into mobile development yet. I should probably learn it but since I don't currently need to support mobile devices at work, I'm currently focusing on other topics. I'm a full-stack developer, responsible not only for the backend and front-end but also deployment tools, servers orchestration, monitoring, and so on, so mobile support will remain low priority for quite some time I guess :)

3

u/[deleted] Jun 16 '17

I was just poking fun. Designer next to me and I just had conversation about text alignment. Exciting stuff on a Friday!

2

u/djungst Jun 17 '17

You should probably contact Facebook Instagram Walmart Nike the NFL MLS Firefox etc. I'm concerned that these could become large scale long-term projects. Someone should warn them. /s

3

u/rrrosenfeld Jun 17 '17

I'm not working for big companies like those. They could afford rewriting their code base many times as they have the resources to do that. I can't, so I can't blindly follow what the big ones are doing. I must respond for my own decisions. With regards to Facebook, since they are behind any decisions regarding React it's quite obvious they won't implement any changes that would break Facebook, so that doesn't make much sense. Anyway, the React team has already clarified that rerender the full application means calling render() on all components, it doesn't mean remounting all components. The diff reconciliation algorithm will still apply, and that's enough for me to be confident about React, since they understand the diff algorithm is too important to be considered just an implementation detail.

0

u/[deleted] Jun 17 '17

[deleted]

2

u/rrrosenfeld Jun 17 '17

I guess you are overestimating React ecosystem. I'm not sure Google is developing the "new-school" React based version of their maps component.

What you call old school is actually how most elements are created and shared in the JavaScript community as a whole. Do you think React will always exist with this hype? What will you do when the new greatest technology comes up and React becomes legacy code? When React community was emptied because people moved to the new cool library. Knockout.js had its hype moment. Rails had it too, jQuery and many other libraries and frameworks and languages. And it seems every year we hear about the new cool thing. Maybe some will say Vue is the new cool, it doesn't matter. What I mean is that one should always consider an incremental path to adopt some technology and an incremental path to move from that technology the next great thing. If React can only play well within the React community, then how are you going to move from React to the New Coolest Awesome Project when it comes the time? Or are you going to be stuck with React when the new interesting projects are no longer using it and it's rare to find people willing to work with React? Maybe you don't think about this because at this point React is the coolest project, but please don't be naive to think that this will always be the case. What are you going to do when you realize your huge code base needs to adapt from React to something else when you need to get great developers interested in working with you in your product?

I'm okay with the statement that things are just easier as long as you keep everything in React's domain as long as you provide a harder path that is reliable to play nice with non React components.

0

u/[deleted] Jun 17 '17

[deleted]

1

u/rrrosenfeld Jun 17 '17

I've updated the article after reading a response in that GitHub issue I created. It seems the reconciliation document meant calling "render()" for all components when they talk about rerendering the whole app, not about unmounting and remounting everything. This makes all the difference to me. This was the bit that was responsible for my concerns and now that it's clarified I'm fine with adopting React.

As you mentioned, Google didn't rewrite its maps component, but the React community uses a wrapper around it, as I was expecting, and that's perfectly fine. My concerns were if that situation would change in case the reconciliation algorithm would recreate all elements as I initially have understood from the documentation.

My misunderstanding was not on how React actually works. I had already understood that part. My concerns were about what guarantees React is giving me for its future. If React could decide to simply remount everything, then it wouldn't suite me. Fortunately this was just a misunderstanding.