mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
1478 lines
187 KiB
XML
1478 lines
187 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||
<channel>
|
||
<title>React</title>
|
||
<description>A JavaScript library for building user interfaces</description>
|
||
<link>https://facebook.github.io/react</link>
|
||
<atom:link href="https://facebook.github.io/react/feed.xml" rel="self" type="application/rss+xml" />
|
||
|
||
<item>
|
||
<title>React v16.0</title>
|
||
<description><p>We&#39;re excited to announce the release of React v16.0! Among the changes are some long-standing feature requests, including <a href="#new-render-return-types-fragments-and-strings"><strong>fragments</strong></a>, <a href="#better-error-handling"><strong>error boundaries</strong></a>, <a href="#portals"><strong>portals</strong></a>, support for <a href="#support-for-custom-dom-attributes"><strong>custom DOM attributes</strong></a>, improved <a href="#better-server-side-rendering"><strong>server-side rendering</strong></a>, and <a href="#reduced-file-size"><strong>reduced file size</strong></a>.</p>
|
||
|
||
<h3>New render return types: fragments and strings</h3>
|
||
|
||
<p>You can now return an array of elements from a component&#39;s <code>render</code> method. Like with other arrays, you&#39;ll need to add a key to each element to avoid the key warning:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="c1">// No need to wrap list items in an extra element!</span>
|
||
<span class="k">return</span> <span class="p">[</span>
|
||
<span class="c1">// Don&#39;t forget the keys :)</span>
|
||
<span class="o">&lt;</span><span class="nx">li</span> <span class="nx">key</span><span class="o">=</span><span class="s2">&quot;A&quot;</span><span class="o">&gt;</span><span class="nx">First</span> <span class="nx">item</span><span class="o">&lt;</span><span class="err">/li&gt;,</span>
|
||
<span class="o">&lt;</span><span class="nx">li</span> <span class="nx">key</span><span class="o">=</span><span class="s2">&quot;B&quot;</span><span class="o">&gt;</span><span class="nx">Second</span> <span class="nx">item</span><span class="o">&lt;</span><span class="err">/li&gt;,</span>
|
||
<span class="o">&lt;</span><span class="nx">li</span> <span class="nx">key</span><span class="o">=</span><span class="s2">&quot;C&quot;</span><span class="o">&gt;</span><span class="nx">Third</span> <span class="nx">item</span><span class="o">&lt;</span><span class="err">/li&gt;,</span>
|
||
<span class="p">];</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>In the future, we&#39;ll likely add a special fragment syntax to JSX that doesn&#39;t require keys.</p>
|
||
|
||
<p>We&#39;ve added support for returning strings, too:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="s1">&#39;Look ma, no spans!&#39;</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p><a href="/react/docs/react-component.html#render">See the full list of supported return types</a>.</p>
|
||
|
||
<h3>Better error handling</h3>
|
||
|
||
<p>Previously, runtime errors during rendering could put React in a broken state, producing cryptic error messages and requiring a page refresh to recover. To address this problem, React 16 uses a more resilient error-handling strategy. By default, if an error is thrown inside a component&#39;s render or lifecycle methods, the whole component tree is unmounted from the root. This prevents the display of corrupted data. However, it&#39;s probably not the ideal user experience.</p>
|
||
|
||
<p>Instead of unmounting the whole app every time there&#39;s an error, you can use error boundaries. Error boundaries are special components that capture errors inside their subtree and display a fallback UI in its place. Think of error boundaries like try-catch statements, but for React components.</p>
|
||
|
||
<p>For more details, check out our <a href="/react/blog/2017/07/26/error-handling-in-react-16.html">previous post on error handling in React 16</a>.</p>
|
||
|
||
<h3>Portals</h3>
|
||
|
||
<p>Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="c1">// React does *not* create a new div. It renders the children into `domNode`.</span>
|
||
<span class="c1">// `domNode` is any valid DOM node, regardless of its location in the DOM.</span>
|
||
<span class="k">return</span> <span class="nx">ReactDOM</span><span class="p">.</span><span class="nx">createPortal</span><span class="p">(</span>
|
||
<span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">children</span><span class="p">,</span>
|
||
<span class="nx">domNode</span><span class="p">,</span>
|
||
<span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>See a full example in the <a href="/react/docs/portals.html">documentation for portals</a>.</p>
|
||
|
||
<h3>Better server-side rendering</h3>
|
||
|
||
<p>React 16 includes a completely rewritten server renderer. It&#39;s really fast. It supports <strong>streaming</strong>, so you can start sending bytes to the client faster. And thanks to a <a href="#reduced-file-size">new packaging strategy</a> that compiles away <code>process.env</code> checks (Believe it or not, reading <code>process.env</code> in Node is really slow!), you no longer need to bundle React to get good server-rendering performance.</p>
|
||
|
||
<p>Core team member Sasha Aickin wrote a <a href="https://medium.com/@aickin/whats-new-with-server-side-rendering-in-react-16-9b0d78585d67">great article describing React 16&#39;s SSR improvements</a>. According to Sasha&#39;s synthetic benchmarks, server rendering in React 16 is roughly <strong>three times faster</strong> than React 15. &quot;When comparing against React 15 with <code>process.env</code> compiled out, there’s about a 2.4x improvement in Node 4, about a 3x performance improvement in Node 6, and a full 3.8x improvement in the new Node 8.4 release. And if you compare against React 15 without compilation, React 16 has a full order of magnitude gain in SSR in the latest version of Node!&quot; (As Sasha points out, please be aware that these numbers are based on synthetic benchmarks and may not reflect real-world performance.)</p>
|
||
|
||
<p>In addition, React 16 is better at hydrating server-rendered HTML once it reaches the client. It no longer requires the initial render to exactly match the result from the server. Instead, it will attempt to reuse as much of the existing DOM as possible. No more checksums! In general, we don&#39;t recommend that you render different content on the client versus the server, but it can be useful in some cases (e.g. timestamps).</p>
|
||
|
||
<p>See the <a href="/react/docs/react-dom-server.html">documentation for <code>ReactDOMServer</code></a> for more details.</p>
|
||
|
||
<h3>Support for custom DOM attributes</h3>
|
||
|
||
<p>Instead of ignoring unrecognized HTML and SVG attributes, React will now <a href="https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html">pass them through to the DOM</a>. This has the added benefit of allowing us to get rid of most of React&#39;s attribute whitelist, resulting in reduced file sizes.</p>
|
||
|
||
<h3>Reduced file size</h3>
|
||
|
||
<p>Despite all these additions, React 16 is actually <strong>smaller</strong> compared to 15.6.1!</p>
|
||
|
||
<ul>
|
||
<li><code>react</code> is 5.3 kb (2.2 kb gzipped), down from 20.7 kb (6.9 kb gzipped).</li>
|
||
<li><code>react-dom</code> is 103.7 kb (32.6 kb gzipped), down from 141 kb (42.9 kb gzipped).</li>
|
||
<li><code>react</code> + <code>react-dom</code> is 109 kb (34.8 kb gzipped), down from 161.7 kb (49.8 kb gzipped).</li>
|
||
</ul>
|
||
|
||
<p>That amounts to a combined <strong>32% size decrease compared to the previous version (30% post-gzip)</strong>.</p>
|
||
|
||
<p>The size difference is partly attributable to a change in packaging. React now uses <a href="https://rollupjs.org/">Rollup</a> to create flat bundles for each of its different target formats, resulting in both size and runtime performance wins. The flat bundle format also means that React&#39;s impact on bundle size is roughly consistent regardless of how your ship your app, whether it&#39;s with Webpack, Browserify, the pre-built UMD bundles, or any other system.</p>
|
||
|
||
<h3>MIT licensed</h3>
|
||
|
||
<p><a href="https://code.facebook.com/posts/300798627056246/relicensing-react-jest-flow-and-immutable-js/">In case you missed it</a>, React 16 is available under the MIT license. We&#39;ve also published React 15.6.2 under MIT, for those who are unable to upgrade immediately.</p>
|
||
|
||
<h3>New core architecture</h3>
|
||
|
||
<p>React 16 is the first version of React built on top of a new core architecture, codenamed &quot;Fiber.&quot; You can read all about this project over on <a href="https://code.facebook.com/posts/1716776591680069/react-16-a-look-inside-an-api-compatible-rewrite-of-our-frontend-ui-library/">Facebook&#39;s engineering blog</a>. (Spoiler: we rewrote React!)</p>
|
||
|
||
<p>Fiber is responsible for most of the new features in React 16, like error boundaries and fragments. Over the next few releases, you can expect more new features as we begin to unlock the full potential of React.</p>
|
||
|
||
<p>Perhaps the most exciting area we&#39;re working on is <strong>async rendering</strong>—a strategy for cooperatively scheduling rendering work by periodically yielding execution to the browser. The upshot is that, with async rendering, apps are more responsive because React avoids blocking the main thread.</p>
|
||
|
||
<p>This demo provides an early peek at the types of problems async rendering can solve:</p>
|
||
|
||
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Ever wonder what &quot;async rendering&quot; means? Here&#39;s a demo of how to coordinate an async React tree with non-React work <a href="https://t.co/3snoahB3uV">https://t.co/3snoahB3uV</a> <a href="https://t.co/egQ988gBjR">pic.twitter.com/egQ988gBjR</a></p>&mdash; Andrew Clark (@acdlite) <a href="https://twitter.com/acdlite/status/909926793536094209">September 18, 2017</a></blockquote>
|
||
|
||
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
|
||
|
||
<p><em>Tip: Pay attention to the spinning black square.</em></p>
|
||
|
||
<p>We think async rendering is a big deal, and represents the future of React. To make migration to v16.0 as smooth as possible, we&#39;re not enabling any async features yet, but we&#39;re excited to start rolling them out in the coming months. Stay tuned!</p>
|
||
|
||
<h2>Installation</h2>
|
||
|
||
<p>React v16.0.0 is available on the npm registry.</p>
|
||
|
||
<p>To install React 16 with Yarn, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">yarn add react@^16.0.0 react-dom@^16.0.0
|
||
</code></pre></div>
|
||
<p>To install React 16 with npm, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">npm install --save react@^16.0.0 react-dom@^16.0.0
|
||
</code></pre></div>
|
||
<p>We also provide UMD builds of React via a CDN:</p>
|
||
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt">&lt;script </span><span class="na">crossorigin</span> <span class="na">src=</span><span class="s">&quot;https://unpkg.com/react@16/umd/react.production.min.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
|
||
<span class="nt">&lt;script </span><span class="na">crossorigin</span> <span class="na">src=</span><span class="s">&quot;https://unpkg.com/react-dom@16/umd/react-dom.production.min.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
|
||
</code></pre></div>
|
||
<p>Refer to the documentation for <a href="/react/docs/installation.html">detailed installation instructions</a>.</p>
|
||
|
||
<h2>Upgrading</h2>
|
||
|
||
<p>Although React 16 includes significant internal changes, in terms of upgrading, you can think of this like any other major React release. We&#39;ve been serving React 16 to Facebook and Messenger.com users since earlier this year, and we released several beta and release candidate versions to flush out additional issues. With minor exceptions, <strong>if your app runs in 15.6 without any warnings, it should work in 16.</strong></p>
|
||
|
||
<h3>New deprecations</h3>
|
||
|
||
<p>Hydrating a server-rendered container now has an explicit API. If you&#39;re reviving server-rendered HTML, use <a href="/react/docs/react-dom.html#hydrate"><code>ReactDOM.hydrate</code></a> instead of <code>ReactDOM.render</code>. Keep using <code>ReactDOM.render</code> if you&#39;re just doing client-side rendering.</p>
|
||
|
||
<h3>React Addons</h3>
|
||
|
||
<p>As previously announced, we&#39;ve <a href="/react/blog/2017/04/07/react-v15.5.0.html#discontinuing-support-for-react-addons">discontinued support for React Addons</a>. We expect the latest version of each addon (except <code>react-addons-perf</code>; see below) to work for the foreseeable future, but we won&#39;t publish additional updates.</p>
|
||
|
||
<p>Refer to the previous announcement for <a href="/react/blog/2017/04/07/react-v15.5.0.html#discontinuing-support-for-react-addons">suggestions on how to migrate</a>.</p>
|
||
|
||
<p><code>react-addons-perf</code> no longer works at all in React 16. It&#39;s likely that we&#39;ll release a new version of this tool in the future. In the meantime, you can <a href="/react/docs/optimizing-performance.html#profiling-components-with-the-chrome-performance-tab">use your browser&#39;s performance tools to profile React components</a>.</p>
|
||
|
||
<h3>Breaking changes</h3>
|
||
|
||
<p>React 16 includes a number of small breaking changes. These only affect uncommon use cases and we don&#39;t expect them to break most apps.</p>
|
||
|
||
<ul>
|
||
<li>React 15 had limited, undocumented support for error boundaries using <code>unstable_handleError</code>. This method has been renamed to <code>componentDidCatch</code>. You can use a codemod to <a href="https://github.com/reactjs/react-codemod#error-boundaries">automatically migrate to the new API</a>.</li>
|
||
<li><code>ReactDOM.render</code> and <code>ReactDOM.unstable_renderIntoContainer</code> now return null if called from inside a lifecycle method. To work around this, you can use <a href="https://github.com/facebook/react/issues/10309#issuecomment-318433235">portals</a> or <a href="https://github.com/facebook/react/issues/10309#issuecomment-318434635">refs</a>.</li>
|
||
<li><code>setState</code>:
|
||
|
||
<ul>
|
||
<li>Calling <code>setState</code> with null no longer triggers an update. This allows you to decide in an updater function if you want to re-render.</li>
|
||
<li>Calling <code>setState</code> directly in render always causes an update. This was not previously the case. Regardless, you should not be calling setState from render.</li>
|
||
<li><code>setState</code> callbacks (second argument) now fire immediately after <code>componentDidMount</code> / <code>componentDidUpdate</code> instead of after all components have rendered.</li>
|
||
</ul></li>
|
||
<li>When replacing <code>&lt;A /&gt;</code> with <code>&lt;B /&gt;</code>, <code>B.componentWillMount</code> now always happens before <code>A.componentWillUnmount</code>. Previously, <code>A.componentWillUnmount</code> could fire first in some cases.</li>
|
||
<li>Previously, changing the ref to a component would always detach the ref before that component&#39;s render is called. Now, we change the ref later, when applying the changes to the DOM.</li>
|
||
<li>It is not safe to re-render into a container that was modified by something other than React. This worked previously in some cases but was never supported. We now emit a warning in this case. Instead you should clean up your component trees using <code>ReactDOM.unmountComponentAtNode</code>. <a href="https://github.com/facebook/react/issues/10294#issuecomment-318820987">See this example.</a></li>
|
||
<li><code>componentDidUpdate</code> lifecycle no longer receives <code>prevContext</code> param. (See <a href="https://github.com/facebook/react/issues/8631">#8631</a>)</li>
|
||
<li>Shallow renderer no longer calls <code>componentDidUpdate</code> because DOM refs are not available. This also makes it consistent with <code>componentDidMount</code> (which does not get called in previous versions either).</li>
|
||
<li>Shallow renderer does not implement <code>unstable_batchedUpdates</code> anymore.</li>
|
||
</ul>
|
||
|
||
<h3>Packaging</h3>
|
||
|
||
<ul>
|
||
<li>There is no <code>react/lib/*</code> and <code>react-dom/lib/*</code> anymore. Even in CommonJS environments, React and ReactDOM are precompiled to single files (“flat bundles”). If you previously relied on undocumented React internals, and they don’t work anymore, let us know about your specific case in a new issue, and we’ll try to figure out a migration strategy for you.</li>
|
||
<li>There is no <code>react-with-addons.js</code> build anymore. All compatible addons are published separately on npm, and have single-file browser versions if you need them.</li>
|
||
<li>The deprecations introduced in 15.x have been removed from the core package. <code>React.createClass</code> is now available as <code>create-react-class</code>, <code>React.PropTypes</code> as <code>prop-types</code>, <code>React.DOM</code> as <code>react-dom-factories</code>, <code>react-addons-test-utils</code> as <code>react-dom/test-utils</code>, and shallow renderer as <code>react-test-renderer/shallow</code>. See <a href="https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html">15.5.0</a> and <a href="https://facebook.github.io/react/blog/2017/06/13/react-v15.6.0.html">15.6.0</a> blog posts for instructions on migrating code and automated codemods.</li>
|
||
<li>The names and paths to the single-file browser builds have changed to emphasize the difference between development and production builds. For example:
|
||
|
||
<ul>
|
||
<li><code>react/dist/react.js</code> → <code>react/umd/react.development.js</code></li>
|
||
<li><code>react/dist/react.min.js</code> → <code>react/umd/react.production.min.js</code></li>
|
||
<li><code>react-dom/dist/react-dom.js</code> → <code>react-dom/umd/react-dom.development.js</code></li>
|
||
<li><code>react-dom/dist/react-dom.min</code>.js → <code>react-dom/umd/react-dom.production.min.js</code></li>
|
||
</ul></li>
|
||
</ul>
|
||
|
||
<h2>JavaScript Environment Requirements</h2>
|
||
|
||
<p>React 16 depends on the collection types <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">Set</a>. If you support older browsers and devices which may not yet provide these natively (e.g. IE &lt; 11), consider including a global polyfill in your bundled application, such as <a href="https://github.com/zloirock/core-js">core-js</a> or <a href="https://babeljs.io/docs/usage/polyfill/">babel-polyfill</a>.</p>
|
||
|
||
<p>A polyfilled environment for React 16 using core-js to support older browsers might look like:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kr">import</span> <span class="s1">&#39;core-js/es6/map&#39;</span><span class="p">;</span>
|
||
<span class="kr">import</span> <span class="s1">&#39;core-js/es6/set&#39;</span><span class="p">;</span>
|
||
|
||
<span class="kr">import</span> <span class="nx">React</span> <span class="nx">from</span> <span class="s1">&#39;react&#39;</span><span class="p">;</span>
|
||
<span class="kr">import</span> <span class="nx">ReactDOM</span> <span class="nx">from</span> <span class="s1">&#39;react-dom&#39;</span><span class="p">;</span>
|
||
|
||
<span class="nx">ReactDOM</span><span class="p">.</span><span class="nx">render</span><span class="p">(</span>
|
||
<span class="o">&lt;</span><span class="nx">h1</span><span class="o">&gt;</span><span class="nx">Hello</span><span class="p">,</span> <span class="nx">world</span><span class="o">!&lt;</span><span class="err">/h1&gt;,</span>
|
||
<span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">&#39;root&#39;</span><span class="p">)</span>
|
||
<span class="p">);</span>
|
||
</code></pre></div>
|
||
<p>React also depends on <code>requestAnimationFrame</code> (even in test environments). A simple shim for test environments would be:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nx">global</span><span class="p">.</span><span class="nx">requestAnimationFrame</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="nx">setTimeout</span><span class="p">(</span><span class="nx">callback</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
|
||
<span class="p">};</span>
|
||
</code></pre></div>
|
||
<h2>Acknowledgments</h2>
|
||
|
||
<p>As always, this release would not have been possible without our open source contributors. Thanks to everyone who filed bugs, opened PRs, responded to issues, wrote documentation, and more!</p>
|
||
|
||
<p>Special thanks to our core contributors, especially for their heroic efforts over the past few weeks during the prerelease cycle: <a href="https://twitter.com/aweary">Brandon Dail</a>, <a href="https://twitter.com/monasticpanic">Jason Quense</a>, <a href="https://twitter.com/natehunzaker">Nathan Hunzaker</a>, and <a href="https://twitter.com/xander76">Sasha Aickin</a>.</p>
|
||
</description>
|
||
<pubDate>2017-09-26T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/09/26/react-v16.0.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/09/26/react-v16.0.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>React v15.6.2</title>
|
||
<description><p>Today we&#39;re sending out React 15.6.2. In 15.6.1, we shipped a few fixes for change events and inputs that had some unintended consequences. Those regressions have been ironed out, and we&#39;ve also included a few more fixes to improve the stability of React across all browsers.</p>
|
||
|
||
<p>Additionally, 15.6.2 adds support for the <a href="https://developers.google.com/web/updates/2017/03/chrome-58-media-updates#controlslist"><code>controlList</code></a> attribute, and CSS columns are no longer appended with a <code>px</code> suffix.</p>
|
||
|
||
<h2>Installation</h2>
|
||
|
||
<p>We recommend using <a href="https://yarnpkg.com/">Yarn</a> or <a href="https://www.npmjs.com/">npm</a> for managing front-end dependencies. If you&#39;re new to package managers, the <a href="https://yarnpkg.com/en/docs/getting-started">Yarn documentation</a> is a good place to get started.</p>
|
||
|
||
<p>To install React with Yarn, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">yarn add react@^15.6.2 react-dom@^15.6.2
|
||
</code></pre></div>
|
||
<p>To install React with npm, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">npm install --save react@^15.6.2 react-dom@^15.6.2
|
||
</code></pre></div>
|
||
<p>We recommend using a bundler like <a href="https://webpack.js.org/">webpack</a> or <a href="http://browserify.org/">Browserify</a> so you can write modular code and bundle it together into small packages to optimize load time.</p>
|
||
|
||
<p>Remember that by default, React runs extra checks and provides helpful warnings in development mode. When deploying your app, make sure to <a href="/react/docs/optimizing-performance.html#use-the-production-build">use the production build</a>.</p>
|
||
|
||
<p>In case you don&#39;t use a bundler, we also provide pre-built bundles in the npm packages which you can <a href="/react/docs/installation.html#using-a-cdn">include as script tags</a> on your page:</p>
|
||
|
||
<ul>
|
||
<li><strong>React</strong><br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.6.2/dist/react.js">react/dist/react.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.6.2/dist/react.min.js">react/dist/react.min.js</a><br/></li>
|
||
<li><strong>React with Add-Ons</strong><br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.6.2/dist/react-with-addons.js">react/dist/react-with-addons.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.5.0/dist/react-with-addons.min.js">react/dist/react-with-addons.min.js</a><br/></li>
|
||
<li><strong>React DOM</strong> (include React in the page before React DOM)<br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.6.2/dist/react-dom.js">react-dom/dist/react-dom.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.6.2/dist/react-dom.min.js">react-dom/dist/react-dom.min.js</a><br/></li>
|
||
<li><strong>React DOM Server</strong> (include React in the page before React DOM Server)<br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.6.2/dist/react-dom-server.js">react-dom/dist/react-dom-server.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.6.2/dist/react-dom-server.min.js">react-dom/dist/react-dom-server.min.js</a><br/></li>
|
||
</ul>
|
||
|
||
<p>We&#39;ve also published version <code>15.6.2</code> of <code>react</code> and <code>react-dom</code> on npm, and the <code>react</code> package on bower.</p>
|
||
|
||
<hr>
|
||
|
||
<h2>Changelog</h2>
|
||
|
||
<h2>15.6.2 (September 25, 2017)</h2>
|
||
|
||
<h3>All Packages</h3>
|
||
|
||
<ul>
|
||
<li>Switch from BSD + Patents to MIT license</li>
|
||
</ul>
|
||
|
||
<h3>React DOM</h3>
|
||
|
||
<ul>
|
||
<li>Fix a bug where modifying <code>document.documentMode</code> would trigger IE detection in other browsers, breaking change events. (<a href="https://github.com/aweary">@aweary</a> in <a href="https://github.com/facebook/react/pull/10032">#10032</a>)</li>
|
||
<li>CSS Columns are treated as unitless numbers. (<a href="https://github.com/aweary">@aweary</a> in <a href="https://github.com/facebook/react/pull/10115">#10115</a>)</li>
|
||
<li>Fix bug in QtWebKit when wrapping synthetic events in proxies. (<a href="https://github.com/walrusfruitcake">@walrusfruitcake</a> in <a href="https://github.com/facebook/react/pull/10011">#10115</a>)</li>
|
||
<li>Prevent event handlers from receiving extra argument in development. (<a href="https://github.com/aweary">@aweary</a> in <a href="https://github.com/facebook/react/pull/8363">#10115</a>)</li>
|
||
<li>Fix cases where <code>onChange</code> would not fire with <code>defaultChecked</code> on radio inputs. (<a href="https://github.com/jquense">@jquense</a> in <a href="https://github.com/facebook/react/pull/10156">#10156</a>)</li>
|
||
<li>Add support for <code>controlList</code> attribute to DOM property whitelist (<a href="https://github.com/nhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/9940">#9940</a>)</li>
|
||
<li>Fix a bug where creating an element with a ref in a constructor did not throw an error in development. (<a href="https://github.com/iansu">@iansu</a> in <a href="https://github.com/facebook/react/pull/10025">#10025</a>)</li>
|
||
</ul>
|
||
</description>
|
||
<pubDate>2017-09-25T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/09/25/react-v15.6.2.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/09/25/react-v15.6.2.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>DOM Attributes in React 16</title>
|
||
<description><p>In the past, React used to ignore unknown DOM attributes. If you wrote JSX with an attribute that React doesn&#39;t recognize, React would just skip it. For example, this:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// Your code:</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="nx">mycustomattribute</span><span class="o">=</span><span class="s2">&quot;something&quot;</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>would render an empty div to the DOM with React 15:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// React 15 output:</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>In React 16, we are making a change. Now, any unknown attributes will end up in the DOM:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// React 16 output:</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="nx">mycustomattribute</span><span class="o">=</span><span class="s2">&quot;something&quot;</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<h2>Why Are We Changing This?</h2>
|
||
|
||
<p>React has always provided a JavaScript-centric API to the DOM. Since React components often take both custom and DOM-related props, it makes sense for React to use the <code>camelCase</code> convention just like the DOM APIs:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">tabIndex</span><span class="o">=</span><span class="s2">&quot;-1&quot;</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>This has not changed. However, the way we enforced it in the past forced us to maintain a whitelist of all valid React DOM attributes in the bundle:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// ...</span>
|
||
<span class="nx">summary</span><span class="o">:</span> <span class="s1">&#39;summary&#39;</span><span class="p">,</span>
|
||
<span class="nx">tabIndex</span><span class="o">:</span> <span class="s1">&#39;tabindex&#39;</span>
|
||
<span class="nx">target</span><span class="o">:</span> <span class="s1">&#39;target&#39;</span><span class="p">,</span>
|
||
<span class="nx">title</span><span class="o">:</span> <span class="s1">&#39;title&#39;</span><span class="p">,</span>
|
||
<span class="c1">// ...</span>
|
||
</code></pre></div>
|
||
<p>This had two downsides:</p>
|
||
|
||
<ul>
|
||
<li><p>You could not <a href="https://github.com/facebook/react/issues/140">pass a custom attribute</a>. This is useful for supplying browser-specific non-standard attributes, trying new DOM APIs, and integrating with opinionated third-party libraries.</p></li>
|
||
<li><p>The attribute list kept growing over time, but most React canonical attribute names are already valid in the DOM. Removing most of the whitelist helped us reduce the bundle size a little bit.</p></li>
|
||
</ul>
|
||
|
||
<p>With the new approach, both of these problems are solved. With React 16, you can now pass custom attributes to all HTML and SVG elements, and React doesn&#39;t have to include the whole attribute whitelist in the production version.</p>
|
||
|
||
<p><strong>Note that you should still use the canonical React naming for known attributes:</strong></p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// Yes, please</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="nx">tabIndex</span><span class="o">=</span><span class="s2">&quot;-1&quot;</span> <span class="o">/&gt;</span>
|
||
|
||
<span class="c1">// Warning: Invalid DOM property `tabindex`. Did you mean `tabIndex`?</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="nx">tabindex</span><span class="o">=</span><span class="s2">&quot;-1&quot;</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>In other words, the way you use DOM components in React hasn&#39;t changed, but now you have some new capabilities.</p>
|
||
|
||
<h2>Should I Keep Data in Custom Attributes?</h2>
|
||
|
||
<p>No. We don&#39;t encourage you to keep data in DOM attributes. Even if you have to, <code>data-</code> attributes are probably a better approach, but in most cases data should be kept in React component state or external stores.</p>
|
||
|
||
<p>However, the new feature is handy if you need to use a non-standard or a new DOM attribute, or if you need to integrate with a third-party library that relies on such attributes.</p>
|
||
|
||
<h2>Data and ARIA Attributes</h2>
|
||
|
||
<p>Just like before, React lets you pass <code>data-</code> and <code>aria-</code> attributes freely:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">data</span><span class="o">-</span><span class="nx">foo</span><span class="o">=</span><span class="s2">&quot;42&quot;</span> <span class="o">/&gt;</span>
|
||
<span class="o">&lt;</span><span class="nx">button</span> <span class="nx">aria</span><span class="o">-</span><span class="nx">label</span><span class="o">=</span><span class="s2">&quot;Close&quot;</span> <span class="nx">onClick</span><span class="o">=</span><span class="p">{</span><span class="nx">onClose</span><span class="p">}</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>This has not changed.</p>
|
||
|
||
<p><a href="/react/docs/accessibility.html">Accessibility</a> is very important, so even though React 16 passes any attributes through, it still validates that <code>aria-</code> props have correct names in development mode, just like React 15 did.</p>
|
||
|
||
<h2>Migration Path</h2>
|
||
|
||
<p>We have included <a href="/react/warnings/unknown-prop.html">a warning about unknown attributes</a> since <a href="https://github.com/facebook/react/releases/tag/v15.2.0">React 15.2.0</a> which came out more than a year ago. The vast majority of third-party libraries have already updated their code. If your app doesn&#39;t produce warnings with React 15.2.0 or higher, this change should not require modifications in your application code.</p>
|
||
|
||
<p>If you still accidentally forward non-DOM props to DOM components, with React 16 you will start seeing those attributes in the DOM, for example:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">myData</span><span class="o">=</span><span class="s1">&#39;[Object object]&#39;</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>This is somewhat safe (the browser will just ignore them) but we recommend to fix these cases when you see them. One potential hazard is if you pass an object that implements a custom <code>toString()</code> or <code>valueOf()</code> method that throws. Another possible issue is that legacy HTML attributes like <code>align</code> and <code>valign</code> will now be passed to the DOM. They used to be stripped out because React didn&#39;t support them.</p>
|
||
|
||
<p>To avoid these problems, we suggest to fix the warnings you see in React 15 before upgrading to React 16.</p>
|
||
|
||
<h2>Changes in Detail</h2>
|
||
|
||
<p>We&#39;ve made a few other changes to make the behavior more predictable and help ensure you&#39;re not making mistakes. We don&#39;t anticipate that these changes are likely to break real-world applications.</p>
|
||
|
||
<p><strong>These changes only affect DOM components like <code>&lt;div&gt;</code>, not your own components.</strong> </p>
|
||
|
||
<p>Below is a detailed list of them.</p>
|
||
|
||
<ul>
|
||
<li><p><strong>Unknown attributes with string, number, and object values:</strong> </p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">mycustomattribute</span><span class="o">=</span><span class="s2">&quot;value&quot;</span> <span class="o">/&gt;</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="nx">mycustomattribute</span><span class="o">=</span><span class="p">{</span><span class="mi">42</span><span class="p">}</span> <span class="o">/&gt;</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="nx">mycustomattribute</span><span class="o">=</span><span class="p">{</span><span class="nx">myObject</span><span class="p">}</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>React 15: Warns and ignores them.<br>
|
||
React 16: Converts values to strings and passes them through.</p>
|
||
|
||
<p><em>Note: attributes starting with <code>on</code> are not passed through as an exception because this could become a potential security hole.</em></p></li>
|
||
<li><p><strong>Known attributes with a different canonical React name:</strong> </p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">tabindex</span><span class="o">=</span><span class="s2">&quot;-1&quot;</span> <span class="o">/&gt;</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;hi&quot;</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>React 15: Warns and ignores them.<br>
|
||
React 16: Warns but converts values to strings and passes them through.</p>
|
||
|
||
<p><em>Note: always use the canonical React naming for all supported attributes.</em></p></li>
|
||
<li><p><strong>Non-boolean attributes with boolean values:</strong> </p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">className</span><span class="o">=</span><span class="p">{</span><span class="kc">false</span><span class="p">}</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>React 15: Converts booleans to strings and passes them through.<br>
|
||
React 16: Warns and ignores them.</p></li>
|
||
<li><p><strong>Non-event attributes with function values:</strong> </p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">className</span><span class="o">=</span><span class="p">{</span><span class="kd">function</span><span class="p">()</span> <span class="p">{}}</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>React 15: Converts functions to strings and passes them through.<br>
|
||
React 16: Warns and ignores them.</p></li>
|
||
<li><p><strong>Attributes with Symbol values:</strong></p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">className</span><span class="o">=</span><span class="p">{</span><span class="nx">Symbol</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)}</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>React 15: Crashes.<br>
|
||
React 16: Warns and ignores them.</p></li>
|
||
<li><p><strong>Attributes with <code>NaN</code> values:</strong></p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">div</span> <span class="nx">tabIndex</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span> <span class="o">/</span> <span class="mi">0</span><span class="p">}</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>React 15: Converts <code>NaN</code>s to strings and passes them through.<br>
|
||
React 16: Warns and ignores them.</p></li>
|
||
</ul>
|
||
|
||
<p>While testing this release, we have also <a href="https://github.com/facebook/react/blob/master/fixtures/attribute-behavior/AttributeTableSnapshot.md">created an automatically generated table</a> for all known attributes to track potential regressions.</p>
|
||
|
||
<h2>Try It!</h2>
|
||
|
||
<p>You can try the change in <a href="https://codepen.io/gaearon/pen/gxNVdP?editors=0010">this CodePen</a>.<br>
|
||
It uses React 16 RC, and you can <a href="https://github.com/facebook/react/issues/10294">help us by testing the RC in your project!</a></p>
|
||
|
||
<h2>Thanks</h2>
|
||
|
||
<p>This effort was largely driven by <a href="https://github.com/nhunzaker">Nathan Hunzaker</a> who has been a <a href="https://github.com/facebook/react/pulls?q=is%3Apr+author%3Anhunzaker+is%3Aclosed">prolific outside contributor to React</a>.</p>
|
||
|
||
<p>You can find his work on this issue in several PRs over the course of last year: <a href="https://github.com/facebook/react/pull/6459">#6459</a>, <a href="https://github.com/facebook/react/pull/7311">#7311</a>, <a href="https://github.com/facebook/react/pull/10229">#10229</a>, <a href="https://github.com/facebook/react/pull/10397">#10397</a>, <a href="https://github.com/facebook/react/pull/10385">#10385</a>, and <a href="https://github.com/facebook/react/pull/10470">#10470</a>.</p>
|
||
|
||
<p>Major changes in a popular project can take a lot of time and research. Nathan demonstrated perseverance and commitment to getting this change through, and we are very thankful to him for this and other efforts.</p>
|
||
|
||
<p>We would also like to thank <a href="https://github.com/aweary">Brandon Dail</a> and <a href="https://github.com/jquense">Jason Quense</a> for their invaluable help maintaining React this year.</p>
|
||
|
||
<h2>Future Work</h2>
|
||
|
||
<p>We are not changing how <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements">custom elements</a> work in React 16, but there are <a href="https://github.com/facebook/react/issues/7249">existing discussions</a> about setting properties instead of attributes, and we might revisit this in React 17. Feel free to chime in if you&#39;d like to help!</p>
|
||
</description>
|
||
<pubDate>2017-09-08T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Error Handling in React 16</title>
|
||
<description><p>As React 16 release is getting closer, we would like to announce a few changes to how React handles JavaScript errors inside components. These changes are included in React 16 beta versions, and will be a part of React 16.</p>
|
||
|
||
<p><strong>By the way, <a href="https://github.com/facebook/react/issues/10294">we just released the first beta of React 16 for you to try!</a></strong></p>
|
||
|
||
<h2>Behavior in React 15 and Earlier</h2>
|
||
|
||
<p>In the past, JavaScript errors inside components used to corrupt React’s internal state and cause it to <a href="https://github.com/facebook/react/issues/4026">emit</a> <a href="https://github.com/facebook/react/issues/6895">cryptic</a> <a href="https://github.com/facebook/react/issues/8579">errors</a> on next renders. These errors were always caused by an earlier error in the application code, but React did not provide a way to handle them gracefully in components, and could not recover from them.</p>
|
||
|
||
<h2>Introducing Error Boundaries</h2>
|
||
|
||
<p>A JavaScript error in a part of the UI shouldn’t break the whole app. To solve this problem for React users, React 16 introduces a new concept of an “error boundary”.</p>
|
||
|
||
<p>Error boundaries are React components that <strong>catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI</strong> instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.</p>
|
||
|
||
<p>A class component becomes an error boundary if it defines a new lifecycle method called <code>componentDidCatch(error, info)</code>:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kr">class</span> <span class="nx">ErrorBoundary</span> <span class="kr">extends</span> <span class="nx">React</span><span class="p">.</span><span class="nx">Component</span> <span class="p">{</span>
|
||
<span class="nx">constructor</span><span class="p">(</span><span class="nx">props</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="kr">super</span><span class="p">(</span><span class="nx">props</span><span class="p">);</span>
|
||
<span class="k">this</span><span class="p">.</span><span class="nx">state</span> <span class="o">=</span> <span class="p">{</span> <span class="nx">hasError</span><span class="o">:</span> <span class="kc">false</span> <span class="p">};</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="hll"> <span class="nx">componentDidCatch</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">info</span><span class="p">)</span> <span class="p">{</span>
|
||
</span><span class="hll"> <span class="c1">// Display fallback UI</span>
|
||
</span><span class="hll"> <span class="k">this</span><span class="p">.</span><span class="nx">setState</span><span class="p">({</span> <span class="nx">hasError</span><span class="o">:</span> <span class="kc">true</span> <span class="p">});</span>
|
||
</span><span class="hll"> <span class="c1">// You can also log the error to an error reporting service</span>
|
||
</span><span class="hll"> <span class="nx">logErrorToMyService</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">info</span><span class="p">);</span>
|
||
</span><span class="hll"> <span class="p">}</span>
|
||
</span>
|
||
<span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="hll"> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">state</span><span class="p">.</span><span class="nx">hasError</span><span class="p">)</span> <span class="p">{</span>
|
||
</span><span class="hll"> <span class="c1">// You can render any custom fallback UI</span>
|
||
</span><span class="hll"> <span class="k">return</span> <span class="o">&lt;</span><span class="nx">h1</span><span class="o">&gt;</span><span class="nx">Something</span> <span class="nx">went</span> <span class="nx">wrong</span><span class="p">.</span><span class="o">&lt;</span><span class="err">/h1&gt;;</span>
|
||
</span><span class="hll"> <span class="p">}</span>
|
||
</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">children</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>Then you can use it as a regular component:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">ErrorBoundary</span><span class="o">&gt;</span>
|
||
<span class="o">&lt;</span><span class="nx">MyWidget</span> <span class="o">/&gt;</span>
|
||
<span class="o">&lt;</span><span class="err">/ErrorBoundary&gt;</span>
|
||
</code></pre></div>
|
||
<p>The <code>componentDidCatch()</code> method works like a JavaScript <code>catch {}</code> block, but for components. Only class components can be error boundaries. In practice, most of the time you’ll want to declare an error boundary component once and use it throughout your application.</p>
|
||
|
||
<p>Note that <strong>error boundaries only catch errors in the components below them in the tree</strong>. An error boundary can’t catch an error within itself. If an error boundary fails trying to render the error message, the error will propagate to the closest error boundary above it. This, too, is similar to how <code>catch {}</code> block works in JavaScript.</p>
|
||
|
||
<h2>Live Demo</h2>
|
||
|
||
<p>Check out <a href="https://codepen.io/gaearon/pen/wqvxGa?editors=0010">this example of declaring and using an error boundary</a> with <a href="https://github.com/facebook/react/issues/10294">React 16 beta</a>.</p>
|
||
|
||
<h2>Where to Place Error Boundaries</h2>
|
||
|
||
<p>The granularity of error boundaries is up to you. You may wrap top-level route components to display a “Something went wrong” message to the user, just like server-side frameworks often handle crashes. You may also wrap individual widgets in an error boundary to protect them from crashing the rest of the application.</p>
|
||
|
||
<h2>New Behavior for Uncaught Errors</h2>
|
||
|
||
<p>This change has an important implication. <strong>As of React 16, errors that were not caught by any error boundary will result in unmounting of the whole React component tree.</strong></p>
|
||
|
||
<p>We debated this decision, but in our experience it is worse to leave corrupted UI in place than to completely remove it. For example, in a product like Messenger leaving the broken UI visible could lead to somebody sending a message to the wrong person. Similarly, it is worse for a payments app to display a wrong amount than to render nothing.</p>
|
||
|
||
<p>This change means that as you migrate to React 16, you will likely uncover existing crashes in your application that have been unnoticed before. Adding error boundaries lets you provide better user experience when something goes wrong.</p>
|
||
|
||
<p>For example, Facebook Messenger wraps content of the sidebar, the info panel, the conversation log, and the message input into separate error boundaries. If some component in one of these UI areas crashes, the rest of them remain interactive.</p>
|
||
|
||
<p>We also encourage you to use JS error reporting services (or build your own) so that you can learn about unhandled exceptions as they happen in production, and fix them.</p>
|
||
|
||
<h2>Component Stack Traces</h2>
|
||
|
||
<p>React 16 prints all errors that occurred during rendering to the console in development, even if the application accidentally swallows them. In addition to the error message and the JavaScript stack, it also provides component stack traces. Now you can see where exactly in the component tree the failure has happened:</p>
|
||
|
||
<p><img src="/react/img/blog/error-boundaries-stack-trace.png" alt="Component stack traces in error message" style="width: 100%;"></p>
|
||
|
||
<p>You can also see the filenames and line numbers in the component stack trace. This works by default in <a href="https://github.com/facebookincubator/create-react-app">Create React App</a> projects:</p>
|
||
|
||
<p><img src="/react/img/blog/error-boundaries-stack-trace-line-numbers.png" alt="Component stack traces with line numbers in error message" style="width: 100%;"></p>
|
||
|
||
<p>If you don’t use Create React App, you can add <a href="https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source">this plugin</a> manually to your Babel configuration. Note that it’s intended only for development and <strong>must be disabled in production</strong>.</p>
|
||
|
||
<h2>Why Not Use <code>try</code> / <code>catch</code>?</h2>
|
||
|
||
<p><code>try</code> / <code>catch</code> is great but it only works for imperative code:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="k">try</span> <span class="p">{</span>
|
||
<span class="nx">showButton</span><span class="p">();</span>
|
||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="c1">// ...</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>However, React components are declarative and specify <em>what</em> should be rendered:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">Button</span> <span class="o">/&gt;</span>
|
||
</code></pre></div>
|
||
<p>Error boundaries preserve the declarative nature of React, and behave as you would expect. For example, even if an error occurs in a <code>componentDidUpdate</code> hook caused by a <code>setState</code> somewhere deep in the tree, it will still correctly propagate to the closest error boundary.</p>
|
||
|
||
<h2>Naming Changes from React 15</h2>
|
||
|
||
<p>React 15 included a very limited support for error boundaries under a different method name: <code>unstable_handleError</code>. This method no longer works, and you will need to change it to <code>componentDidCatch</code> in your code starting from the first 16 beta release.</p>
|
||
|
||
<p>For this change, we’ve provided <a href="https://github.com/reactjs/react-codemod#error-boundaries">a codemod</a> to automatically migrate your code.</p>
|
||
</description>
|
||
<pubDate>2017-07-26T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>React v15.6.0</title>
|
||
<description><p>Today we are releasing React 15.6.0. As we prepare for React 16.0, we have been fixing and cleaning up many things. This release continues to pave the way.</p>
|
||
|
||
<h2>Improving Inputs</h2>
|
||
|
||
<p>In React 15.6.0 the <code>onChange</code> event for inputs is a little bit more reliable and handles more edge cases, including the following:</p>
|
||
|
||
<ul>
|
||
<li>not firing when radio button is clicked but not changed (<a href="https://github.com/facebook/react/issues/1471">issue 1471</a>)</li>
|
||
<li>changing an input of type <code>range</code> with the arrow keys (<a href="https://github.com/facebook/react/issues/554">issue 554</a>)</li>
|
||
<li>pasting text into a text area in IE11 (<a href="https://github.com/facebook/react/issues/7211">issue 7211</a>)</li>
|
||
<li>auto-fill in IE11 (<a href="https://github.com/facebook/react/issues/6614">issue 6614</a>)</li>
|
||
<li>clearing input with &#39;x&#39; button or right-click &#39;delete&#39; in IE11 (<a href="https://github.com/facebook/react/issues/6822">issue 6822</a>)</li>
|
||
<li>not firing when characters are present in the input on render in IE11 (<a href="https://github.com/facebook/react/issues/2185">issue 2185</a>)</li>
|
||
</ul>
|
||
|
||
<p>Thanks to <a href="https://github.com/jquense">Jason Quense</a> and everyone who helped out on those issues and PRs.</p>
|
||
|
||
<h2>Less Noisy Deprecation Warnings</h2>
|
||
|
||
<p>We are also including a couple of new warnings for upcoming deprecations. These should not affect most users, and for more details see the changelog below.</p>
|
||
|
||
<p>After the last release, we got valuable community feedback that deprecation warnings were causing noise and failing tests. <strong>In React 15.6, we have downgraded deprecation warnings to use <code>console.warn</code> instead of <code>console.error</code>.</strong> Our other warnings will still use <code>console.error</code> because they surface urgent issues which could lead to bugs. Unlike our other warnings, deprecation warnings can be fixed over time and won&#39;t cause problems in your app if shipped. We believe that downgrading the urgency of deprecation warnings will make your next update easier. Thanks to everyone who was involved in the discussion of this change.</p>
|
||
|
||
<hr>
|
||
|
||
<h2>Installation</h2>
|
||
|
||
<p>We recommend using <a href="https://yarnpkg.com/">Yarn</a> or <a href="https://www.npmjs.com/">npm</a> for managing front-end dependencies. If you&#39;re new to package managers, the <a href="https://yarnpkg.com/en/docs/getting-started">Yarn documentation</a> is a good place to get started.</p>
|
||
|
||
<p>To install React with Yarn, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">yarn add react@^15.6.0 react-dom@^15.6.0
|
||
</code></pre></div>
|
||
<p>To install React with npm, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">npm install --save react@^15.6.0 react-dom@^15.6.0
|
||
</code></pre></div>
|
||
<p>We recommend using a bundler like <a href="https://webpack.js.org/">webpack</a> or <a href="http://browserify.org/">Browserify</a> so you can write modular code and bundle it together into small packages to optimize load time.</p>
|
||
|
||
<p>Remember that by default, React runs extra checks and provides helpful warnings in development mode. When deploying your app, make sure to <a href="/react/docs/optimizing-performance.html#use-the-production-build">use the production build</a>.</p>
|
||
|
||
<p>In case you don&#39;t use a bundler, we also provide pre-built bundles in the npm packages which you can <a href="/react/docs/installation.html#using-a-cdn">include as script tags</a> on your page:</p>
|
||
|
||
<ul>
|
||
<li><strong>React</strong><br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.6.0/dist/react.js">react/dist/react.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.6.0/dist/react.min.js">react/dist/react.min.js</a><br/></li>
|
||
<li><strong>React with Add-Ons</strong><br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.6.0/dist/react-with-addons.js">react/dist/react-with-addons.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.5.0/dist/react-with-addons.min.js">react/dist/react-with-addons.min.js</a><br/></li>
|
||
<li><strong>React DOM</strong> (include React in the page before React DOM)<br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.6.0/dist/react-dom.js">react-dom/dist/react-dom.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.6.0/dist/react-dom.min.js">react-dom/dist/react-dom.min.js</a><br/></li>
|
||
<li><strong>React DOM Server</strong> (include React in the page before React DOM Server)<br/>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.6.0/dist/react-dom-server.js">react-dom/dist/react-dom-server.js</a><br/>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.6.0/dist/react-dom-server.min.js">react-dom/dist/react-dom-server.min.js</a><br/></li>
|
||
</ul>
|
||
|
||
<p>We&#39;ve also published version <code>15.6.0</code> of <code>react</code> and <code>react-dom</code> on npm, and the <code>react</code> package on bower.</p>
|
||
|
||
<hr>
|
||
|
||
<h2>Changelog</h2>
|
||
|
||
<h2>15.6.0 (June 13, 2017)</h2>
|
||
|
||
<h3>React</h3>
|
||
|
||
<ul>
|
||
<li>Downgrade deprecation warnings to use <code>console.warn</code> instead of <code>console.error</code>. (<a href="https://github.com/flarnie">@flarnie</a> in <a href="https://github.com/facebook/react/pull/9753">#9753</a>)</li>
|
||
<li>Add a deprecation warning for <code>React.createClass</code>. Points users to <code>create-react-class</code> instead. (<a href="https://github.com/flarnie">@flarnie</a> in <a href="https://github.com/facebook/react/pull/9771">#9771</a>)</li>
|
||
<li>Add deprecation warnings and separate module for <code>React.DOM</code> factory helpers. (<a href="https://github.com/nhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/8356">#8356</a>)</li>
|
||
<li>Warn for deprecation of <code>React.createMixin</code> helper, which was never used. (<a href="https://github.com/aweary">@aweary</a> in <a href="https://github.com/facebook/react/pull/8853">#8853</a>)</li>
|
||
</ul>
|
||
|
||
<h3>React DOM</h3>
|
||
|
||
<ul>
|
||
<li>Add support for CSS variables in <code>style</code> attribute. (<a href="https://github.com/aweary">@aweary</a> in <a href="https://github.com/facebook/react/pull/9302">#9302</a>)</li>
|
||
<li>Add support for CSS Grid style properties. (<a href="https://github.com/ericsakmar">@ericsakmar</a> in <a href="https://github.com/facebook/react/pull/9185">#9185</a>)</li>
|
||
<li>Fix bug where inputs mutated value on type conversion. (<a href="https://github.com/mhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/9806">#9806</a>)</li>
|
||
<li>Fix issues with <code>onChange</code> not firing properly for some inputs. (<a href="https://github.com/jquense">@jquense</a> in <a href="https://github.com/facebook/react/pull/8575">#8575</a>)</li>
|
||
<li>Fix bug where controlled number input mistakenly allowed period. (<a href="https://github.com/nhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/9584">#9584</a>)</li>
|
||
<li>Fix bug where performance entries were being cleared. (<a href="https://github.com/chrisui">@chrisui</a> in <a href="https://github.com/facebook/react/pull/9451">#9451</a>)</li>
|
||
</ul>
|
||
|
||
<h3>React Addons</h3>
|
||
|
||
<ul>
|
||
<li>Fix AMD support for addons depending on <code>react</code>. (<a href="https://github.com/flarnie">@flarnie</a> in <a href="https://github.com/facebook/react/issues/9919">#9919</a>)</li>
|
||
<li>Fix <code>isMounted()</code> to return <code>true</code> in <code>componentWillUnmount</code>. (<a href="https://github.com/mridgway">@mridgway</a> in <a href="https://github.com/facebook/react/issues/9638">#9638</a>)</li>
|
||
<li>Fix <code>react-addons-update</code> to not depend on native <code>Object.assign</code>. (<a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebook/react/pull/9937">#9937</a>)</li>
|
||
<li>Remove broken Google Closure Compiler annotation from <code>create-react-class</code>. (<a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebook/react/pull/9933">#9933</a>)</li>
|
||
<li>Remove unnecessary dependency from <code>react-linked-input</code>. (<a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebook/react/pull/9766">#9766</a>)</li>
|
||
<li>Point <code>react-addons-(css-)transition-group</code> to the new package. (<a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebook/react/pull/9937">#9937</a>)</li>
|
||
</ul>
|
||
</description>
|
||
<pubDate>2017-06-13T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/06/13/react-v15.6.0.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/06/13/react-v15.6.0.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>What's New in Create React App</title>
|
||
<description><p>Less than a year ago, we introduced <a href="/react/blog/2016/07/22/create-apps-with-no-configuration.html">Create React App</a> as an officially supported way to create apps with zero configuration. The project has since enjoyed tremendous growth, with over 950 commits by more than 250 contributors.</p>
|
||
|
||
<p>Today, we are excited to announce that many features that have been in the pipeline for the last few months are finally released.</p>
|
||
|
||
<p>As usual with Create React App, <strong>you can enjoy these improvements in your existing non-ejected apps by updating a single dependency</strong> and following our <a href="https://github.com/facebookincubator/create-react-app/releases/tag/v1.0.0">migration instructions</a>.</p>
|
||
|
||
<p>Newly created apps will get these improvements automatically.</p>
|
||
|
||
<h3>webpack 2</h3>
|
||
|
||
<blockquote>
|
||
<p><em>This change was contributed by <a href="https://github.com/Timer">@Timer</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/1291">#1291</a>.</em></p>
|
||
</blockquote>
|
||
|
||
<p>We have upgraded to webpack 2 which has been <a href="https://medium.com/webpack/webpack-2-and-beyond-40520af9067f">officially released</a> a few months ago. It is a big upgrade with many bugfixes and general improvements. We have been testing it for a while, and now consider it stable enough to recommend it to everyone.</p>
|
||
|
||
<p>While the Webpack configuration format has changed, Create React App users who didn&#39;t eject don&#39;t need to worry about it as we have updated the configuration on our side.</p>
|
||
|
||
<p>If you had to eject your app for one reason or another, Webpack provides a <a href="https://webpack.js.org/guides/migrating/">configuration migration guide</a> that you can follow to update your apps. Note that with each release of Create React App, we are working to support more use cases out of the box so that you don&#39;t have to eject in the future.</p>
|
||
|
||
<p>The biggest notable webpack 2 feature is the ability to write and import <a href="http://2ality.com/2014/09/es6-modules-final.html">ES6 modules</a> directly without compiling them to CommonJS. This shouldn’t affect how you write code since you likely already use <code>import</code> and <code>export</code> statements, but it will help catch more mistakes like missing named exports at compile time:</p>
|
||
|
||
<p><img src='/react/img/blog/cra-update-exports.gif' alt='Export validation' style="max-width:100%"> </p>
|
||
|
||
<p>In the future, as the ecosystem around ES6 modules matures, you can expect more improvements to your app&#39;s bundle size thanks to <a href="https://webpack.js.org/guides/tree-shaking/">tree shaking</a>.</p>
|
||
|
||
<h3> Runtime Error Overlay</h3>
|
||
|
||
<blockquote>
|
||
<p><em>This change was contributed by <a href="https://github.com/Timer">@Timer</a> and <a href="https://github.com/nicinabox">@nicinabox</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/1101">#1101</a>, <a href="https://github.com/bvaughn">@bvaughn</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/2201">#2201</a>.</em></p>
|
||
</blockquote>
|
||
|
||
<p>Have you ever made a mistake in code and only realized it after the console is flooded with cryptic errors? Or worse, have you ever shipped an app with crashes in production because you accidentally missed an error in development?</p>
|
||
|
||
<p>To address these issues, we are introducing an overlay that pops up whenever there is an uncaught error in your application. It only appears in development, and you can dismiss it by pressing Escape. </p>
|
||
|
||
<p>A GIF is worth a thousand words:</p>
|
||
|
||
<p><img src='/react/img/blog/cra-runtime-error.gif' alt='Runtime error overlay' style="max-width:100%"> </p>
|
||
|
||
<p>(Yes, it integrates with your editor!)</p>
|
||
|
||
<p>In the future, we plan to teach the runtime error overlay to understand more about your React app. For example, after React 16 we plan to show React component stacks in addition to the JavaScript stacks when an error is thrown.</p>
|
||
|
||
<h3>Progressive Web Apps by Default</h3>
|
||
|
||
<blockquote>
|
||
<p><em>This change was contributed by <a href="https://github.com/jeffposnick">@jeffposnick</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/1728">#1728</a>.</em></p>
|
||
</blockquote>
|
||
|
||
<p>Newly created projects are built as <a href="https://developers.google.com/web/progressive-web-apps/">Progressive Web Apps</a> by default. This means that they employ <a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers">service workers</a> with an <a href="https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network">offline-first caching strategy</a> to minimize the time it takes to serve the app to the users who visit it again. You can opt out of this behavior, but we recommend it both for new and existing apps, especially if you target mobile devices.</p>
|
||
|
||
<p><img src='/react/img/blog/cra-pwa.png' alt='Loading assets from service worker' style="max-width:100%"> </p>
|
||
|
||
<p>New apps automatically have these features, but you can easily convert an existing project to a Progressive Web App by following <a href="https://github.com/facebookincubator/create-react-app/releases/tag/v1.0.0">our migration guide</a>.</p>
|
||
|
||
<p>We will be adding <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#making-a-progressive-web-app">more documentation</a> on this topic in the coming weeks. Please feel free to <a href="https://github.com/facebookincubator/create-react-app/issues/new">ask any questions</a> on the issue tracker!</p>
|
||
|
||
<h3>Jest 20</h3>
|
||
|
||
<blockquote>
|
||
<p><em>This change was contributed by <a href="https://github.com/rogeliog">@rogeliog</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/1614">#1614</a> and <a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/2171">#2171</a>.</em></p>
|
||
</blockquote>
|
||
|
||
<p>We are now using the latest version of Jest that includes numerous bugfixes and improvements. You can read more about the changes in <a href="https://facebook.github.io/jest/blog/2017/02/21/jest-19-immersive-watch-mode-test-platform-improvements.html">Jest 19</a> and <a href="http://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html">Jest 20</a> blog posts.</p>
|
||
|
||
<p>Highlights include a new <a href="https://facebook.github.io/jest/blog/2017/02/21/jest-19-immersive-watch-mode-test-platform-improvements.html#immersive-watch-mode">immersive watch mode</a>, <a href="https://facebook.github.io/jest/blog/2017/02/21/jest-19-immersive-watch-mode-test-platform-improvements.html#snapshot-updates">a better snapshot format</a>, <a href="https://facebook.github.io/jest/blog/2017/02/21/jest-19-immersive-watch-mode-test-platform-improvements.html#improved-printing-of-skipped-tests">improvements to printing skipped tests</a>, and <a href="https://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html#new-improved-testing-apis">new testing APIs</a>.</p>
|
||
|
||
<p><img src='/react/img/blog/cra-jest-search.gif' alt='Immersive test watcher' style="max-width:100%"> </p>
|
||
|
||
<p>Additionally, Create React App now support configuring a few Jest options related to coverage reporting.</p>
|
||
|
||
<h3>Code Splitting with Dynamic import()</h3>
|
||
|
||
<blockquote>
|
||
<p><em>This change was contributed by <a href="https://github.com/Timer">@Timer</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/1538">#1538</a> and <a href="https://github.com/tharakawj">@tharakawj</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/1801">#1801</a>.</em></p>
|
||
</blockquote>
|
||
|
||
<p>It is important to keep the initial JavaScript payload of web apps down to the minimum, and <a href="https://medium.com/@addyosmani/progressive-web-apps-with-react-js-part-2-page-load-performance-33b932d97cf2">load the rest of the code on demand</a>. Although Create React App supported <a href="https://webpack.js.org/guides/code-splitting-async/">code splitting</a> using <code>require.ensure()</code> since the first release, it used a webpack-specific syntax that did not work in Jest or other environments.</p>
|
||
|
||
<p>In this release, we are adding support for the <a href="http://2ality.com/2017/01/import-operator.html#loading-code-on-demand">dynamic <code>import()</code> proposal</a> which aligns with the future web standards. Unlike <code>require.ensure()</code>, it doesn&#39;t break Jest tests, and should eventually become a part of JavaScript. We encourage you to use <code>import()</code> to delay loading the code for non-critical component subtrees until you need to render them.</p>
|
||
|
||
<p><img src='/react/img/blog/cra-dynamic-import.gif' alt='Creating chunks with dynamic import' style="max-width:100%"></p>
|
||
|
||
<h3>Better Console Output</h3>
|
||
|
||
<blockquote>
|
||
<p><em>This change was contributed by <a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebookincubator/create-react-app/pull/2120">#2120</a>, <a href="https://github.com/facebookincubator/create-react-app/pull/2125">#2125</a>, and <a href="https://github.com/facebookincubator/create-react-app/pull/2161">#2161</a>.</em></p>
|
||
</blockquote>
|
||
|
||
<p>We have improved the console output across the board.</p>
|
||
|
||
<p>For example, when you start the development server, we now display the LAN address in additional to the localhost address so that you can quickly access the app from a mobile device on the same network:</p>
|
||
|
||
<p><img src='/react/img/blog/cra-better-output.png' alt='Better console output' style="max-width:100%"> </p>
|
||
|
||
<p>When lint errors are reported, we no longer show the warnings so that you can concentrate on more critical issues. Errors and warnings in the production build output are better formatted, and the build error overlay font size now matches the browser font size more closely.</p>
|
||
|
||
<h3>But Wait... There&#39;s More!</h3>
|
||
|
||
<p>You can only fit so much in a blog post, but there are other long-requested features in this release, such as <a href="https://github.com/facebookincubator/create-react-app/pull/1344">environment-specific and local <code>.env</code> files</a>, <a href="https://github.com/facebookincubator/create-react-app/pull/2130">a lint rule against confusingly named globals</a>, <a href="https://github.com/facebookincubator/create-react-app/pull/1790">support for multiple proxies in development</a>, <a href="https://github.com/facebookincubator/create-react-app/pull/1590">a customizable browser launch script</a>, and many bugfixes.</p>
|
||
|
||
<p>You can read the full changelog and the migration guide in the <a href="https://github.com/facebookincubator/create-react-app/releases/tag/v1.0.0">v1.0.0 release notes</a>.</p>
|
||
|
||
<h3>Acknowledgements</h3>
|
||
|
||
<p>This release is a result of months of work from many people in the React community. It is focused on improving both developer and end user experience, as we believe they are complementary and go hand in hand.</p>
|
||
|
||
<p>We are grateful to <a href="https://github.com/facebookincubator/create-react-app/graphs/contributors">everyone who has offered their contributions</a>, whether in code, documentation, or by helping other people. We would like to specifically thank <a href="https://github.com/timer">Joe Haddad</a> for his invaluable help maintaining the project.</p>
|
||
|
||
<p>We are excited to bring these improvements to everybody using Create React App, and we are looking forward to more of your feedback and contributions.</p>
|
||
</description>
|
||
<pubDate>2017-05-18T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/05/18/whats-new-in-create-react-app.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/05/18/whats-new-in-create-react-app.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>React v15.5.0</title>
|
||
<description><p>It&#39;s been exactly one year since the last breaking change to React. Our next major release, React 16, will include some exciting improvements, including a <a href="https://www.youtube.com/watch?v=ZCuYPiUIONs">complete rewrite</a> of React&#39;s internals. <a href="/react/contributing/design-principles.html#stability">We take stability seriously</a>, and are committed to bringing those improvements to all of our users with minimal effort.</p>
|
||
|
||
<p>To that end, today we&#39;re releasing React 15.5.0.</p>
|
||
|
||
<h3>New Deprecation Warnings</h3>
|
||
|
||
<p>The biggest change is that we&#39;ve extracted <code>React.PropTypes</code> and <code>React.createClass</code> into their own packages. Both are still accessible via the main <code>React</code> object, but using either will log a one-time deprecation warning to the console when in development mode. This will enable future code size optimizations.</p>
|
||
|
||
<p>These warnings will not affect the behavior of your application. However, we realize they may cause some frustration, particularly if you use a testing framework that treats <code>console.error</code> as a failure.</p>
|
||
|
||
<p><strong>Adding new warnings is not something we do lightly.</strong> Warnings in React are not mere suggestions — they are integral to our strategy of keeping as many people as possible on the latest version of React. We never add warnings without providing an incremental path forward.</p>
|
||
|
||
<p>So while the warnings may cause frustration in the short-term, we believe <strong>prodding developers to migrate their codebases now prevents greater frustration in the future</strong>. Proactively fixing warnings ensures you are prepared for the next major release. If your app produces zero warnings in 15.5, it should continue to work in 16 without any changes.</p>
|
||
|
||
<p>For each of these new deprecations, we&#39;ve provided a codemod to automatically migrate your code. They are available as part of the <a href="https://github.com/reactjs/react-codemod">react-codemod</a> project.</p>
|
||
|
||
<h3>Migrating from React.PropTypes</h3>
|
||
|
||
<p>Prop types are a feature for runtime validation of props during development. We&#39;ve extracted the built-in prop types to a separate package to reflect the fact that not everybody uses them.</p>
|
||
|
||
<p>In 15.5, instead of accessing <code>PropTypes</code> from the main <code>React</code> object, install the <code>prop-types</code> package and import them from there:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// Before (15.4 and below)</span>
|
||
<span class="kr">import</span> <span class="nx">React</span> <span class="nx">from</span> <span class="s1">&#39;react&#39;</span><span class="p">;</span>
|
||
|
||
<span class="kr">class</span> <span class="nx">Component</span> <span class="kr">extends</span> <span class="nx">React</span><span class="p">.</span><span class="nx">Component</span> <span class="p">{</span>
|
||
<span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span><span class="p">{</span><span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">text</span><span class="p">}</span><span class="o">&lt;</span><span class="err">/div&gt;;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="nx">Component</span><span class="p">.</span><span class="nx">propTypes</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="hll"> <span class="nx">text</span><span class="o">:</span> <span class="nx">React</span><span class="p">.</span><span class="nx">PropTypes</span><span class="p">.</span><span class="nx">string</span><span class="p">.</span><span class="nx">isRequired</span><span class="p">,</span>
|
||
</span><span class="p">}</span>
|
||
|
||
<span class="c1">// After (15.5)</span>
|
||
<span class="kr">import</span> <span class="nx">React</span> <span class="nx">from</span> <span class="s1">&#39;react&#39;</span><span class="p">;</span>
|
||
<span class="hll"><span class="kr">import</span> <span class="nx">PropTypes</span> <span class="nx">from</span> <span class="s1">&#39;prop-types&#39;</span><span class="p">;</span>
|
||
</span>
|
||
<span class="kr">class</span> <span class="nx">Component</span> <span class="kr">extends</span> <span class="nx">React</span><span class="p">.</span><span class="nx">Component</span> <span class="p">{</span>
|
||
<span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span><span class="p">{</span><span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">text</span><span class="p">}</span><span class="o">&lt;</span><span class="err">/div&gt;;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="nx">Component</span><span class="p">.</span><span class="nx">propTypes</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="hll"> <span class="nx">text</span><span class="o">:</span> <span class="nx">PropTypes</span><span class="p">.</span><span class="nx">string</span><span class="p">.</span><span class="nx">isRequired</span><span class="p">,</span>
|
||
</span><span class="p">};</span>
|
||
</code></pre></div>
|
||
<p>The <a href="https://github.com/reactjs/react-codemod#react-proptypes-to-prop-types">codemod</a> for this change performs this conversion automatically. Basic usage:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js &lt;path&gt;
|
||
</code></pre></div>
|
||
<p>The <code>propTypes</code>, <code>contextTypes</code>, and <code>childContextTypes</code> APIs will work exactly as before. The only change is that the built-in validators now live in a separate package.</p>
|
||
|
||
<p>You may also consider using <a href="https://flow.org/">Flow</a> to statically type check your JavaScript code, including <a href="https://flow.org/en/docs/frameworks/react/#setup-flow-with-react-a-classtoc-idtoc-setup-flow-with-react-hreftoc-setup-flow-with-reacta">React components</a>.</p>
|
||
|
||
<h3>Migrating from React.createClass</h3>
|
||
|
||
<p>When React was initially released, there was no idiomatic way to create classes in JavaScript, so we provided our own: <code>React.createClass</code>.</p>
|
||
|
||
<p>Later, classes were added to the language as part of ES2015, so we added the ability to create React components using JavaScript classes. <strong>Along with functional components, JavaScript classes are now the <a href="/react/docs/components-and-props.html#functional-and-class-components">preferred way to create components in React</a>.</strong></p>
|
||
|
||
<p>For your existing <code>createClass</code> components, we recommend that you migrate them to JavaScript classes. However, if you have components that rely on mixins, converting to classes may not be immediately feasible. If so, <code>create-react-class</code> is available on npm as a drop-in replacement:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// Before (15.4 and below)</span>
|
||
<span class="kd">var</span> <span class="nx">React</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;react&#39;</span><span class="p">);</span>
|
||
|
||
<span class="hll"><span class="kd">var</span> <span class="nx">Component</span> <span class="o">=</span> <span class="nx">React</span><span class="p">.</span><span class="nx">createClass</span><span class="p">({</span>
|
||
</span> <span class="nx">mixins</span><span class="o">:</span> <span class="p">[</span><span class="nx">MixinA</span><span class="p">],</span>
|
||
<span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="o">&lt;</span><span class="nx">Child</span> <span class="o">/&gt;</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">});</span>
|
||
|
||
<span class="c1">// After (15.5)</span>
|
||
<span class="kd">var</span> <span class="nx">React</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;react&#39;</span><span class="p">);</span>
|
||
<span class="hll"><span class="kd">var</span> <span class="nx">createReactClass</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;create-react-class&#39;</span><span class="p">);</span>
|
||
</span>
|
||
<span class="hll"><span class="kd">var</span> <span class="nx">Component</span> <span class="o">=</span> <span class="nx">createReactClass</span><span class="p">({</span>
|
||
</span> <span class="nx">mixins</span><span class="o">:</span> <span class="p">[</span><span class="nx">MixinA</span><span class="p">],</span>
|
||
<span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="o">&lt;</span><span class="nx">Child</span> <span class="o">/&gt;</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">});</span>
|
||
</code></pre></div>
|
||
<p>Your components will continue to work the same as they did before.</p>
|
||
|
||
<p>The <a href="https://github.com/reactjs/react-codemod#explanation-of-the-new-es2015-class-transform-with-property-initializers">codemod</a> for this change attempts to convert a <code>createClass</code> component to a JavaScript class, with a fallback to <code>create-react-class</code> if necessary. It has converted thousands of components internally at Facebook.</p>
|
||
|
||
<p>Basic usage:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">jscodeshift -t react-codemod/transforms/class.js path/to/components
|
||
</code></pre></div>
|
||
<h3>Discontinuing support for React Addons</h3>
|
||
|
||
<p>We&#39;re discontinuing active maintenance of React Addons packages. In truth, most of these packages haven&#39;t been actively maintained in a long time. They will continue to work indefinitely, but we recommend migrating away as soon as you can to prevent future breakages.</p>
|
||
|
||
<ul>
|
||
<li><strong>react-addons-create-fragment</strong> – React 16 will have first-class support for fragments, at which point this package won&#39;t be necessary. We recommend using arrays of keyed elements instead.</li>
|
||
<li><strong>react-addons-css-transition-group</strong> - Use <a href="https://github.com/reactjs/react-transition-group">react-transition-group/CSSTransitionGroup</a> instead. Version 1.1.1 provides a drop-in replacement.</li>
|
||
<li><strong>react-addons-linked-state-mixin</strong> - Explicitly set the <code>value</code> and <code>onChange</code> handler instead.</li>
|
||
<li><strong>react-addons-pure-render-mixin</strong> - Use <a href="/react/docs/react-api.html#react.purecomponent"><code>React.PureComponent</code></a> instead.</li>
|
||
<li><strong>react-addons-shallow-compare</strong> - Use <a href="/react/docs/react-api.html#react.purecomponent"><code>React.PureComponent</code></a> instead.</li>
|
||
<li><strong>react-addons-transition-group</strong> - Use <a href="https://github.com/reactjs/react-transition-group">react-transition-group/TransitionGroup</a> instead. Version 1.1.1 provides a drop-in replacement.</li>
|
||
<li><strong>react-addons-update</strong> - Use <a href="https://github.com/kolodny/immutability-helper">immutability-helper</a> instead, a drop-in replacement.</li>
|
||
<li><strong>react-linked-input</strong> - Explicitly set the <code>value</code> and <code>onChange</code> handler instead.</li>
|
||
</ul>
|
||
|
||
<p>We&#39;re also discontinuing support for the <code>react-with-addons</code> UMD build. It will be removed in React 16.</p>
|
||
|
||
<h3>React Test Utils</h3>
|
||
|
||
<p>Currently, the React Test Utils live inside <code>react-addons-test-utils</code>. As of 15.5, we&#39;re deprecating that package and moving them to <code>react-dom/test-utils</code> instead:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// Before (15.4 and below)</span>
|
||
<span class="kr">import</span> <span class="nx">TestUtils</span> <span class="nx">from</span> <span class="s1">&#39;react-addons-test-utils&#39;</span><span class="p">;</span>
|
||
|
||
<span class="c1">// After (15.5)</span>
|
||
<span class="kr">import</span> <span class="nx">TestUtils</span> <span class="nx">from</span> <span class="s1">&#39;react-dom/test-utils&#39;</span><span class="p">;</span>
|
||
</code></pre></div>
|
||
<p>This reflects the fact that what we call the Test Utils are really a set of APIs that wrap the DOM renderer.</p>
|
||
|
||
<p>The exception is shallow rendering, which is not DOM-specific. The shallow renderer has been moved to <code>react-test-renderer/shallow</code>.</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// Before (15.4 and below)</span>
|
||
<span class="hll"><span class="kr">import</span> <span class="p">{</span> <span class="nx">createRenderer</span> <span class="p">}</span> <span class="nx">from</span> <span class="s1">&#39;react-addons-test-utils&#39;</span><span class="p">;</span>
|
||
</span>
|
||
<span class="c1">// After (15.5)</span>
|
||
<span class="hll"><span class="kr">import</span> <span class="p">{</span> <span class="nx">createRenderer</span> <span class="p">}</span> <span class="nx">from</span> <span class="s1">&#39;react-test-renderer/shallow&#39;</span><span class="p">;</span>
|
||
</span></code></pre></div>
|
||
<hr>
|
||
|
||
<h2>Acknowledgements</h2>
|
||
|
||
<p>A special thank you to these folks for transferring ownership of npm package names:</p>
|
||
|
||
<ul>
|
||
<li><a href="https://github.com/developit">Jason Miller</a></li>
|
||
<li><a href="https://github.com/aackerman">Aaron Ackerman</a></li>
|
||
<li><a href="https://github.com/viniciusmarson">Vinicius Marson</a></li>
|
||
</ul>
|
||
|
||
<hr>
|
||
|
||
<h2>Installation</h2>
|
||
|
||
<p>We recommend using <a href="https://yarnpkg.com/">Yarn</a> or <a href="https://www.npmjs.com/">npm</a> for managing front-end dependencies. If you&#39;re new to package managers, the <a href="https://yarnpkg.com/en/docs/getting-started">Yarn documentation</a> is a good place to get started.</p>
|
||
|
||
<p>To install React with Yarn, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">yarn add react@^15.5.0 react-dom@^15.5.0
|
||
</code></pre></div>
|
||
<p>To install React with npm, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">npm install --save react@^15.5.0 react-dom@^15.5.0
|
||
</code></pre></div>
|
||
<p>We recommend using a bundler like <a href="https://webpack.js.org/">webpack</a> or <a href="http://browserify.org/">Browserify</a> so you can write modular code and bundle it together into small packages to optimize load time.</p>
|
||
|
||
<p>Remember that by default, React runs extra checks and provides helpful warnings in development mode. When deploying your app, make sure to <a href="/react/docs/installation.html#development-and-production-versions">compile it in production mode</a>.</p>
|
||
|
||
<p>In case you don&#39;t use a bundler, we also provide pre-built bundles in the npm packages which you can <a href="/react/docs/installation.html#using-a-cdn">include as script tags</a> on your page:</p>
|
||
|
||
<ul>
|
||
<li><strong>React</strong><br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.5.0/dist/react.js">react/dist/react.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.5.0/dist/react.min.js">react/dist/react.min.js</a><br></li>
|
||
<li><strong>React with Add-Ons</strong><br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.5.0/dist/react-with-addons.js">react/dist/react-with-addons.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.5.0/dist/react-with-addons.min.js">react/dist/react-with-addons.min.js</a><br></li>
|
||
<li><strong>React DOM</strong> (include React in the page before React DOM)<br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.5.0/dist/react-dom.js">react-dom/dist/react-dom.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.5.0/dist/react-dom.min.js">react-dom/dist/react-dom.min.js</a><br></li>
|
||
<li><strong>React DOM Server</strong> (include React in the page before React DOM Server)<br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.5.0/dist/react-dom-server.js">react-dom/dist/react-dom-server.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.5.0/dist/react-dom-server.min.js">react-dom/dist/react-dom-server.min.js</a></li>
|
||
</ul>
|
||
|
||
<p>We&#39;ve also published version <code>15.5.0</code> of the <code>react</code>, <code>react-dom</code>, and addons packages on npm and the <code>react</code> package on bower.</p>
|
||
|
||
<hr>
|
||
|
||
<h2>Changelog</h2>
|
||
|
||
<h2>15.5.0 (April 7, 2017)</h2>
|
||
|
||
<h3>React</h3>
|
||
|
||
<ul>
|
||
<li>Added a deprecation warning for <code>React.createClass</code>. Points users to create-react-class instead. (<a href="https://github.com/acdlite">@acdlite</a> in <a href="https://github.com/facebook/react/commit/d9a4fa4f51c6da895e1655f32255cf72c0fe620e">d9a4fa4</a>)</li>
|
||
<li>Added a deprecation warning for <code>React.PropTypes</code>. Points users to prop-types instead. (<a href="https://github.com/acdlite">@acdlite</a> in <a href="https://github.com/facebook/react/commit/043845ce75ea0812286bbbd9d34994bb7e01eb28">043845c</a>)</li>
|
||
<li>Fixed an issue when using <code>ReactDOM</code> together with <code>ReactDOMServer</code>. (<a href="https://github.com/wacii">@wacii</a> in <a href="https://github.com/facebook/react/pull/9005">#9005</a>)</li>
|
||
<li>Fixed issue with Closure Compiler. (<a href="https://github.com/anmonteiro">@anmonteiro</a> in <a href="https://github.com/facebook/react/pull/8895">#8895</a>)</li>
|
||
<li>Another fix for Closure Compiler. (<a href="https://github.com/Shastel">@Shastel</a> in <a href="https://github.com/facebook/react/pull/8882">#8882</a>)</li>
|
||
<li>Added component stack info to invalid element type warning. (<a href="https://github.com/n3tr">@n3tr</a> in <a href="https://github.com/facebook/react/pull/8495">#8495</a>)</li>
|
||
</ul>
|
||
|
||
<h3>React DOM</h3>
|
||
|
||
<ul>
|
||
<li>Fixed Chrome bug when backspacing in number inputs. (<a href="https://github.com/nhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/7359">#7359</a>)</li>
|
||
<li>Added <code>react-dom/test-utils</code>, which exports the React Test Utils. (<a href="https://github.com/bvaughn">@bvaughn</a>)</li>
|
||
</ul>
|
||
|
||
<h3>React Test Renderer</h3>
|
||
|
||
<ul>
|
||
<li>Fixed bug where <code>componentWillUnmount</code> was not called for children. (<a href="https://github.com/gre">@gre</a> in <a href="https://github.com/facebook/react/pull/8512">#8512</a>)</li>
|
||
<li>Added <code>react-test-renderer/shallow</code>, which exports the shallow renderer. (<a href="https://github.com/bvaughn">@bvaughn</a>)</li>
|
||
</ul>
|
||
|
||
<h3>React Addons</h3>
|
||
|
||
<ul>
|
||
<li>Last release for addons; they will no longer be actively maintained.</li>
|
||
<li>Removed <code>peerDependencies</code> so that addons continue to work indefinitely. (<a href="https://github.com/acdlite">@acdlite</a> and <a href="https://github.com/bvaughn">@bvaughn</a> in <a href="https://github.com/facebook/react/commit/8a06cd7a786822fce229197cac8125a551e8abfa">8a06cd7</a> and <a href="https://github.com/facebook/react/commit/67a8db3650d724a51e70be130e9008806402678a">67a8db3</a>)</li>
|
||
<li>Updated to remove references to <code>React.createClass</code> and <code>React.PropTypes</code> (<a href="https://github.com/acdlite">@acdlite</a> in <a href="https://github.com/facebook/react/commit/12a96b94823d6b6de6b1ac13bd576864abd50175">12a96b9</a>)</li>
|
||
<li><code>react-addons-test-utils</code> is deprecated. Use <code>react-dom/test-utils</code> and <code>react-test-renderer/shallow</code> instead. (<a href="https://github.com/bvaughn">@bvaughn</a>)</li>
|
||
</ul>
|
||
</description>
|
||
<pubDate>2017-04-07T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>React v15.4.0</title>
|
||
<description><p>Today we are releasing React 15.4.0.</p>
|
||
|
||
<p>We didn&#39;t announce the <a href="https://github.com/facebook/react/blob/master/CHANGELOG.md#1510-may-20-2016">previous</a> <a href="https://github.com/facebook/react/blob/master/CHANGELOG.md#1520-july-1-2016">minor</a> <a href="https://github.com/facebook/react/blob/master/CHANGELOG.md#1530-july-29-2016">releases</a> on the blog because most of the changes were bug fixes. However, 15.4.0 is a special release, and we would like to highlight a few notable changes in it.</p>
|
||
|
||
<h3>Separating React and React DOM</h3>
|
||
|
||
<p><a href="/react/blog/2015/09/10/react-v0.14-rc1.html#two-packages-react-and-react-dom">More than a year ago</a>, we started separating React and React DOM into separate packages. We deprecated <code>React.render()</code> in favor of <code>ReactDOM.render()</code> in React 0.14, and removed DOM-specific APIs from <code>React</code> completely in React 15. However, the React DOM implementation still <a href="https://www.reddit.com/r/javascript/comments/3m6wyu/found_this_line_in_the_react_codebase_made_me/cvcyo4a/">secretly lived inside the React package</a>.</p>
|
||
|
||
<p>In React 15.4.0, we are finally moving React DOM implementation to the React DOM package. The React package will now contain only the renderer-agnostic code such as <code>React.Component</code> and <code>React.createElement()</code>.</p>
|
||
|
||
<p>This solves a few long-standing issues, such as <a href="https://github.com/facebook/react/issues/7386">errors</a> when you import React DOM in the same file as the <a href="https://facebook.github.io/jest/blog/2016/07/27/jest-14.html">snapshot testing</a> renderer.</p>
|
||
|
||
<p><strong>If you only use the official and documented React APIs you won&#39;t need to change anything in your application.</strong></p>
|
||
|
||
<p>However, there is a possibility that you imported private APIs from <code>react/lib/*</code>, or that a package you rely on might use them. We would like to remind you that this was never supported, and that your apps should not rely on internal APIs. The React internals will keep changing as we work to make React better.</p>
|
||
|
||
<p>Another thing to watch out for is that React DOM Server is now about the same size as React DOM since it contains its own copy of the React reconciler. We don&#39;t recommend using React DOM Server on the client in most cases.</p>
|
||
|
||
<h3>Profiling Components with Chrome Timeline</h3>
|
||
|
||
<p>You can now visualize React components in the Chrome Timeline. This lets you see which components exactly get mounted, updated, and unmounted, how much time they take relative to each other.</p>
|
||
|
||
<p><center><img src="/react/img/blog/react-perf-chrome-timeline.png" width="651" height="228" alt="React components in Chrome timeline" /></center></p>
|
||
|
||
<p>To use it:</p>
|
||
|
||
<ol>
|
||
<li><p>Load your app with <code>?react_perf</code> in the query string (for example, <code>http://localhost:3000/?react_perf</code>).</p></li>
|
||
<li><p>Open the Chrome DevTools <strong>Timeline</strong> tab and press <strong>Record</strong>.</p></li>
|
||
<li><p>Perform the actions you want to profile. Don&#39;t record more than 20 seconds or Chrome might hang.</p></li>
|
||
<li><p>Stop recording.</p></li>
|
||
<li><p>React events will be grouped under the <strong>User Timing</strong> label.</p></li>
|
||
</ol>
|
||
|
||
<p>Note that the numbers are relative so components will render faster in production. Still, this should help you realize when unrelated UI gets updated by mistake, and how deep and how often your UI updates occur.</p>
|
||
|
||
<p>Currently Chrome, Edge, and IE are the only browsers supporting this feature, but we use the standard <a href="https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API">User Timing API</a> so we expect more browsers to add support for it.</p>
|
||
|
||
<h3>Mocking Refs for Snapshot Testing</h3>
|
||
|
||
<p>If you&#39;re using Jest <a href="https://facebook.github.io/jest/blog/2016/07/27/jest-14.html">snapshot testing</a>, you might have had <a href="https://github.com/facebook/react/issues/7371">issues</a> with components that rely on refs. With React 15.4.0, we introduce a way to provide mock refs to the test renderer. For example, consider this component using a ref in <code>componentDidMount</code>:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kr">import</span> <span class="nx">React</span> <span class="nx">from</span> <span class="s1">&#39;react&#39;</span><span class="p">;</span>
|
||
|
||
<span class="kr">export</span> <span class="k">default</span> <span class="kr">class</span> <span class="nx">MyInput</span> <span class="kr">extends</span> <span class="nx">React</span><span class="p">.</span><span class="nx">Component</span> <span class="p">{</span>
|
||
<span class="nx">componentDidMount</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="hll"> <span class="k">this</span><span class="p">.</span><span class="nx">input</span><span class="p">.</span><span class="nx">focus</span><span class="p">();</span>
|
||
</span> <span class="p">}</span>
|
||
|
||
<span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="p">(</span>
|
||
<span class="o">&lt;</span><span class="nx">input</span>
|
||
<span class="hll"> <span class="nx">ref</span><span class="o">=</span><span class="p">{</span><span class="nx">node</span> <span class="o">=&gt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">input</span> <span class="o">=</span> <span class="nx">node</span><span class="p">}</span>
|
||
</span> <span class="o">/&gt;</span>
|
||
<span class="p">);</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>With snapshot renderer, <code>this.input</code> will be <code>null</code> because there is no DOM. React 15.4.0 lets us avoid such crashes by passing a custom <code>createNodeMock</code> function to the snapshot renderer in an <code>options</code> argument:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kr">import</span> <span class="nx">React</span> <span class="nx">from</span> <span class="s1">&#39;react&#39;</span><span class="p">;</span>
|
||
<span class="kr">import</span> <span class="nx">MyInput</span> <span class="nx">from</span> <span class="s1">&#39;./MyInput&#39;</span><span class="p">;</span>
|
||
<span class="kr">import</span> <span class="nx">renderer</span> <span class="nx">from</span> <span class="s1">&#39;react-test-renderer&#39;</span><span class="p">;</span>
|
||
|
||
<span class="hll"><span class="kd">function</span> <span class="nx">createNodeMock</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
|
||
</span><span class="hll"> <span class="k">if</span> <span class="p">(</span><span class="nx">element</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s1">&#39;input&#39;</span><span class="p">)</span> <span class="p">{</span>
|
||
</span><span class="hll"> <span class="k">return</span> <span class="p">{</span>
|
||
</span><span class="hll"> <span class="nx">focus</span><span class="p">()</span> <span class="p">{},</span>
|
||
</span><span class="hll"> <span class="p">};</span>
|
||
</span><span class="hll"> <span class="p">}</span>
|
||
</span><span class="hll"> <span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
|
||
</span><span class="hll"><span class="p">}</span>
|
||
</span>
|
||
<span class="nx">it</span><span class="p">(</span><span class="s1">&#39;renders correctly&#39;</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
|
||
<span class="kr">const</span> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span><span class="nx">createNodeMock</span><span class="p">};</span>
|
||
<span class="hll"> <span class="kr">const</span> <span class="nx">tree</span> <span class="o">=</span> <span class="nx">renderer</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="o">&lt;</span><span class="nx">MyInput</span> <span class="o">/&gt;</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
|
||
</span> <span class="nx">expect</span><span class="p">(</span><span class="nx">tree</span><span class="p">).</span><span class="nx">toMatchSnapshot</span><span class="p">();</span>
|
||
<span class="p">});</span>
|
||
</code></pre></div>
|
||
<p>We would like to thank <a href="https://github.com/Aweary">Brandon Dail</a> for implementing this feature.</p>
|
||
|
||
<p>You can learn more about snapshot testing in <a href="https://facebook.github.io/jest/blog/2016/07/27/jest-14.html">this Jest blog post</a>.</p>
|
||
|
||
<hr>
|
||
|
||
<h2>Installation</h2>
|
||
|
||
<p>We recommend using <a href="https://yarnpkg.com/">Yarn</a> or <a href="https://www.npmjs.com/">npm</a> for managing front-end dependencies. If you&#39;re new to package managers, the <a href="https://yarnpkg.com/en/docs/getting-started">Yarn documentation</a> is a good place to get started.</p>
|
||
|
||
<p>To install React with Yarn, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">yarn add react@15.4.0 react-dom@15.4.0
|
||
</code></pre></div>
|
||
<p>To install React with npm, run:</p>
|
||
<div class="highlight"><pre><code class="language-bash" data-lang="bash">npm install --save react@15.4.0 react-dom@15.4.0
|
||
</code></pre></div>
|
||
<p>We recommend using a bundler like <a href="https://webpack.js.org/">webpack</a> or <a href="http://browserify.org/">Browserify</a> so you can write modular code and bundle it together into small packages to optimize load time.</p>
|
||
|
||
<p>Remember that by default, React runs extra checks and provides helpful warnings in development mode. When deploying your app, make sure to <a href="/react/docs/installation.html#development-and-production-versions">compile it in production mode</a>.</p>
|
||
|
||
<p>In case you don&#39;t use a bundler, we also provide pre-built bundles in the npm packages which you can <a href="/react/docs/installation.html#using-a-cdn">include as script tags</a> on your page:</p>
|
||
|
||
<ul>
|
||
<li><strong>React</strong><br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.4.0/dist/react.js">react/dist/react.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.4.0/dist/react.min.js">react/dist/react.min.js</a><br></li>
|
||
<li><strong>React with Add-Ons</strong><br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react@15.4.0/dist/react-with-addons.js">react/dist/react-with-addons.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react@15.4.0/dist/react-with-addons.min.js">react/dist/react-with-addons.min.js</a><br></li>
|
||
<li><strong>React DOM</strong> (include React in the page before React DOM)<br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.4.0/dist/react-dom.js">react-dom/dist/react-dom.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.4.0/dist/react-dom.min.js">react-dom/dist/react-dom.min.js</a><br></li>
|
||
<li><strong>React DOM Server</strong> (include React in the page before React DOM Server)<br>
|
||
Dev build with warnings: <a href="https://unpkg.com/react-dom@15.4.0/dist/react-dom-server.js">react-dom/dist/react-dom-server.js</a><br>
|
||
Minified build for production: <a href="https://unpkg.com/react-dom@15.4.0/dist/react-dom-server.min.js">react-dom/dist/react-dom-server.min.js</a></li>
|
||
</ul>
|
||
|
||
<p>We&#39;ve also published version <code>15.4.0</code> of the <code>react</code>, <code>react-dom</code>, and addons packages on npm and the <code>react</code> package on bower.</p>
|
||
|
||
<hr>
|
||
|
||
<h2>Changelog</h2>
|
||
|
||
<h3>React</h3>
|
||
|
||
<ul>
|
||
<li>React package and browser build no longer &quot;secretly&quot; includes React DOM.<br>
|
||
<small>(<a href="https://github.com/sebmarkbage">@sebmarkbage</a> in <a href="https://github.com/facebook/react/pull/7164">#7164</a> and <a href="https://github.com/facebook/react/pull/7168">#7168</a>)</small></li>
|
||
<li>Required PropTypes now fail with specific messages for null and undefined.<br>
|
||
<small>(<a href="https://github.com/chenglou">@chenglou</a> in <a href="https://github.com/facebook/react/pull/7291">#7291</a>)</small></li>
|
||
<li>Improved development performance by freezing children instead of copying.<br>
|
||
<small>(<a href="https://github.com/keyanzhang">@keyanzhang</a> in <a href="https://github.com/facebook/react/pull/7455">#7455</a>)</small></li>
|
||
</ul>
|
||
|
||
<h3>React DOM</h3>
|
||
|
||
<ul>
|
||
<li>Fixed occasional test failures when React DOM is used together with shallow renderer.<br>
|
||
<small>(<a href="https://github.com/goatslacker">@goatslacker</a> in <a href="https://github.com/facebook/react/pull/8097">#8097</a>)</small></li>
|
||
<li>Added a warning for invalid <code>aria-</code> attributes.<br>
|
||
<small>(<a href="https://github.com/jessebeach">@jessebeach</a> in <a href="https://github.com/facebook/react/pull/7744">#7744</a>)</small></li>
|
||
<li>Added a warning for using <code>autofocus</code> rather than <code>autoFocus</code>.<br>
|
||
<small>(<a href="https://github.com/hkal">@hkal</a> in <a href="https://github.com/facebook/react/pull/7694">#7694</a>)</small></li>
|
||
<li>Removed an unnecessary warning about polyfilling <code>String.prototype.split</code>.<br>
|
||
<small>(<a href="https://github.com/nhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/7629">#7629</a>)</small></li>
|
||
<li>Clarified the warning about not calling PropTypes manually.<br>
|
||
<small>(<a href="https://github.com/jedwards1211">@jedwards1211</a> in <a href="https://github.com/facebook/react/pull/7777">#7777</a>)</small></li>
|
||
<li>The unstable <code>batchedUpdates</code> API now passes the wrapped function&#39;s return value through.<br>
|
||
<small>(<a href="https://github.com/bgnorlov">@bgnorlov</a> in <a href="https://github.com/facebook/react/pull/7444">#7444</a>)</small></li>
|
||
<li>Fixed a bug with updating text in IE 8.<br>
|
||
<small>(<a href="https://github.com/mnpenner">@mnpenner</a> in <a href="https://github.com/facebook/react/pull/7832">#7832</a>)</small></li>
|
||
</ul>
|
||
|
||
<h3>React Perf</h3>
|
||
|
||
<ul>
|
||
<li>When ReactPerf is started, you can now view the relative time spent in components as a chart in Chrome Timeline.<br>
|
||
<small>(<a href="https://github.com/gaearon">@gaearon</a> in <a href="https://github.com/facebook/react/pull/7549">#7549</a>)</small></li>
|
||
</ul>
|
||
|
||
<h3>React Test Utils</h3>
|
||
|
||
<ul>
|
||
<li>If you call <code>Simulate.click()</code> on a <code>&lt;input disabled onClick={foo} /&gt;</code> then <code>foo</code> will get called whereas it didn&#39;t before.<br>
|
||
<small>(<a href="https://github.com/nhunzaker">@nhunzaker</a> in <a href="https://github.com/facebook/react/pull/7642">#7642</a>)</small></li>
|
||
</ul>
|
||
|
||
<h3>React Test Renderer</h3>
|
||
|
||
<ul>
|
||
<li>Due to packaging changes, it no longer crashes when imported together with React DOM in the same file.<br>
|
||
<small>(<a href="https://github.com/sebmarkbage">@sebmarkbage</a> in <a href="https://github.com/facebook/react/pull/7164">#7164</a> and <a href="https://github.com/facebook/react/pull/7168">#7168</a>)</small></li>
|
||
<li><code>ReactTestRenderer.create()</code> now accepts <code>{createNodeMock: element =&gt; mock}</code> as an optional argument so you can mock refs with snapshot testing.<br>
|
||
<small>(<a href="https://github.com/Aweary">@Aweary</a> in <a href="https://github.com/facebook/react/pull/7649">#7649</a> and <a href="https://github.com/facebook/react/pull/8261">#8261</a>)</small></li>
|
||
</ul>
|
||
</description>
|
||
<pubDate>2016-11-16T00:00:00-08:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2016/11/16/react-v15.4.0.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2016/11/16/react-v15.4.0.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Our First 50,000 Stars</title>
|
||
<description><p>Just three and a half years ago we open sourced a little JavaScript library called React. The journey since that day has been incredibly exciting.</p>
|
||
|
||
<h2>Commemorative T-Shirt</h2>
|
||
|
||
<p>In order to celebrate 50,000 GitHub stars, <a href="http://www.maggieappleton.com/">Maggie Appleton</a> from <a href="http://egghead.io/">egghead.io</a> has designed us a special T-shirt, which will be available for purchase from Teespring <strong>only for a week</strong> through Thursday, October 6. Maggie also wrote <a href="https://www.behance.net/gallery/43269677/Reacts-50000-Stars-Shirt">a blog post</a> showing all the different concepts she came up with before settling on the final design.</p>
|
||
|
||
<p><a target="_blank" href="https://teespring.com/react-50000-stars"><img src="/react/img/blog/react-50k-tshirt.jpg" width="650" height="340" alt="React 50k Tshirt" /></a></p>
|
||
|
||
<p>The T-shirts are super soft using American Apparel&#39;s tri-blend fabric; we also have kids and toddler T-shirts and baby onesies available.</p>
|
||
|
||
<ul>
|
||
<li><a href="https://teespring.com/react-50000-stars">Adult T-shirts (straight-cut and fitted)</a></li>
|
||
<li><a href="https://teespring.com/react-50000-stars-kids">Kids T-shirts</a></li>
|
||
<li><a href="https://teespring.com/react-50000-stars-toddler">Toddler T-Shirts</a></li>
|
||
<li><a href="https://teespring.com/react-50000-stars-baby">Baby Onesies</a></li>
|
||
</ul>
|
||
|
||
<p>Proceeds from the shirts will be donated to <a href="http://www.code2040.org/">CODE2040</a>, a nonprofit that creates access, awareness, and opportunities in technology for underrepresented minorities with a specific focus on Black and Latinx talent.</p>
|
||
|
||
<h2>Archeology</h2>
|
||
|
||
<p>We&#39;ve spent a lot of time trying to explain the concepts behind React and the problems it attempts to solve, but we haven&#39;t talked much about how React evolved before being open sourced. This milestone seemed like as good a time as any to dig through the earliest commits and share some of the more important moments and fun facts.</p>
|
||
|
||
<p>The story begins in our ads org, where we were building incredibly sophisticated client side web apps using an internal MVC framework called <a href="http://web.archive.org/web/20130608154901/http://shaneosullivan.github.io/boltjs/intro.html">BoltJS</a>. Here&#39;s a sample of what some Bolt code looked like:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">var</span> <span class="nx">CarView</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;javelin/core&#39;</span><span class="p">).</span><span class="nx">createClass</span><span class="p">({</span>
|
||
<span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;CarView&#39;</span><span class="p">,</span>
|
||
<span class="nx">extend</span><span class="o">:</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;container&#39;</span><span class="p">).</span><span class="nx">Container</span><span class="p">,</span>
|
||
<span class="nx">properties</span><span class="o">:</span> <span class="p">{</span>
|
||
<span class="nx">wheels</span><span class="o">:</span> <span class="mi">4</span><span class="p">,</span>
|
||
<span class="p">},</span>
|
||
<span class="nx">declare</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="p">{</span>
|
||
<span class="nx">childViews</span><span class="o">:</span> <span class="p">[</span>
|
||
<span class="p">{</span> <span class="nx">content</span><span class="o">:</span> <span class="s1">&#39;I have &#39;</span> <span class="p">},</span>
|
||
<span class="p">{</span> <span class="nx">ref</span><span class="o">:</span> <span class="s1">&#39;wheelView&#39;</span> <span class="p">},</span>
|
||
<span class="p">{</span> <span class="nx">content</span><span class="o">:</span> <span class="s1">&#39; wheels&#39;</span> <span class="p">}</span>
|
||
<span class="p">]</span>
|
||
<span class="p">};</span>
|
||
<span class="p">},</span>
|
||
<span class="nx">setWheels</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">wheels</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="k">this</span><span class="p">.</span><span class="nx">findRef</span><span class="p">(</span><span class="s1">&#39;wheelView&#39;</span><span class="p">).</span><span class="nx">setContent</span><span class="p">(</span><span class="nx">wheels</span><span class="p">);</span>
|
||
<span class="p">},</span>
|
||
<span class="nx">getWheels</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">findRef</span><span class="p">(</span><span class="s1">&#39;wheelView&#39;</span><span class="p">).</span><span class="nx">getContent</span><span class="p">();</span>
|
||
<span class="p">},</span>
|
||
<span class="p">});</span>
|
||
|
||
<span class="kd">var</span> <span class="nx">car</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CarView</span><span class="p">();</span>
|
||
<span class="nx">car</span><span class="p">.</span><span class="nx">setWheels</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span>
|
||
<span class="nx">car</span><span class="p">.</span><span class="nx">placeIn</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</span><span class="p">);</span>
|
||
<span class="c1">//&lt;div&gt;</span>
|
||
<span class="c1">// &lt;div&gt;I have &lt;/div&gt;</span>
|
||
<span class="c1">// &lt;div&gt;3&lt;/div&gt;</span>
|
||
<span class="c1">// &lt;div&gt; wheels&lt;/div&gt;</span>
|
||
<span class="c1">//&lt;/div&gt;</span>
|
||
</code></pre></div>
|
||
<p>Bolt introduced a number of APIs and features that would eventually make their way into React including <code>render</code>, <code>createClass</code>, and <code>refs</code>. Bolt introduced the concept of <code>refs</code> as a way to create references to nodes that can be used imperatively. This was relevant for legacy interoperability and incremental adoption, and while React would eventually strive to be a lot more functional, <code>refs</code> proved to be a very useful way to break out of the functional paradigm when the need arose.</p>
|
||
|
||
<p>But as our applications grew more and more sophisticated, our Bolt codebases got pretty complicated. Recognizing some of the framework&#39;s shortcomings, <a href="https://twitter.com/jordwalke">Jordan Walke</a> started experimenting with a side-project called <a href="https://github.com/jordwalke/FaxJs">FaxJS</a>. His goal was to solve many of the same problems as Bolt, but in a very different way. This is actually where most of React&#39;s fundamentals were born, including props, state, re-evaluating large portions of the tree to “diff” the UI, server-side rendering, and a basic concept of components.</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nx">TestProject</span><span class="p">.</span><span class="nx">PersonDisplayer</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="nx">structure</span> <span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="nx">Div</span><span class="p">({</span>
|
||
<span class="nx">classSet</span><span class="o">:</span> <span class="p">{</span> <span class="nx">personDisplayerContainer</span><span class="o">:</span> <span class="kc">true</span> <span class="p">},</span>
|
||
<span class="nx">titleDiv</span><span class="o">:</span> <span class="nx">Div</span><span class="p">({</span>
|
||
<span class="nx">classSet</span><span class="o">:</span> <span class="p">{</span> <span class="nx">personNameTitle</span><span class="o">:</span> <span class="kc">true</span> <span class="p">},</span>
|
||
<span class="nx">content</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">name</span>
|
||
<span class="p">}),</span>
|
||
<span class="nx">nestedAgeDiv</span><span class="o">:</span> <span class="nx">Div</span><span class="p">({</span>
|
||
<span class="nx">content</span><span class="o">:</span> <span class="s1">&#39;Interests: &#39;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">interests</span>
|
||
<span class="p">})</span>
|
||
<span class="p">});</span>
|
||
<span class="p">}</span>
|
||
<span class="p">};</span>
|
||
</code></pre></div>
|
||
<h2>FBolt is Born</h2>
|
||
|
||
<p>Through his FaxJS experiment, Jordan became convinced that functional APIs — which discouraged mutation — offered a better, more scalable way to build user interfaces. He imported his library into Facebook&#39;s codebase in March of 2012 and renamed it “FBolt”, signifying an extension of Bolt where components are written in a functional programming style. Or maybe “FBolt” was a nod to FaxJS – he didn&#39;t tell us! ;)</p>
|
||
|
||
<p>The interoperability between FBolt and Bolt allowed us to experiment with replacing just one component at a time with more functional component APIs. We could test the waters of this new functional paradigm, without having to go all in. We started with the components that were clearly best expressed functionally and then we would later continue to push the boundaries of what we could express as functions.</p>
|
||
|
||
<p>Realizing that FBolt wouldn&#39;t be a great name for the library when used on its own, Jordan Walke and <a href="https://twitter.com/tomocchino">Tom Occhino</a> decided on a new name: “React.” After Tom sent out the diff to rename everything to React, Jordan commented:</p>
|
||
|
||
<blockquote>
|
||
<p>Jordan Walke:
|
||
I might add for the sake of discussion, that many systems advertise some kind of reactivity, but they usually require that you set up some kind of point-to-point listeners and won&#39;t work on structured data. This API reacts to any state or property changes, and works with data of any form (as deeply structured as the graph itself) so I think the name is fitting.</p>
|
||
</blockquote>
|
||
|
||
<p>Most of Tom&#39;s other commits at the time were on the first version of <a href="https://github.com/graphql/graphiql">GraphiQL</a>, a project which was recently open sourced.</p>
|
||
|
||
<h2>Adding JSX</h2>
|
||
|
||
<p>Since about 2010 Facebook has been using an extension of PHP called <a href="https://www.facebook.com/notes/facebook-engineering/xhp-a-new-way-to-write-php/294003943919/">XHP</a>, which enables engineers to create UIs using XML literals right inside their PHP code. It was first introduced to help prevent XSS holes but ended up being an excellent way to structure applications with custom components.</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kr">final</span> <span class="kr">class</span> <span class="o">:</span><span class="nx">a</span><span class="o">:</span><span class="nx">post</span> <span class="kr">extends</span> <span class="o">:</span><span class="nx">x</span><span class="o">:</span><span class="nx">element</span> <span class="p">{</span>
|
||
<span class="nx">attribute</span> <span class="o">:</span><span class="nx">a</span><span class="p">;</span>
|
||
<span class="kr">protected</span> <span class="kd">function</span> <span class="nx">render</span><span class="p">()</span><span class="o">:</span> <span class="nx">XHPRoot</span> <span class="p">{</span>
|
||
<span class="nx">$anchor</span> <span class="o">=</span> <span class="o">&lt;</span><span class="nx">a</span><span class="o">&gt;</span><span class="p">{</span><span class="nx">$this</span><span class="o">-&gt;</span><span class="nx">getChildren</span><span class="p">()}</span><span class="o">&lt;</span><span class="err">/a&gt;;</span>
|
||
<span class="nx">$form</span> <span class="o">=</span> <span class="p">(</span>
|
||
<span class="o">&lt;</span><span class="nx">form</span>
|
||
<span class="nx">method</span><span class="o">=</span><span class="s2">&quot;post&quot;</span>
|
||
<span class="nx">action</span><span class="o">=</span><span class="p">{</span><span class="nx">$this</span><span class="o">-&gt;:</span><span class="nx">href</span><span class="p">}</span>
|
||
<span class="nx">target</span><span class="o">=</span><span class="p">{</span><span class="nx">$this</span><span class="o">-&gt;:</span><span class="nx">target</span><span class="p">}</span>
|
||
<span class="kr">class</span><span class="o">=</span><span class="s2">&quot;postLink&quot;</span>
|
||
<span class="o">&gt;</span><span class="p">{</span><span class="nx">$anchor</span><span class="p">}</span><span class="o">&lt;</span><span class="err">/form&gt;</span>
|
||
<span class="p">);</span>
|
||
<span class="nx">$this</span><span class="o">-&gt;</span><span class="nx">transferAllAttributes</span><span class="p">(</span><span class="nx">$anchor</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="nx">$form</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>Before Jordan&#39;s work had even made its way into the Facebook codebase, Adam Hupp implemented an XHP-like concept for JavaScript, written in Haskell. This system enabled you to write the following inside a JavaScript file:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="o">:</span><span class="nx">example</span><span class="o">:</span><span class="nx">hello</span><span class="p">(</span><span class="nx">attrib</span><span class="p">,</span> <span class="nx">children</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="p">(</span>
|
||
<span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;special&quot;</span><span class="o">&gt;</span>
|
||
<span class="o">&lt;</span><span class="nx">h1</span><span class="o">&gt;</span><span class="nx">Hello</span><span class="p">,</span> <span class="nx">World</span><span class="o">!&lt;</span><span class="err">/h1&gt;</span>
|
||
<span class="p">{</span><span class="nx">children</span><span class="p">}</span>
|
||
<span class="o">&lt;</span><span class="err">/div&gt;</span>
|
||
<span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>It would compile the above into the following normal ES3-compatible JavaScript:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">jsx_example_hello</span><span class="p">(</span><span class="nx">attrib</span><span class="p">,</span> <span class="nx">children</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="k">return</span> <span class="p">(</span>
|
||
<span class="nx">S</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s2">&quot;div&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;class&quot;</span><span class="o">:</span> <span class="s2">&quot;special&quot;</span><span class="p">},</span> <span class="p">[</span>
|
||
<span class="nx">S</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s2">&quot;h1&quot;</span><span class="p">,</span> <span class="p">{},</span> <span class="p">[</span><span class="s2">&quot;Hello, World!&quot;</span><span class="p">]),</span>
|
||
<span class="nx">children</span>
|
||
<span class="p">]</span>
|
||
<span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div>
|
||
<p>In this prototype, <code>S.create</code> would immediately create and return a DOM node. Most of the conversations on this prototype revolved around the performance characteristics of <code>innerHTML</code> versus creating DOM nodes directly. At the time, it would have been less than ideal to push developers universally in the direction of creating DOM nodes directly since it did not perform as well, especially in Firefox and IE. Facebook&#39;s then-CTO <a href="https://twitter.com/btaylor">Bret Taylor</a> chimed in on the discussion at the time in favor of <code>innerHTML</code> over <code>document.createElement</code>:</p>
|
||
|
||
<blockquote>
|
||
<p>Bret Taylor:
|
||
If you are not convinced about innerHTML, here is a small microbenchmark. It is about the same in Chrome. innerHTML is about 30% faster in the latest version of Firefox (much more in previous versions), and about 90% faster in IE8.</p>
|
||
</blockquote>
|
||
|
||
<p>This work was eventually abandoned but was revived after React made its way into the codebase. Jordan sidelined the previous performance discussions by introducing the concept of a “Virtual DOM,” though its eventual name didn&#39;t exist yet.</p>
|
||
|
||
<blockquote>
|
||
<p>Jordan Walke:
|
||
For the first step, I propose that we do the easiest, yet most general transformation possible. My suggestion is to simply map xml expressions to function call expressions.</p>
|
||
|
||
<ul>
|
||
<li><code>&lt;x&gt;&lt;/x&gt;</code> becomes <code>x( )</code></li>
|
||
<li><code>&lt;x height=12&gt;&lt;/x&gt;</code> becomes <code>x( {height:12} )</code></li>
|
||
<li><code>&lt;x&gt; &lt;y&gt; &lt;/y&gt; &lt;/x&gt;</code> becomes <code>x({ childList: [y( )] })</code></li>
|
||
</ul>
|
||
|
||
<p>At this point, JSX doesn&#39;t need to know about React - it&#39;s just a convenient way to write function calls. Coincidentally, React&#39;s primary abstraction is the function. Okay maybe it&#39;s not so coincidental ;)</p>
|
||
</blockquote>
|
||
|
||
<p>Adam made a very insightful comment, which is now the default way we write lists in React with JSX.</p>
|
||
|
||
<blockquote>
|
||
<p>Adam Hupp:
|
||
I think we should just treat arrays of elements as a frag. This is useful for constructs like:</p>
|
||
<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="o">&lt;</span><span class="nx">ul</span><span class="o">&gt;</span><span class="p">{</span><span class="nx">foo</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="o">&lt;</span><span class="nx">li</span><span class="o">&gt;</span><span class="p">{</span><span class="nx">i</span><span class="p">.</span><span class="nx">data</span><span class="p">}</span><span class="o">&lt;</span><span class="err">/li&gt;; })}&lt;/ul&gt;</span>
|
||
</code></pre></div>
|
||
<p>In this case the ul(..) will get a childList with a single child, which is itself a list.</p>
|
||
</blockquote>
|
||
|
||
<p>React didn&#39;t end up using Adam&#39;s implementation directly. Instead, we created JSX by forking <a href="https://github.com/laverdet/js-xml-literal">js-xml-literal</a>, a side project by XHP creator Marcel Laverdet. JSX took its name from js-xml-literal, which Jordan modified to just be syntactic sugar for deeply nested function calls.</p>
|
||
|
||
<h2>API Churn</h2>
|
||
|
||
<p>During the first year of React, internal adoption was growing quickly but there was quite a lot of churn in the component APIs and naming conventions:</p>
|
||
|
||
<ul>
|
||
<li><code>project</code> was renamed to <code>declare</code> then to <code>structure</code> and finally to <code>render</code>.</li>
|
||
<li><code>Componentize</code> was renamed to <code>createComponent</code> and finally to <code>createClass</code>.</li>
|
||
</ul>
|
||
|
||
<p>As the project was about to be open sourced, <a href="https://twitter.com/leeb">Lee Byron</a> sat down with Jordan Walke, Tom Occhino and Sebastian Markbåge in order to refactor, reimplement, and rename one of React&#39;s most beloved features – the lifecycle API. Lee <a href="https://gist.github.com/vjeux/f2b015d230cc1ab18ed1df30550495ed">came up with a well-designed API</a> that is still in place today.</p>
|
||
|
||
<ul>
|
||
<li>Concepts
|
||
|
||
<ul>
|
||
<li>component - a ReactComponent instance</li>
|
||
<li>state - internal state to a component</li>
|
||
<li>props - external state to a component</li>
|
||
<li>markup - the stringy HTML-ish stuff components generate</li>
|
||
<li>DOM - the document and elements within the document</li>
|
||
</ul></li>
|
||
<li>Actions
|
||
|
||
<ul>
|
||
<li>mount - to put a component into a DOM</li>
|
||
<li>initialize - to prepare a component for rendering</li>
|
||
<li>update - a transition of state (and props) resulting a render.</li>
|
||
<li>render - a side-effect-free process to get the representation (markup) of a component.</li>
|
||
<li>validate - make assertions about something created and provided</li>
|
||
<li>destroy - opposite of initialize</li>
|
||
</ul></li>
|
||
<li>Operands
|
||
|
||
<ul>
|
||
<li>create - make a new thing</li>
|
||
<li>get - get an existing thing</li>
|
||
<li>set - merge into existing</li>
|
||
<li>replace - replace existing</li>
|
||
<li>receive - respond to new data</li>
|
||
<li>force - skip checks to do action</li>
|
||
</ul></li>
|
||
<li>Notifications
|
||
|
||
<ul>
|
||
<li>shouldObjectAction</li>
|
||
<li>objectWillAction</li>
|
||
<li>objectDidAction</li>
|
||
</ul></li>
|
||
</ul>
|
||
|
||
<h2>Instagram</h2>
|
||
|
||
<p>In 2012, Instagram got acquired by Facebook. <a href="https://twitter.com/floydophone">Pete Hunt</a>, who was working on Facebook photos and videos at the time, joined their newly formed web team. He wanted to build their website completely in React, which was in stark contrast with the incremental adoption model that had been used at Facebook.</p>
|
||
|
||
<p>To make this happen, React had to be decoupled from Facebook&#39;s infrastructure, since Instagram didn&#39;t use any of it. This project acted as a forcing function to do the work needed to open source React. In the process, Pete also discovered and promoted a little project called webpack. He also implemented the <code>renderToString</code> primitive which was needed to do server-side rendering.</p>
|
||
|
||
<p>As we started to prepare for the open source launch, <a href="https://twitter.com/miekd">Maykel Loomans</a>, a designer on Instagram, made a mock of what the website could look like. The header ended up defining the visual identity of React: its logo and the electric blue color!</p>
|
||
|
||
<p><center><a target="_blank" href="/react/img/blog/react-50k-mock-full.jpg"><img src="/react/img/blog/react-50k-mock.jpg" width="400" height="410" alt="React website mock" /></a></center></p>
|
||
|
||
<p>In its earliest days, React benefited tremendously from feedback, ideas, and technical contributions of early adopters and collaborators all over the company. While it might look like an overnight success in hindsight, the story of React is actually a great example of how new ideas often need to go through several rounds of refinement, iteration, and course correction over a long period of time before reaching their full potential.</p>
|
||
|
||
<p>React&#39;s approach to building user interfaces with functional programming principles has changed the way we do things in just a few short years. It goes without saying, but React would be nothing without the amazing open source community that&#39;s built up around it!</p>
|
||
</description>
|
||
<pubDate>2016-09-28T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2016/09/28/our-first-50000-stars.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2016/09/28/our-first-50000-stars.html</guid>
|
||
</item>
|
||
|
||
<item>
|
||
<title>Relay: State of the State</title>
|
||
<description><p>This month marks a year since we released Relay and we&#39;d like to share an update on the project and what&#39;s next.</p>
|
||
|
||
<h2>A Year In Review</h2>
|
||
|
||
<p>A year after launch, we&#39;re incredibly excited to see an active community forming around Relay and that companies such as Twitter are <a href="https://fabric.io/blog/building-fabric-mission-control-with-graphql-and-relay">using Relay in production</a>:</p>
|
||
|
||
<blockquote>
|
||
<p>For a project like mission control, GraphQL and Relay were a near-perfect solution, and the cost of building it any other way justified the investment.</p>
|
||
|
||
<p>-- <cite>Fin Hopkins</cite></p>
|
||
</blockquote>
|
||
|
||
<p>This kind of positive feedback is really encouraging (I&#39;ll admit to re-reading that post far too many times), and great motivation for us to keep going and make Relay even better.</p>
|
||
|
||
<p>With the community&#39;s help we&#39;ve already come a long way since the technical preview. Here are some highlights:</p>
|
||
|
||
<ul>
|
||
<li>In March we added support for server-side rendering and for creating multiple instances of Relay on a single page. This was a coordinated effort over the course of several months by community members <a href="https://github.com/denvned">Denis Nedelyaev</a> and <a href="https://github.com/devknoll">Gerald Monaco</a> (now at Facebook).</li>
|
||
<li>Also in March we added support for React Native. While we use Relay and React Native together internally, they didn&#39;t quite work together in open-source out of the box. We owe a big thanks to <a href="https://github.com/skevy">Adam Miskiewicz</a>, <a href="https://github.com/boourns">Tom Burns</a>, <a href="https://github.com/gre">Gaëtan Renaudeau</a>, <a href="https://github.com/davidaurelio">David Aurelio</a>, <a href="https://github.com/martinbigio">Martín Bigio</a>, <a href="https://github.com/zpao">Paul O’Shannessy</a>, <a href="https://github.com/sophiebits">Sophie Alpert</a>, and many others who helped track down and resolve issues. Finally, thanks to <a href="https://github.com/steveluscher">Steven Luscher</a> for coordinating this effort and building the first Relay/ReactNative example app.</li>
|
||
</ul>
|
||
|
||
<p>We&#39;ve also seen some great open-source projects spring up around Relay:</p>
|
||
|
||
<ul>
|
||
<li><a href="https://github.com/denvned">Denis Nedelyaev</a> created <a href="https://github.com/denvned/isomorphic-relay/">isomorphic-relay</a>, a package that helps developers build server-rendered Relay apps where data is prepared on the server and then used to bootstrap the app on the client.</li>
|
||
<li><a href="https://github.com/taion">Jimmy Jia</a> created <a href="https://github.com/relay-tools/react-router-relay">react-router-relay</a> to integrate Relay data-fetching into React Router.</li>
|
||
<li><a href="https://github.com/nodkz">Pavel Chertorogov</a> released <a href="https://github.com/nodkz/react-relay-network-layer">relay-network-layer</a>, which adds features such as batching query requests, middleware, authentication, logging, and more.</li>
|
||
</ul>
|
||
|
||
<p>This is just a small sampling of the community&#39;s contributions. So far we&#39;ve merged over 300 PRs - about 25% of our commits - from over 80 of you. These PRs have improved everything from the website and docs down the very core of the framework. We&#39;re humbled by these outstanding contributions and excited to keep working with each of you!</p>
|
||
|
||
<h1>Retrospective &amp; Roadmap</h1>
|
||
|
||
<p>Earlier this year we paused to reflect on the state of the project. What was working well? What could be improved? What features should we add, and what could we remove? A few themes emerged: performance on mobile, developer experience, and empowering the community.</p>
|
||
|
||
<h2>Mobile Perf</h2>
|
||
|
||
<p>First, Relay was built to serve the needs of product developers at Facebook. In 2016, that means helping developers to build apps that work well on <a href="https://newsroom.fb.com/news/2015/10/news-feed-fyi-building-for-all-connectivity/">mobile devices connecting on slower networks</a>. For example, people in developing markets commonly use <a href="https://code.facebook.com/posts/307478339448736/year-class-a-classification-system-for-android/">2011 year-class phones</a> and connect via <a href="https://code.facebook.com/posts/952628711437136/classes-performance-and-network-segmentation-on-android/">2G class networks</a>. These scenarios present their own challenges.</p>
|
||
|
||
<p>Therefore, one of our primary goals this year is to optimize Relay for performance on low-end mobile devices <em>first</em>, knowing that this can translate to improved performance on high-end devices as well. In addition to standard approaches such as benchmarking, profiling, and optimizations, we&#39;re also working on big-picture changes.</p>
|
||
|
||
<p>For example, in today&#39;s Relay, here&#39;s what happens when an app is opened. First, React Native starts initializing the JavaScript context (loading and parsing your code and then running it). When this finishes, the app executes and Relay sees that you need data. It constructs and prints the query, uploads the query text to the server, processes the response, and renders your app. (Note that this process applies on the web, except that the code has to be <em>downloaded</em> instead of loaded from the device.)</p>
|
||
|
||
<p>Ideally, though, we could begin fetching data as soon as the native code had loaded - in parallel with the JS context initialization. By the time your JS code was ready to run, the data-fetching would already be under way. To do this we would need a way to determine <em>statically</em> - at build time - what query an application would send.</p>
|
||
|
||
<p>The key is that GraphQL is already static - we just need to fully embrace this fact. More on this later.</p>
|
||
|
||
<h2>Developer Experience</h2>
|
||
|
||
<p>Next, we&#39;ve paid attention to the community&#39;s feedback and know that, to put it simply, Relay could be &quot;easier&quot; to use (and &quot;simpler&quot; too). This isn&#39;t entirely surprising to us - Relay was originally designed as a routing library and gradually morphed into a data-fetching library. Concepts like Relay &quot;routes&quot;, for example, no longer serve as critical a role and are just one more concept that developers have to learn about. Another example is mutations: while writes <em>are</em> inherently more complex than reads, our API doesn&#39;t make the simple things simple enough.</p>
|
||
|
||
<p>Alongside our focus on mobile performance, we&#39;ve also kept the developer experience in mind as we evolve Relay core.</p>
|
||
|
||
<h2>Empowering the Community</h2>
|
||
|
||
<p>Finally, we want to make it easier for people in the community to develop useful libraries that work with Relay. By comparison, React&#39;s small surface area - components - allows developers to build cool things like routing, higher-order components, or reusable text editors. For Relay, this would mean having the framework provide core primitives that users can build upon. We want it to be possible for the community to integrate Relay with view libraries other than React, or to build real-time subscriptions as a complementary library.</p>
|
||
|
||
<h1>What&#39;s Next</h1>
|
||
|
||
<p>These were big goals, and also a bit scary; we knew that incremental improvements would only allow us to move so fast. So in April we started a project to build a new implementation of Relay core targeting low-end mobile devices from the start.</p>
|
||
|
||
<p>As you can guess since we&#39;re writing this, the experiment was a success. The result is a new core that retains the best parts of Relay today - colocated components &amp; data-dependencies, automatic data/view consistency, declarative data-fetching - while improving performance on mobile devices and addressing several common areas of confusion.</p>
|
||
|
||
<p>We&#39;re currently focused on shipping the first applications using the new core: ironing out bugs, refining the API changes and developer experience, and adding any missing features. We&#39;re excited to bring these changes to open source, and will do so once we&#39;ve proven them in production. We&#39;ll go into more detail in some upcoming talks - links below - but for now here&#39;s an overview:</p>
|
||
|
||
<ul>
|
||
<li><strong>Static Queries</strong>: By adding a couple of Relay-specific directives, we&#39;ve been able to retain the expressivity of current Relay queries using static syntax (concretely: you know what query an app will execute just by looking at the source text, without having to run that code). For starters this will allow Relay apps to start fetching data in parallel with JavaScript initialization. But it also unlocks other possibilities: knowing the query ahead of time means that we can generate optimized code for handling query responses, for example, or for reading query data from an offline cache.</li>
|
||
<li><strong>Expressive Mutations</strong>: We&#39;ll continue to support a higher-level mutation API for common cases, but will also provide a lower-level API that allows &quot;raw&quot; data access where necessary. If you need to order a list of cached elements, for example, there will be a way to <code>sort()</code> it.</li>
|
||
<li><strong>Route-less Relay</strong>: Routes will be gone in open source. Instead of a route with multiple query definitions, you&#39;ll just provide a single query with as many root fields as you want.</li>
|
||
<li><strong>Cache Eviction/Garbage Collection</strong>: The API and architecture is designed from the start to allow removing cached data that is no longer referenced by a mounted view.</li>
|
||
</ul>
|
||
|
||
<p>Stepping back, we recognize that any API changes will require an investment on your part. To make the transition easier, though, <em>we will continue to support the current API for the foreseeable future</em> (we&#39;re still using it too). And as much as possible we will open-source the tools that we use to migrate our own code. Ideas that we&#39;re exploring include codemods, an interoperability layer for the old/new APIs, and tutorials &amp; guides to ease migration.</p>
|
||
|
||
<p>Ultimately, we&#39;re making these changes because we believe they make Relay better all around: simpler for developers building apps and faster for the people using them.</p>
|
||
|
||
<h1>Conclusion</h1>
|
||
|
||
<p>If you made it this far, congrats and thanks for reading! We&#39;ll be sharing more information about these changes in some upcoming talks:</p>
|
||
|
||
<ul>
|
||
<li><a href="https://github.com/wincent">Greg Hurrell</a> will presenting a Relay &quot;Deep Dive&quot; at the <a href="http://www.meetup.com/Silicon-Valley-ReactJS-Meetup/events/232236845/">Silicon Valley ReactJS Meetup</a> on August 17th.</li>
|
||
<li>I (<a href="https://github.com/josephsavona">@josephsavona</a>) will be speaking about Relay at <a href="http://www.reactrally.com">React Rally</a> on August 25th.</li>
|
||
</ul>
|
||
|
||
<p>We can&#39;t wait to share the new code with you and are working as fast as we can to do so!</p>
|
||
</description>
|
||
<pubDate>2016-08-05T00:00:00-07:00</pubDate>
|
||
<link>https://facebook.github.io/react/blog/2016/08/05/relay-state-of-the-state.html</link>
|
||
<guid isPermaLink="true">https://facebook.github.io/react/blog/2016/08/05/relay-state-of-the-state.html</guid>
|
||
</item>
|
||
|
||
</channel>
|
||
</rss>
|