914 points · by markthethomas · 9y ago · 338 comments
Very impressive improvement for a drop-in upgrade! Especially considering the previous version was not considered slow at all given the complexity.
Edit: I've got it in announcement:
React is 5.3 kb (2.2 kb gzipped), down from 20.7 kb (6.9 kb gzipped). react-dom is 103.7 kb (32.6 kb gzipped), down from 141 kb (42.9 kb gzipped). react + react-dom is 109 kb (34.8 kb gzipped), down from 161.7 kb (49.8 kb gzipped
15kb shaved in production builds. Thats quite nice!
(the 40kb are with core-js, will need to look for something smaller)
I recently inherited a moderately sized Redux app with over 1300 source files! It's not a trivial app but it's not a word processor or videogame, either...
I'll also post a link to the slides and livestream video for my React Boston talk this last weekend, where I talked about the Redux ecosystem and gave an overview of useful Redux libs that can help with various use cases: http://blog.isquaredsoftware.com/2017/09/presentation-might-... .
Happy to answer questions if y'all have any. :)
Community: This license is a legal nightmare. Something needs doing! Facebook: We have done something. Community: Try listening to both sentences next time.
Depending on the patent in question, it is possible to be on the hook even if you don't use React.
Close enough, I'd say.
> FB could still enforce patents regardless of license
It is widely accepted that the MIT license has an implicit patent grant.
Ultimately the React ecosystem would benefit from the attempt.
https://github.com/facebook/react-native/blob/master/PATENTS
That blog post mentions your featureFlag approach, the initial dogfooding and then the gradual rollout. I'd be very interested to hear on top of that:
1. How did you approach the rewrite on the coding side? What I mean is: Did you just say "Okay, let's start from scratch and use the lessons learned from v1?" Or did you use a specific approach along along the lines of: "Let's structure our code based on these principles and ...?"
2. When you started the rewrite, how did you know in advance and make sure that the rewrite would be faster and have a smaller code-size?
3. Was your focus during the rewrite on a cleaner code base (and the performance improvements followed automatically) or was your focus on speed right from the start?
4. Any other lessons learned during the rewrite? Patterns and approaches that helped/didn't help during the coding?
I always remember how the SQLite author Richard Hipp talked about being able to rewrite major chunks of the SQLite engine due to their test coverage. Their testing page currently says they have 730x more test code than core library code. https://www.sqlite.org/testing.html
Why remove the dist folder that was in prior releases?
Out of curiosity, did you switch to Rollup for the tree shaking optimizer, or for some other reason?
It's just not the way things are done in the JavaScript world.
Removing the need to wrap sibling elements in a single parent element is a welcome change.
I'd be interested in hearing some use cases for using the Portal API.
Lastly, the new licensing announced last week was fantastic news. I commented on last weeks thread, but I want to extend another round of compliments to Facebook and the React community as a whole for prompting this change. Props to them.
Portals are helpful when using content overflow in modals. For example, we have a modal which contains a form and that form has an autocomplete text box. When we render the autocomplete part, we need to render it outside of the modal, otherwise the overflow policy blocks the contents and does not allow the autocomplete are to appear over / outside of the modal.
The use of portals also make it easier to support screen readers through the aria tags by allowing the application to quickly block the background of the application and allow the screen reader to focus on the content presented to the user.
[0] https://github.com/StreakYC/react-float-anchor [1] https://github.com/StreakYC/react-menu-list
Smaller size and easier to use is a big win. Going with the MIT license puts a real bow on this release. Thank you to the React team.
My level of genuine respect for the way they do open source makes me feel a bit awkward about the fact that I dislike FB's primary product and mission. Especially given I make quite a bit of use of their code.
https://code.facebook.com/posts/300798627056246/relicensing-...
For example, I have one component that throws an exception. Previously, React would print the stack trace in console and carry on. Now, it destroys the entire DOM, spews three times as many errors, without even letting me see what the visual result was of that error.
To debug, I need to write a componentDidCatch method in the parent class of the erroring class, because the root componentDidCatch error handler can't reconstruct the DOM, because of that one sub-sub-sub-sub-sub-child state error.
Even after writing all this new code, React still removes the erroring element from the DOM, leaving ambiguous what its impact was on the end-user experience.
Does anyone else feel that the new version of React is fault-intolerant?
While I do enjoy Java, I would argue that Null-Pointer-Exception hell does not belong in JS scripting.
While this is more of a lateral move, it's an important one. Before, an error during render left your app in an undefined, potentially unstable state. Then, you might find some unrelated junk errors in your Sentry or whatever you use, and on top of that the user is wondering why when they click nothing happens.
Now, you can recover from an error completely, even if you don't have control over the code running in other components. That's a big deal when you might want to have third party components or something to that effect.
It's a bit hard to reply to a comment here with technical points :-) The valuable discussion will get buried.
As explained in the blog post about error handling, the recommendation is to add error boundaries in "strategic places" (e.g. around main UI blocks) so that they fail gracefully. But it requires some design input on how it should work. It means error states should be part of your app's design, and I understand this might seem unusual.
Still, let's please continue this in the issue tracker.
I'm not sure how I feel about this change, but at least there's an escape hatch.
class MyButton extends MyBaseComponent {
// Render a button
}Class MyBaseComponent extends React.Component {
// Include error handling lifecycle hook here
}Congrats on shipping!
2) I'm surprised no one has mentioned it so far -- but this release uses the new fiber architecture - I saw the video presentation about fiber and think it could really help in terms of performance
Overall reduction of container elements is a huge plus. I'll be happy if I can start thinning out the giant christmas tree that react tends to create, even if it's not a huge performance gain, this will improve debugging immensely.
These days it seems you need to download half the internet for even the most trivial uses, never mind using the half-finished ersatz JS du jour. And yes, I know that it gets compiled to a tiny thing worth of the IOCCC for the end user, but sometimes even us programmers want an easy setup. It seems the only framework that still has a good story regarding that is Mithril…
https://facebook.github.io/react/docs/react-without-es6.html
https://facebook.github.io/react/docs/react-without-jsx.html
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>Looks like Mithril code (https://mithril.js.org/) if you alias React.createElement to a short function name.
I learned Mithril before React, and kinda think it's a better learning experience to learn the simple way like this first, and then add build tools, Redux, JSX later (if you choose to).
See also: the docs
Crazy to see such a robust, mature framework still improving so much. Can't wait to upgrade!
I'm also glad to see the switch to MIT license if only to put this patents controversy behind us. Now curious to see what happens with GraphQL...
https://medium.com/@leeb/relicensing-the-graphql-specificati...
It's also more compatible (which, tbh, is actually more important practically) and that was the main problem with the whole Apache thing.
I tried to make a set of React components that worked like a table (with rows and columns) using CSS grid in React 15, but it was nearly impossible to do. For the record, the reason I didn't just use a table was because the grid system allows for more expressive sizing of columns than plain tables.
Due to the way implied patent licenses work, if Facebook distributes React without explicit restrictions or conditions, they're automatically granting a license to any patents that are inherently infringed by React itself. This is a pretty well-established area of US patent law, see e.g. https://www.wilmerhale.com/pages/publicationsandnewsdetail.a...
if fb actually wanted to prevent someone from using react, they could just revoke the copyright grant.
Before the license change I was looking around for other options, but now I can continue to enjoy front-end development with this awesome library for at least a few years more. For me this definitely helps fighting JS fatigue not having to change to another framework.
Multiple render return types and portals both solve some annoying situations that can come up.
Fantastic release nevertheless!
I strongly doubt I'm the only one there.
or Set: http://kangax.github.io/compat-table/es6/#test-Set
I will probably continue to transpile for the moment (till I can check everything).
There is also polyfill.io which would only polyfill old browsers.
You could also include polyfills conditionally by sniffing the user agent.
I'm also fairly sure there exist smaller polyfills for Map and Set. We should probably look for them and suggest them instead.
That's a pretty good idea, actually. Thanks for the suggestion!
The author creates a library, piece by piece, which introduces the same concepts. Makes it much easier to jump into the 'real' framework.
After that, I keep a big list of links to high-quality tutorials and articles on React, Redux, and related topics, at https://github.com/markerikson/react-redux-links . Specifically intended to be a great starting point for anyone trying to learn the ecosystem, as well as a solid source of good info on more advanced topics. It includes links for learning core Javascript (ES5), modern Javascript (ES6+), React, Redux, and much more. I also published an "Intro to React (and Redux)" presentation at http://blog.isquaredsoftware.com/2017/02/presentation-react-... , which is a good overview of the basic concepts for both React and Redux.
Also, the Reactiflux chat channels on Discord are a great place to hang out, ask questions, and learn. The invite link is at https://www.reactiflux.com .
https://github.com/gothinkster/react-redux-realworld-example...
- whether or not this really uses best practices?
- leverages React to the fullest?
The more important thing to decide is whether the development model of React is suitable for your needs.
But one caveat is that if you need to hydrate serverside-rendered React markup for clientside use, that will add at least some small performance penalty. And you will also want to pass in props data that matches as closely as possible between the client and server, which means that your base page will need to include some serialized version of the data that should be passed in as props to the component(s) you serverside-rendered and want to hydrate. If this is a large chunk of data, there could be negative SEO impact if it is placed above meaningful content in the page or if the time to download it delays complete load of the page.
I work on Asia's largest real-estate portals and we use React 16 and SSR. If you want to talk more about what we've done, contact me: swen [at] sectorlabs.ro
The crawler would read it no differently.
> Instead of ignoring unrecognized HTML and SVG attributes, React will now pass them through to the DOM.
Does that mean we can start using "class" instead of "className"?
[1]: https://developer.mozilla.org/en-US/docs/Web/API/Element/cla...
[2]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelEl...
const { class } = props
Which is very common and deeply confusing.So even though "class" will technically work now, it will still warn, and ask that you use "className".
(And officially supporting both would make it confusing for third party components since each would have to also support both.)
> Note: always use the canonical React naming for all supported attributes.
Looking through the examples, it looks like non-string class values will be converted to strings, while non-string className values will be ignored (with a warning).
[0] https://facebook.github.io/react/blog/2017/09/08/dom-attribu...
What you really want with streaming is whenever rendering is blocked by something asynchronous, like a database request, that whatever HTML is finished can be flushed out. React could support real streaming in the future, but would likely require some new API.
Anyways, the sentence from the article "start sending bytes to the client faster" isn't factually true, it doesn't send it out any faster than renderToString would.
Our new architecture makes it easier to implement the type of async data fetching you describe and we'd like to add it in the future.
We've added support for returning strings, too:
[…]
See the full list of supported return types.
Why not express that with… ehm… proper types?!? You know… like those used by Flow or TypeScript.React is idiomatic javascript. Vue is it's own quirky thing that doesn't feel anything at all like Javascript to me.
At the end of the day, I think that calling something idiomatic is subjective and so, varies from people to people.
*: to be clear, my point is many people use JSX with React because it feels idiomatic (I manipulate HTML/DOM, so why not just write with HTML-like syntax?) but it is not idiomatic to JavaScript and I don't think the other React APIs are that nice to use. If I didn't use JSX with React, I'd tend to use other framework because, in my opinion, they make more sense.
When I look at the guide and I see stuff like this:
<div id="app-2">
<span v-bind:title="message">
Hover your mouse over me for a few seconds
to see my dynamically bound title!
</span>
</div>
I get immediately queasy about what Vue is doing. Does it parse the HTML? How exactly does scoping work? What sort of special classes and expressions can I put in the span, and in what manner will they be evaluated?In contrast, React is a JS library, and works like any other. JSX is weird for the first minute, but it's a very light transformation to the underlying JS, to the point where when I write it I can mentally see what JS functions I'm invoking, which therefore helps me understand all those things I mentioned before like scoping rules, what this will refer to, etc.
If you know plain javascript you know half of what makes react. The API surface usually consists of a single function: render. The rest are 3-4 class lifecycles, setState, a few jsx semantics and that's it. You solve problems in the same way you always solved them, there is nothing to re-learn and you don't bend to the framework.
Go ahead and re-create this in Vue, tell me what you're doing is easier:
import timestamp from 'time-stamp'
const Header = props => <h1>{props.text}</h1>
const Main = () => <Header text={timestamp()} />
ReactDom.render(<Main />, document.querySelector('#app'))
A beginner could blink at this once and start making simple apps blindfolded. A Vue beginner would be stuck even trying to create components, not to mention compose them, or pass props, or access the import. Every single step on top of this has to be fished out of the documentation: children, conditions, loops, filters, etc.Once you get rolling both of them are good but it's no easy task to start-up a React project on your own. You need a lot libraries, have to twiddle with immutability which is no piece of cake with JS and be constantly aware of small quirks like keys when looping jsx-elements, className instead of class, how to add css preprocessor, using setState instead of directly assigning to it with the constant farce with deeply nested Object.assigning oh such fun.
React tries to make the world a better place with more theoretical approach while Vue focuses on tried-and-true methods that work and are straight-forward for everyone with a little experience in programming. (v-if might not be pretty but it beats JSX conditional) Granted modern frontend development has a lot of different things to be aware of that make it bit difficult for beginners but IMO Vue makes it a lot more simpler and productive. Some things I wish might be better like the ecosystem but oh well. Overall I'm happier and the only problem is having to fight off overly smug React-developers who have rubbed their egos so hard that they aren't able to even think about better solutions anymore.
• lifecycle method names: mounted vs componentDidMount
• proptypes: builtin vs `import PropTypes from 'prop-types'`
• component creation: basic JS object vs ES6 class extending `React.component`
Please don't spread misinformation because you prefer one way of writing frontend apps to another. React is better at complex apps, and Vue has a simpler API that many find easier to memorize.
It's rude to insult other commenters by saying "A beginner could blink at this once and start making simple apps blindfolded." I think you're being hyperbolic, but it comes off as condescending.
Frontend is hard. No one "blinks at this once" and learns how to build component-based layouts with view, data, and logic. Please be nice.
function Header(props) {
return <h1>{props.text}</h1>;
}
function Main() {
return <Header text={new Date()}/>;
}
ReactDom.render(<Main />, document.querySelector('#app'))Usually not a problem but some issues on Github are in "Chinese" (not sure if Mandarin or Cantonese sorry) so not very helpful.
If you want more choices for those libs (at the cost of potentially more dependency update hell) React is great and more popular.
Admittedly there are tooling gaps with projects like Polymer, but these are being addressed. YouTube.com is already in production built with Polymer.
So just leaving this comment here to encourage everyone to rethink the framework defaults of React/Vue in 2017.
- React uses JSX and JS logic for render methods. Vue usually uses templates, although JSX is also supported.
- While React _can_ be used as a plain script tag, it's usually compiled as part of a build step. Vue can be compiled, but it seems friendlier to the "drop-in script tag" approach.
- The Vue community values official integrated addons for routing and state management. The React community prefers a "pick-and-choose your own adventure" approach.
- Since React has been around longer, there's probably more React components and related libraries available
- A larger percentage of the Vue community is located in China
The best comparison of Angular, React, and Vue I've seen thus far is at https://medium.com/unicorn-supplies/angular-vs-react-vs-vue-... . It lays out a lot of the similarities and differences in a fair way, and gives some suggestions for why you might pick one over the others.
I hate that facebook has basically made a new version of javascript.
I don't like facebook as a company and prefer software that is made by people who aren't told "go make this" by their boss.
Facebook has thrown out all of the previous approaches and just started again. This is good for things like the virtual dom, as the alternatives never worked to begin with, but bad for things like html templates, which have worked fine.
The problem with combining javascript and html (JSX) is that the javascript gets in the way and you can't really see what the component looks.
If there's any huge company that gives engineers relative freedom to build what they want, Facebook is definitely it.
I'd recommend react over Vue any day of the week, to answer ops question. Vue.js is everything I hated about Angular. String based dependency injection, bizzare attibute syntax, highly opinionated.
React is everything I love about javascript. Functional, fast, and with an easy to reason about API.
Opinionated: React is a library written for a language that is not JavaScript (the first prototype was written in OCaml). It demands immutability, which JS has no native support for. it wants you to use FP, but JS natively has little support for FP both in its standard library and syntax. FP only looks good in JS if you've never used a real FP language.
DSL: JSX is a DSL - I can't remember the last time I've seen someone use && as a poor man's if statement, or ternary statements dozens of lines long until I started writing JSX. JSX is neither idiomatic JavaScript nor HTML.
Fast: Performance benchmarks (which admitted are flawed as they can't capture real-world usage) show that React and Vue have similar rendering speeds. Vue's computed property dependency tracing means that a lot of the performance optimizations which require manual work to enable in React (manually memoize expensive computation, shouldComponentUpdate, PureComponent etc.) are handled automatically by the framework.
I learned react before vue and found it great compared to angular but lately I've been using vue. It is quickier and neater with the bizzare syntax and lighter overall.
With the latest release I have the urge to go back.
I guess will stand out and prosper the one with the largest adoption (to this point, React). All this looks exactly like the old jQuery vs Mootools vs Prototype debate 10 years ago.
History repeats itself.
You can use Vue as plain JS. You don't lose much by abandoning the single file components.
> React is just Javascript.
Except the entire ecosystem is designed to steer you toward JSX which is not "just Javascript".
The opposite of an opinionated framework is an opinionated user-base.
You ask what should I use for X (routing, state management, HTTP requests, etc, etc) and every react developer gives you a different combination of answers, and you have no good way to figure out which combination is the best.
I much rather the framework answer those questions for me so I can focus on getting shit done and actually building the thing I want to build.
This release is MIT license release after they start losing in front of more real open source frameworks like vue. Better late than sorry facebook!