Lessons from migrating a large codebase to React 16
blog.discordapp.com
blog.discordapp.com
I do full-stack javascript for my income, but have reached the point of not enjoying coding anymore because of this continuous change of ideas forced upon me. Why do I need to change from React.createClass to ES6 classes, from ESxx to Typescript or Flow, from React to Vue, from callbacks to Promises, from Flux to Redux, or from any idea to the next hyped idea?
When will people start to realise that this new method or technology they're implementing is deprecated already?
There is no end to this and I actually hate it as it destroys my passion for coding. I code to create things, not to continuously change what's created already and works fine.
As soon as I find a cool C job I'll definitely leave this mad house.
And I do understand why - it's just quite pathetic to see all of that being done for no practical reason.
Those times were painful, now it’s much much better.
Javascript has more library churn, but the alternative is being stuck on something like BOOST. ugh.
People hate it because there's no practical reason why we're forced to use JavaScript in order to program - and most of the people who are productive are probably using some sort of variation on ECMAScript that makes it bearable anyway.
I'm not sure how you came to this conclusion. JavaScript is the common language for two major platforms (browsers, Node.js) and many smaller ones (Cocos2d, enyo JS, Espruino, GNOME Shell, Kinoma XS6, NativeScript, Weex, etc.).
- browsers: used since the 90s because there's no other alternative
- node.js: created because JS is used in browsers and it's easier to write code in a single language for browsers and servers
- Cocos2d: you're clearly lying as the only place where JS is mentioned is Cocos2d-html, as there's again - no alternative
- enyo JS: again, used clearly due to the fact that modern - browsers are available for all of the modern platforms
- Weex, NativeScript: typical "native app" libraries which use a webkit pane for most of the rendering, again - javascript here is circumstantial since you can't choose anything else
- GNOME Shell, Kinoma XS6: OK. These are the only ones that make any sort of a strong point in your message; but as far as it goes - modern linux distros are moving to Python for systems programming anyway. So learning JS here is a miss.
Who's forcing you to do this? All of these old things still work. If your team/job are forcing you to do this, then why is the problem not with them, rather than the language/ecosystem?
The old things likely have bugs. And most libraries don't spend a lot of time patching old versions (why should they, it's free software). The longer time passes the less and less likely there will be bug/security patches. So if you want to own those bugs/security issues, sure, stay behind to avoid the cost of upgrading.
There are good reasons for those changes. As you are a full stack JS developer, I'd recommend you dig deeper and find out why. It might alleviate your frustration.
C has been around for 45 years.
I'm sure things will be relatively stable 24 years from now in terms of web development, but then there will be a new medium for writing code with massive churn in commonly-used libraries and techniques.
A need to learn new things in a young language will never die.
Even C++, which is "only" 34 years old is experiencing massive changes to its syntax and common practices.
And if it's not for changes sake it becomes some weird squabble over how to best handle X, and we wind up with numerous ways to do so. At that point we have to take a bet as to which approach we think will be supported and pushed forward in the future (i.e. promises? generators? callbacks? async/await?). If we're right? Great. If we're wrong. Well, let's hope the libs we're using keep support for the way we've written our code.
On the other hand, it does finally seem like React has one the shake out of front-end frameworks. While it's ever changing, it does seem like it's longevity will be far greater than most front-end frameworks of the past. And it does solve a lot of the BS that one would deal with if they didn't have a framework to leverage.
But yeah.. The danger with front-end development is how fast the knowledge depreciates.
edit: by danger, I more mean difficulty of keeping up with.
npm install --save react-router@3
which will add "react-router": "^3.2.0" to your package.json.We had a lot of pain doing this rewrite ourselves, but I must say it was worth it in the end.
Unfortunately, this is major version 4, so who is to say that the repo maintainers don't find an even better way to do it in six months, prompting a version 5 and so on...
The only things we're looking at for another major version are some changes to the default API behaviors (making `exact` default to true, for instance). There are potentially some changes to path matching, but that's being driven by path-to-regexp, not our own development.
Yes, 4.0 was a big change, but a necessary one. Now that we're in a great place, we plan on keeping things relatively stable indefinitely. Pencils down, as it were. Outside of some major upstream change with React itself, future versions will be more evolutionary than revolutionary.
> Yes, 4.0 was a big change, but a necessary one. Now that we're in a great place, we plan on keeping things relatively stable indefinitely.
Out of curiosity, was this also the thinking when 3.x was released?
Or when 3.x was released was there more of a philosophy that the problem space was still being explored, and major design changes were still possible and acceptable?
It seems like a bizarre decision to spend time migrating to a new system / tool that provides no immediate benefits. A thorough refactoring of their codebase seems like it would have been a better use of engineering time.
If you're all-in on React (as Discord is), the upgrade to React 16 is inevitable. Given that, upgrading now makes sense.
At a previous workplace we had to go from React 0.13 to React 15. We had to re-write, fork and patch, or get rid of entire third-party libraries. There are no stepping stones in the JS ecosystem that let you do gradual updates if you are several versions behind.
Constantly trying to keep up either needs a larger team to keep up and do those things, or you compromise somewhere.
I have had my complaints in the past when I don't touch an Ember app for a year, but for the most part, they provide ample "stepping stones" to bring the community along without too much anxiety.
Literally the only reason a migration could be painful if you're on the latest version of 15 before upgrading is that your code or your dependencies are using deprecated APIs, which the latest version of React 15 will helpfully warn about. You can fix that before migrating.
My eyes kinda got wide when I read that part.
React has pretty thorough deprecation warnings on the final releases of each major version about what is going away with the next major. Once you've gotten rid of all deprecation warnings, migrating to the next major should be uneventful.
This means you can take your sweet time when upgrading, migrating your code without breaking your entire application.
Yeah that’s what I’m saying :)
What really happened is that they switched from createClass to ES6 classes. ES6 class methods have implicit 'use strict' mode.
They weren't forced to switch to ES6 classes if they didn't want to. createClass is on npm (create-react-class) and still works fine.
It's only a bizarre decision if you approach it exclusively from a short-term view.
"Right now, it isn’t clear that the advantages are significant" - so why invest the time in doing so? Why not use a tried and tested version until such times as you either need features from the newer version or some third party dependencies you absolutely need require it?
This is one of reasons to limit third party libraries you use along with React. Every dependency comes at cost. If you use React and React-Foo, React-Bar, React-Baz and dozen of other React based additional libraries, then upgrading all/troubleshooting can be painful. As it was ("We ran into an error which took us 2 days to track down to a library, ...")
The great thing about web components is that they cannot make breaking changes now that it's been implemented by multiple libraries. It's stamped in time forever.
If there ever comes a time where the existing API can't be updated any more because of mistakes or whatever, they'll just make a new API and your existing code will continue to work, forever. Look at XMLHttpRequest and fetch(). Did you have to migrating your XHR code over to fetch()? No, it works fine, and always will.
There's definitely progress, but an older Polymer 1.0 app of mine is painfully slow on everything but Chrome.
Maybe chrome is better at rendering your application structure?
https://mobile.twitter.com/winkler1/status/91158079802491289...
I also agree with one of the comments in reply who linked to "How to win in web framework benchmarks"[2]
Unlike, say, benchmarks for performing hash functions on graphics cards or frame rates on certain hardware the units of work being tested on web benchmarks very rarely reflect the units of work used in your own systems
In performance and security critical components we write benchmark-*.{ts,js} tests and track performance of real-world components.
At the moment in the mocha world there is no good way to keep a history of results, so we tend to copy+paste them as code comments (noticed this in a lot of projects) - but it wouldn't be difficult to write a storage backend here in sqlite or similar and store it in the same way coverage reports are
If you're doing comparisons on modules you use - you can include them as devDependancies. This also forces you to abstract away your dependancies which is often a good thing.
[0] https://reactjs.org/docs/react-dom-server.html#rendertonodes...
[1] https://github.com/facebook/react/issues/6420
[2] https://medium.com/@localvoid/how-to-win-in-web-framework-be...
We are using Preact for a small mobile site, so I’m wondering if it’s worth switching.
IIRC, preact is faster by the virtue of being smaller so it's loads faster, but React is actually more efficient when updating the state, in some ways.
The initial improvement that Fiber gives is about splitting up the rendering process into bite-size chunks so that the determination of what does need to change doesn't block the main thread. The rewrite of the internals also made the codebase more maintainable, and gave them a chance to implement often-requested features like returning strings or arrays from render(), as well as implementing error boundaries.
This rewrite is a bit pointless to me, increase the complexity of using React on the long term (before, you could count on synchronous rendering having predictive results) and is just a hack to spread the cost of react's rendering across multiple frames. If anything your site will take longer to render now that it's async :)
I'm wary of progressively rendered sites (like Facebook) where buttons are rendered but don't work for the first few hundred milliseconds or seconds anyway. Complex websites can already defer the rendering of their most expensive parts (e.g google maps, etc); baking it in the framework sounds like engineers who had too much free time to me :p