<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[React]]></title><description><![CDATA[A JavaScript library for building user interfaces]]></description><link>https://reactjs.org</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Mar 2018 01:33:41 GMT</lastBuildDate><item><title><![CDATA[Sneak Peek: Beyond React 16]]></title><description><![CDATA[<p><a href="https://twitter.com/dan_abramov">Dan Abramov</a> from our team just spoke at <a href="https://2018.jsconf.is/">JSConf Iceland 2018</a> with a preview of some new features we’ve been working on in React. The talk opens with a question: “With vast differences in computing power and network speed, how do we deliver the best user experience for everyone?”</p>
<p>Here’s the video courtesy of JSConf Iceland:</p>
<div>
          <div
            class="gatsby-resp-iframe-wrapper"
            style="padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden;"
          >
            <iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Freact%2Fvideos%2F1552821821462886%2F&amp;show_text=0&amp;width=560&amp;mute=0" scrolling="no" frameborder="0" allowtransparency="true" allowfullscreen="true" style="
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
          "></iframe>
          </div>
          </div>
<p>I think you’ll enjoy the talk more if you stop reading here and just watch the video. If you don’t have time to watch, a (very) brief summary follows.</p>
<h2 id="about-the-two-demos"><a href="#about-the-two-demos" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>About the Two Demos</h2>
<p>On the first demo, Dan says: “We’ve built a generic way to ensure that high-priority updates don’t get blocked by a low-priority update, called <strong>time slicing</strong>. If my device is fast enough, it feels almost like it’s synchronous; if my device is slow, the app still feels responsive. It adapts to the device thanks to the <a href="https://developers.google.com/web/updates/2015/08/using-requestidlecallback">requestIdleCallback</a> API. Notice that only the final state was displayed; the rendered screen is always consistent and we don’t see visual artifacts of slow rendering causing a janky user experience.”</p>
<p>On the second demo, Dan explains: “We’ve built a generic way for components to suspend rendering while they load async data, which we call <strong>suspense</strong>. You can pause any state update until the data is ready, and you can add async loading to any component deep in the tree without plumbing all the props and state through your app and hoisting the logic. On a fast network, updates appear very fluid and instantaneous without a jarring cascade of spinners that appear and disappear. On a slow network, you can intentionally design which loading states the user should see and how granular or coarse they should be, instead of showing spinners based on how the code is written. The app stays responsive throughout.”</p>
<p>“Importantly, this is still the React you know. This is still the declarative component paradigm that you probably like about React.”</p>
<p>We can’t wait to release these new async rendering features later this year. Follow this blog and <a href="https://twitter.com/reactjs">@reactjs on Twitter</a> for updates.</p>]]></description><link>https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-16.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-16.html</guid><pubDate>Thu, 01 Mar 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[Behind the Scenes: Improving the Repository Infrastructure]]></title><description><![CDATA[<p>As we worked on <a href="/blog/2017/09/26/react-v16.0.html">React 16</a>, we revamped the folder structure and much of the build tooling in the React repository. Among other things, we introduced projects such as <a href="https://rollupjs.org/">Rollup</a>, <a href="https://prettier.io/">Prettier</a>, and <a href="https://developers.google.com/closure/compiler/">Google Closure Compiler</a> into our workflow. People often ask us questions about how we use those tools. In this post, we would like to share some of the changes that we’ve made to our build and test infrastructure in 2017, and what motivated them.</p>
<p>While these changes helped us make React better, they don’t affect most React users directly. However, we hope that blogging about them might help other library authors solve similar problems. Our contributors might also find these notes helpful!</p>
<h2 id="formatting-code-with-prettier"><a href="#formatting-code-with-prettier" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Formatting Code with Prettier</h2>
<p>React was one of the first large repositories to <a href="https://github.com/facebook/react/pull/9101">fully embrace</a> opinionated automatic code formatting with <a href="https://prettier.io/">Prettier</a>. Our current Prettier setup consists of:</p>
<ul>
<li>A local <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/package.json#L115"><code>yarn prettier</code></a> script that <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/prettier/index.js#L71-L77">uses the Prettier Node API</a> to format files in place. We typically run it before committing changes. It is fast because it only checks the <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/shared/listChangedFiles.js#L29-L33">files changed since diverging from remote master</a>.</li>
<li>A script that <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/prettier/index.js#L79-L90">runs Prettier</a> as part of our <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/circleci/test_entry_point.sh#L10">continuous integration checks</a>. It won’t attempt to overwrite the files, but instead will fail the build if any file differs from the Prettier output for that file. This ensures that we can’t merge a pull request unless it has been fully formatted.</li>
</ul>
<p>Some team members have also set up the <a href="https://prettier.io/docs/en/editors.html">editor integrations</a>. Our experience with Prettier has been fantastic, and we recommend it to any team that writes JavaScript.</p>
<h2 id="restructuring-the-monorepo"><a href="#restructuring-the-monorepo" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Restructuring the Monorepo</h2>
<p>Ever since React was split into packages, it has been a <a href="https://danluu.com/monorepo/">monorepo</a>: a set of packages under the umbrella of a single repository. This made it easier to coordinate changes and share the tooling, but our folder structure was deeply nested and difficult to understand. It was not clear which files belonged to which package. After releasing React 16, we’ve decided to completely reorganize the repository structure. Here is how we did it.</p>
<h3 id="migrating-to-yarn-workspaces"><a href="#migrating-to-yarn-workspaces" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Migrating to Yarn Workspaces</h3>
<p>The Yarn package manager <a href="https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/">introduced a feature called Workspaces</a> a few months ago. This feature lets you tell Yarn where your monorepo’s packages are located in the source tree. Every time you run <code>yarn</code>, in addition to installing your dependencies it also sets up the symlinks that point from your project’s <code>node_modules</code> to the source folders of your packages.</p>
<p>Thanks to Workspaces, absolute imports between our own packages (such as importing <code>react</code> from <code>react-dom</code>) “just work” with any tools that support the Node resolution mechanism. The only problem we encountered was Jest not running the transforms inside the linked packages, but we <a href="https://github.com/facebook/jest/pull/4761">found a fix</a>, and it was merged into Jest.</p>
<p>To enable Yarn Workspaces, we added <code>"workspaces": ["packages/*"]</code> to our <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/package.json#L4-L6"><code>package.json</code></a>, and moved all the code into <a href="https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages">top-level <code>packages/*</code> folders</a>, each with its own <code>package.json</code> file.</p>
<p>Each package is structured in a similar way. For every public API entry point such as <code>react-dom</code> or <code>react-dom/server</code>, there is a <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/index.js">file</a> in the package root folder that re-exports the implementation from the <a href="https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/src"><code>/src/</code></a> subfolder. The decision to point entry points to the source rather than to the built versions was intentional. Typically, we re-run a subset of tests after every change during development. Having to build the project to run a test would have been prohibitively slow. When we publish packages to npm, we replace these entry points with files in the <a href="https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/npm"><code>/npm/</code></a> folder that point to the build artifacts.</p>
<p>Not all packages have to be published on npm. For example, we keep some utilities that are tiny enough and can be safely duplicated in a <a href="https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared">pseudo-package called <code>shared</code></a>. Our bundler is configured to <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L326-L329">only treat <code>dependencies</code> declared from <code>package.json</code> as externals</a> so it happily bundles the <code>shared</code> code into <code>react</code> and <code>react-dom</code> without leaving any references to <code>shared/</code> in the build artifacts. So you can use Yarn Workspaces even if you don’t plan to publish actual npm packages!</p>
<h3 id="removing-the-custom-module-system"><a href="#removing-the-custom-module-system" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Removing the Custom Module System</h3>
<p>In the past, we used a non-standard module system called “Haste” that lets you import any file from any other file by its unique <code>@providesModule</code> directive no matter where it is in the tree. It neatly avoids the problem of deep relative imports with paths like <code>../../../../</code> and is great for the product code. However, this makes it hard to understand the dependencies between packages. We also had to resort to hacks to make it work with different tools.</p>
<p>We decided to <a href="https://github.com/facebook/react/pull/11303">remove Haste</a> and use the Node resolution with relative imports instead. To avoid the problem of deep relative paths, we have <a href="https://github.com/facebook/react/pull/11304">flattened our repository structure</a> so that it goes at most one level deep inside each package:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-none"><code>|-react
|  |-npm
|  |-src
|-react-dom
|  |-npm
|  |-src
|  |  |-client
|  |  |-events
|  |  |-server
|  |  |-shared</code></pre>
      </div>
<p>This way, the relative paths can only contain one <code>./</code> or <code>../</code> followed by the filename. If one package needs to import something from another package, it can do so with an absolute import from a top-level entry point.</p>
<p>In practice, we still have <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/src/client/ReactDOMFiberComponent.js#L10-L11">some cross-package “internal” imports</a> that violate this principle, but they’re explicit, and we plan to gradually get rid of them.</p>
<h2 id="compiling-flat-bundles"><a href="#compiling-flat-bundles" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Compiling Flat Bundles</h2>
<p>Historically, React was distributed in two different formats: as a single-file build that you can add as a <code>&#x3C;script></code> tag in the browser, and as a collection of CommonJS modules that you can bundle with a tool like webpack or Browserify. </p>
<p>Before React 16, each React source file had a corresponding CommonJS module that was published as part of the npm packages. Importing <code>react</code> or <code>react-dom</code> led bundlers to the package <a href="https://unpkg.com/react@15/index.js">entry point</a> from which they would build a dependency tree with the CommonJS modules in the <a href="https://unpkg.com/react@15/lib/">internal <code>lib</code> folder</a>.</p>
<p>However, this approach had multiple disadvantages:</p>
<ul>
<li><strong>It was inconsistent.</strong> Different tools produce bundles of different sizes for identical code importing React, with the difference going as far as 30 kB (before gzip).</li>
<li><strong>It was inefficient for bundler users.</strong> The code produced by most bundlers today contains a lot of “glue code” at the module boundaries. It keeps the modules isolated from each other, but increases the parse time, the bundle size, and the build time.</li>
<li><strong>It was inefficient for Node users.</strong> When running in Node, performing <code>process.env.NODE_ENV</code> checks before development-only code incurs the overhead of actually looking up environment variables. This slowed down React server rendering. We couldn’t cache it in a variable either because it prevented dead code elimination with Uglify.</li>
<li><strong>It broke encapsulation.</strong> React internals were exposed both in the open source (as <code>react-dom/lib/*</code> imports) and internally at Facebook. It was convenient at first as a way to share utilities between projects, but with time it became a maintenance burden because renaming or changing argument types of internal functions would break unrelated projects.</li>
<li><strong>It prevented experimentation.</strong> There was no way for the React team to experiment with any advanced compilation techniques. For example, in theory, we might want to apply <a href="https://developers.google.com/closure/compiler/docs/api-tutorial3">Google Closure Compiler Advanced</a> optimizations or <a href="https://prepack.io/">Prepack</a> to some of our code, but they are designed to work on complete bundles rather than small individual modules that we used to ship to npm.</li>
</ul>
<p>Due to these and other issues, we’ve changed the strategy in React 16. We still ship CommonJS modules for Node.js and bundlers, but instead of publishing many individual files in the npm package, we publish just two CommonJS bundles per entry point.</p>
<p>For example, when you import <code>react</code> with React 16, the bundler <a href="https://unpkg.com/react@16/index.js">finds the entry point</a> that just re-exports one of the two files:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token string">'use strict'</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>NODE_ENV <span class="token operator">===</span> <span class="token string">'production'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'./cjs/react.production.min.js'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
  module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'./cjs/react.development.js'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>In every package provided by React, the <a href="https://unpkg.com/react@16/cjs/"><code>cjs</code> folder</a> (short for “CommonJS”) contains a development and a production pre-built bundle for each entry point. </p>
<p>For example, <a href="https://unpkg.com/react@16/cjs/react.development.js"><code>react.development.js</code></a> is the version intended for development. It is readable and includes comments. On the other hand, <a href="https://unpkg.com/react@16/cjs/react.production.min.js"><code>react.production.min.js</code></a> was minified and optimized before it was published to npm.</p>
<p>Note how this is essentially the same strategy that we’ve been using for the single-file browser builds (which now reside in the <a href="https://unpkg.com/react@16/umd/"><code>umd</code> directory</a>, short for <a href="https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/">Universal Module Definition</a>). Now we just apply the same strategy to the CommonJS builds as well.</p>
<h3 id="migrating-to-rollup"><a href="#migrating-to-rollup" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Migrating to Rollup</h3>
<p>Just compiling CommonJS modules into single-file bundles doesn’t solve all of the above problems. The really significant wins came from <a href="https://github.com/facebook/react/pull/9327">migrating our build system</a> from Browserify to <a href="https://rollupjs.org/">Rollup</a>.</p>
<p><a href="https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c">Rollup was designed with libraries rather than apps in mind</a>, and it is a perfect fit for React’s use case. It solves one problem well: how to combine multiple modules into a flat file with minimal junk code in between. To achieve this, instead of turning modules into functions like many other bundlers, it puts all the code in the same scope, and renames variables so that they don’t conflict. This produces code that is easier for the JavaScript engine to parse, for a human to read, and for a minifier to optimize.</p>
<p>Rollup currently doesn’t support some features that are important to application builders, such as code splitting. However, it does not aim to replace tools like webpack that do a great job at this. Rollup is a perfect fit for <em>libraries</em> like React that can be pre-built and then integrated into apps.</p>
<p>You can find our Rollup build configuration <a href="https://github.com/facebook/react/blob/8ec146c38ee4f4c84b6ecf59f52de3371224e8bd/scripts/rollup/build.js#L336-L362">here</a>, with a <a href="https://github.com/facebook/react/blob/8ec146c38ee4f4c84b6ecf59f52de3371224e8bd/scripts/rollup/build.js#L196-L273">list of plugins we currently use</a>.</p>
<h3 id="migrating-to-google-closure-compiler"><a href="#migrating-to-google-closure-compiler" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Migrating to Google Closure Compiler</h3>
<p>After migrating to flat bundles, we <a href="https://github.com/facebook/react/pull/10236">started</a> using <a href="https://github.com/google/closure-compiler-js">the JavaScript version of the Google Closure Compiler</a> in its “simple” mode. In our experience, even with the advanced optimizations disabled, it still provided a significant advantage over Uglify, as it was able to better eliminate dead code and automatically inline small functions when appropriate.</p>
<p>At first, we could only use Google Closure Compiler for the React bundles we shipped in the open source. At Facebook, we still needed the checked-in bundles to be unminified so we could symbolicate React production crashes with our error reporting tools. We ended up contributing <a href="https://github.com/google/closure-compiler/pull/2707">a flag</a> that completely disables the renaming compiler pass. This lets us apply other optimizations like function inlining, but keep the code fully readable for the Facebook-specific builds of React. To improve the output readability, we <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L249-L250">also format that custom build using Prettier</a>. Interestingly, running Prettier on production bundles while debugging the build process is a great way to find unnecessary code in the bundles!</p>
<p>Currently, all production React bundles <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L235-L248">run through Google Closure Compiler in simple mode</a>, and we may look into enabling advanced optimizations in the future.</p>
<h3 id="protecting-against-weak-dead-code-elimination"><a href="#protecting-against-weak-dead-code-elimination" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Protecting Against Weak Dead Code Elimination</h3>
<p>While we use an efficient <a href="https://en.wikipedia.org/wiki/Dead_code_elimination">dead code elimination</a> solution in React itself, we can’t make a lot of assumptions about the tools used by the React consumers.</p>
<p>Typically, when you <a href="/docs/optimizing-performance.html#use-the-production-build">configure a bundler for production</a>, you need to tell it to substitute <code>process.env.NODE_ENV</code> with the <code>"production"</code> string literal. This process is sometimes called “envification”. Consider this code:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">if</span> <span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>NODE_ENV <span class="token operator">!==</span> <span class="token string">"production"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// development-only code</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>After envification, this condition will always be <code>false</code>, and can be completely eliminated by most minifiers:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token string">"production"</span> <span class="token operator">!==</span> <span class="token string">"production"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// development-only code</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>However, if the bundler is misconfigured, you can accidentally ship development code into production. We can’t completely prevent this, but we took a few steps to mitigate the common cases when it happens.</p>
<h4 id="protecting-against-late-envification"><a href="#protecting-against-late-envification" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Protecting Against Late Envification</h4>
<p>As mentioned above, our entry points now look like this:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token string">'use strict'</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>NODE_ENV <span class="token operator">===</span> <span class="token string">'production'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'./cjs/react.production.min.js'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
  module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'./cjs/react.development.js'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>However, some bundlers process <code>require</code>s before envification. In this case, even if the <code>else</code> block never executes, the <code>cjs/react.development.js</code> file still gets bundled.</p>
<p>To prevent this, we also <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/rollup/wrappers.js#L65-L69">wrap the whole content</a> of the development bundle into another <code>process.env.NODE_ENV</code> check inside the <code>cjs/react.development.js</code> bundle itself:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token string">'use strict'</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>NODE_ENV <span class="token operator">!==</span> <span class="token string">"production"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// bundle code</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>This way, even if the application bundle includes both the development and the production versions of the file, the development version will be empty after envification.</p>
<p>The additional <a href="https://en.wikipedia.org/wiki/Immediately-invoked_function_expression">IIFE</a> wrapper is necessary because some declarations (e.g. functions) can’t be placed inside an <code>if</code> statement in JavaScript.</p>
<h4 id="detecting-misconfigured-dead-code-elimination"><a href="#detecting-misconfigured-dead-code-elimination" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Detecting Misconfigured Dead Code Elimination</h4>
<p>Even though <a href="https://twitter.com/iamakulov/status/941336777188696066">the situation is changing</a>, many popular bundlers don’t yet force the users to specify the development or production mode. In this case <code>process.env.NODE_ENV</code> is typically provided by a runtime polyfill, but the dead code elimination doesn’t work.</p>
<p>We can’t completely prevent React users from misconfiguring their bundlers, but we introduced a few additional checks for this in <a href="https://github.com/facebook/react-devtools">React DevTools</a>.</p>
<p>If the development bundle executes, <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/packages/react-dom/src/client/ReactDOM.js#L1333-L1335">React DOM reports this to React DevTools</a>:</p>
<br>

  <a class="gatsby-resp-image-link" href="/static/devtools-dev-e434ce2f7e64f63e597edf03f4465694-1e9b4.png" style="display: block" target="_blank" rel="noopener">
  
  <span class="gatsby-resp-image-wrapper" style="position: relative; display: block; ; max-width: 600px; margin-left: auto; margin-right: auto;">
    <span class="gatsby-resp-image-background-image" style="padding-bottom: 33.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAIAAACHqfpvAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA7ElEQVQY05WQDWuDMBCG8///VQvCSIzxI9n8qEtiurmaqFFHwc3pUsZKYYyxh+N477gX7g68/x+tdSs593bgz9GPHyzLcn6dzoMFNGEQwiShaZr6GDNGaXIBQkQIYYwFJKRJjHEgxUHXqTOv6+rytm0gzwtVVZzzsiyLIldKHY9PnD9KIZ0uioMQQlXKDWRZJqvKNZ3W2lzMb78wz/OtuJZX3EXA8zy3XoD9OKToLnSBYRSFaUTu4/CBYLLf77DvI4QR8t0tUqjtG9Ca1lo7jmNnBtMMTW2bF3uqe6dPz33X2S+Mafu+n6bp9nOfEzOCGSCp8RoAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;">
      <img class="gatsby-resp-image-image" style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;" alt="React DevTools on a website with development version of React" title="" src="/static/devtools-dev-e434ce2f7e64f63e597edf03f4465694-1e9b4.png" srcset="/static/devtools-dev-e434ce2f7e64f63e597edf03f4465694-1cd08.png 210w,
/static/devtools-dev-e434ce2f7e64f63e597edf03f4465694-9b07a.png 420w,
/static/devtools-dev-e434ce2f7e64f63e597edf03f4465694-1e9b4.png 600w" sizes="(max-width: 600px) 100vw, 600px">
    </span>
  </span>
  
  </a>
    
<p>There is also one more bad scenario. Sometimes, <code>process.env.NODE_ENV</code> is set to <code>"production"</code> at runtime rather than at the build time. This is how it should work in Node.js, but it is bad for the client-side builds because the unnecessary development code is bundled even though it never executes. This is harder to detect but we found a heuristic that works well in most cases and doesn’t seem to produce false positives.</p>
<p>We can write a function that contains a <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/packages/react-dom/npm/index.js#L11-L20">development-only branch</a> with an arbitrary string literal. Then, if <code>process.env.NODE_ENV</code> is set to <code>"production"</code>, we can <a href="https://github.com/facebook/react-devtools/blob/b370497ba6e873c63479408f11d784095523a630/backend/installGlobalHook.js#L143">call <code>toString()</code> on that function</a> and verify that the string literal in the development-only has been stripped out. If it is still there, the dead code elimination didn’t work, and we need to warn the developer. Since developers might not notice the React DevTools warnings on a production website, we also <a href="https://github.com/facebook/react-devtools/blob/b370497ba6e873c63479408f11d784095523a630/backend/installGlobalHook.js#L153-L160">throw an error inside <code>setTimeout</code></a> from React DevTools in the hope that it will be picked up by the error analytics.</p>
<p>We recognize this approach is somewhat fragile. The <code>toString()</code> method is not reliable and may change its behavior in future browser versions. This is why we put that logic into React DevTools itself rather than into React. This allows us to remove it later if it becomes problematic. We also warn only if we <em>found</em> the special string literal rather than if we <em>didn’t</em> find it. This way, if the <code>toString()</code> output becomes opaque, or is overridden, the warning just won’t fire.</p>
<h2 id="catching-mistakes-early"><a href="#catching-mistakes-early" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Catching Mistakes Early</h2>
<p>We want to catch bugs as early as possible. However, even with our extensive test coverage, occasionally we make a blunder. We made several changes to our build and test infrastructure this year to make it harder to mess up.</p>
<h3 id="migrating-to-es-modules"><a href="#migrating-to-es-modules" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Migrating to ES Modules</h3>
<p>With the CommonJS <code>require()</code> and <code>module.exports</code>, it is easy to import a function that doesn’t really exist, and not realize that until you call it. However, tools like Rollup that natively support <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import"><code>import</code></a> and <a href="https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export"><code>export</code></a> syntax fail the build if you mistype a named import. After releasing React 16, <a href="https://github.com/facebook/react/pull/11389">we have converted the entire React source code</a> to the ES Modules syntax.</p>
<p>Not only did this provide some extra protection, but it also helped improve the build size. Many React modules only export utility functions, but CommonJS forced us to wrap them into an object. By turning those utility functions into named exports and eliminating the objects that contained them, we let Rollup place them into the top-level scope, and thus let the minifier mangle their names in the production builds.</p>
<p>For now, have decided to only convert the source code to ES Modules, but not the tests. We use powerful utilities like <code>jest.resetModules()</code> and want to retain tighter control over when the modules get initialized in tests. In order to consume ES Modules from our tests, we enabled the <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/jest/preprocessor.js#L28-L29">Babel CommonJS transform</a>, but only for the test environment.</p>
<h3 id="running-tests-in-production-mode"><a href="#running-tests-in-production-mode" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Running Tests in Production Mode</h3>
<p>Historically, we’ve been running all tests in a development environment. This let us assert on the warning messages produced by React, and seemed to make general sense. However, even though we try to keep the differences between the development and production code paths minimal, occasionally we would make a mistake in production-only code branches that weren’t covered by tests, and cause an issue at Facebook.</p>
<p>To solve this problem, we have added a new <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/package.json#L110"><code>yarn test-prod</code></a> command that runs on CI for every pull request, and <a href="https://github.com/facebook/react/pull/11616">executes all React test cases in the production mode</a>. We wrapped any assertions about warning messages into development-only conditional blocks in all tests so that they can still check the rest of the expected behavior in both environments. Since we have a custom Babel transform that replaces production error messages with the <a href="/blog/2016/07/11/introducing-reacts-error-code-system.html">error codes</a>, we also added a <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/jest/setupTests.js#L91-L126">reverse transformation</a> as part of the production test run.</p>
<h3 id="using-public-api-in-tests"><a href="#using-public-api-in-tests" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Using Public API in Tests</h3>
<p>When we were <a href="https://code.facebook.com/posts/1716776591680069/react-16-a-look-inside-an-api-compatible-rewrite-of-our-frontend-ui-library/">rewriting the React reconciler</a>, we recognized the importance of writing tests against the public API instead of internal modules. If the test is written against the public API, it is clear what is being tested from the user’s perspective, and you can run it even if you rewrite the implementation from scratch.</p>
<p>We reached out to the wonderful React community <a href="https://github.com/facebook/react/issues/11299">asking for help</a> converting the remaining tests to use the public API. Almost all of the tests are converted now! The process wasn’t easy. Sometimes a unit test just calls an internal method, and it’s hard to figure out what the observable behavior from user’s point of view was supposed to be tested. We found a few strategies that helped with this. The first thing we would try is to find the git history for when the test was added, and find clues in the issue and pull request description. Often they would contain reproducing cases that ended up being more valuable than the original unit tests! A good way to verify the guess is to try commenting out individual lines in the source code being tested. If the test fails, we know for sure that it stresses the given code path.</p>
<p>We would like to give our deepest thanks to <a href="https://github.com/facebook/react/issues?q=is%3Apr+11299+is%3Aclosed">everyone who contributed to this effort</a>.</p>
<h3 id="running-tests-on-compiled-bundles"><a href="#running-tests-on-compiled-bundles" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Running Tests on Compiled Bundles</h3>
<p>There is also one more benefit to writing tests against the public API: now we can <a href="https://github.com/facebook/react/pull/11633">run them against the compiled bundles</a>.</p>
<p>This helps us ensure that tools like Babel, Rollup, and Google Closure Compiler don’t introduce any regressions. This also opens the door for future more aggressive optimizations, as we can be confident that React still behaves exactly as expected after them.</p>
<p>To implement this, we have created a <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/jest/config.build.js">second Jest config</a>. It overrides our default config but points <code>react</code>, <code>react-dom</code>, and other entry points to the <code>/build/packages/</code> folder. This folder doesn’t contain any React source code, and reflects what gets published to npm. It is populated after you run <code>yarn build</code>.</p>
<p>This lets us run the same exact tests that we normally run against the source, but execute them using both development and production pre-built React bundles produced with Rollup and Google Closure Compiler.</p>
<p>Unlike the normal test run, the bundle test run depends on the build products so it is not great for quick iteration. However, it still runs on the CI server so if something breaks, the test will display as failed, and we will know it’s not safe to merge into master.</p>
<p>There are still some test files that we intentionally don’t run against the bundles. Sometimes we want to mock an internal module or override a feature flag that isn’t exposed to the public yet. For those cases, we blacklist a test file by renaming it from <code>MyModule-test.js</code> to <code>MyModule-test.internal.js</code>.</p>
<p>Currently, over 93% out of 2,650 React tests run against the compiled bundles.</p>
<h3 id="linting-compiled-bundles"><a href="#linting-compiled-bundles" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Linting Compiled Bundles</h3>
<p>In addition to linting our source code, we run a much more limited set of lint rules (really, <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/validate/eslintrc.cjs.js#L26-L27">just two of them</a>) on the compiled bundles. This gives us an extra layer of protection against regressions in the underlying tools and <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/validate/eslintrc.cjs.js#L22">ensures</a> that the bundles don’t use any language features that aren’t supported by older browsers.</p>
<h3 id="simulating-package-publishing"><a href="#simulating-package-publishing" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Simulating Package Publishing</h3>
<p>Even running the tests on the built packages is not enough to avoid shipping a broken update. For example, we use the <code>files</code> field in our <code>package.json</code> files to specify a whitelist of folders and files that should be published on npm. However, it is easy to add a new entry point to a package but forget to add it to the whitelist. Even the bundle tests would pass, but after publishing the new entry point would be missing.</p>
<p>To avoid situations like this, we are now simulating the npm publish by <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/packaging.js#L129-L134">running <code>npm pack</code> and then immediately unpacking the archive</a> after the build. Just like <code>npm publish</code>, this command filters out anything that isn’t in the <code>files</code> whitelist. With this approach, if we were to forget adding an entry point to the list, it would be missing in the build folder, and the bundle tests relying on it would fail.</p>
<h3 id="creating-manual-test-fixtures"><a href="#creating-manual-test-fixtures" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Creating Manual Test Fixtures</h3>
<p>Our unit tests run only in the Node environment, but not in the browsers. This was an intentional decision because browser-based testing tools were flaky in our experience, and didn’t catch many issues anyway.</p>
<p>We could get away with this because the code that touches the DOM is consolidated in a few files, and doesn’t change that often. Every week, we update the Facebook.com codebase to the latest React commit on master. At Facebook, we use a set of internal <a href="http://www.seleniumhq.org/projects/webdriver/">WebDriver</a> tests for critical product workflows, and these catch some regressions. React updates are first delivered to employees, so severe bugs get reported immediately before they reach two billion users.</p>
<p>Still, it was hard to review DOM-related changes, and occasionally we would make mistakes. In particular, it was hard to remember all the edge cases that the code had to handle, why they were added, and when it was safe to remove them. We considered adding some automatic tests that run in the browser but we didn’t want to slow down the development cycle and deal with a fragile CI. Additionally, automatic tests don’t always catch DOM issues. For example, an input value displayed by the browser may not match what it reports as a DOM property.</p>
<p>We’ve chatted about this with <a href="https://github.com/aweary">Brandon Dail</a>, <a href="https://github.com/jquense">Jason Quense</a>, and <a href="https://github.com/nhunzaker">Nathan Hunzaker</a>. They were sending substantial patches to React DOM but were frustrated that we failed to review them timely. We decided to give them commit access, but asked them to <a href="https://github.com/facebook/react/pull/8589">create a set of manual tests</a> for DOM-related areas like input management. The initial set of manual fixtures <a href="https://github.com/facebook/react/commits/master/fixtures/dom">kept growing</a> over the year.</p>
<p>These fixtures are implemented as a React app located in <a href="https://github.com/facebook/react/tree/d906de7f602df810c38aa622c83023228b047db6/fixtures/dom"><code>fixtures/dom</code></a>. Adding a fixture involves writing a React component with a description of the expected behavior, and links to the appropriate issues and browser quirks, like <a href="https://github.com/facebook/react/pull/11760">in this example</a>:</p>
<img src="https://user-images.githubusercontent.com/590904/33555298-dd52fb4e-d8cd-11e7-80e9-8369538eb633.png" style="max-width:100%" alt="DOM fixture example">
<p>The fixture app lets you choose a version of React (local or one of the published versions) which is handy for comparing the behavior before and after the changes. When we change the behavior related to how we interact with the DOM, we can verify that it didn’t regress by going through the related fixtures in different browsers.</p>
<p>In some cases, a change proved to be so complex that it necessitated a standalone purpose-built fixture to verify it. For example, the <a href="/blog/2017/09/08/dom-attributes-in-react-16.html">DOM attribute handling in React 16</a> was very hard to pull off with confidence at first. We kept discovering different edge cases, and almost gave up on doing it in time for the React 16 release. However, then we’ve built an <a href="https://github.com/facebook/react/tree/d906de7f602df810c38aa622c83023228b047db6/fixtures/attribute-behavior">“attribute table” fixture</a> that renders all supported attributes and their misspellings with previous and next version of React, and displays the differences. It took a few iterations (the key insight was to group attributes with similar behavior together) but it ultimately allowed us to fix all major issues in just a few days.</p>
<br>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">We went through the table to vet the new behavior for every case (and discovered some old bugs too) <a href="https://t.co/cmF2qnK9Q9">pic.twitter.com/cmF2qnK9Q9</a></p>&mdash; Dan Abramov (@dan_abramov) <a href="https://twitter.com/dan_abramov/status/906244378066345984?ref_src=twsrc%5Etfw">September 8, 2017</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>Going through the fixtures is still a lot of work, and we are considering automating some of it. Still, the fixture app is invaluable even as documentation for the existing behavior and all the edge cases and browser bugs that React currently handles. Having it gives us confidence in making significant changes to the logic without breaking important use cases. Another improvement we’re considering is to have a GitHub bot build and deploy the fixtures automatically for every pull request that touches the relevant files so anyone can help with browser testing.</p>
<h3 id="preventing-infinite-loops"><a href="#preventing-infinite-loops" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Preventing Infinite Loops</h3>
<p>The React 16 codebase contains many <code>while</code> loops. They let us avoid the dreaded deep stack traces that occurred with earlier versions of React, but can make development of React really difficult. Every time there is a mistake in an exit condition our tests would just hang, and it took a while to figure out which of the loops is causing the issue.</p>
<p>Inspired by the <a href="https://repl.it/site/blog/infinite-loops">strategy adopted by Repl.it</a>, we have added a <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/babel/transform-prevent-infinite-loops.js">Babel plugin that prevents infinite loops</a> in the test environment. If some loop continues for more than the maximum allowed number of iterations, we throw an error and immediately fail it so that Jest can display where exactly this happened.</p>
<p>This approach has a pitfall. If an error thrown from the Babel plugin gets caught and ignored up the call stack, the test will pass even though it has an infinite loop. This is really, really bad. To solve this problem, we <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/babel/transform-prevent-infinite-loops.js#L26-L30">set a global field</a> before throwing the error. Then, after every test run, we <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/jest/setupTests.js#L42-L56">rethrow that error if the global field has been set</a>. This way any infinite loop will cause a test failure, no matter whether the error from the Babel plugin was caught or not.</p>
<h2 id="customizing-the-build"><a href="#customizing-the-build" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Customizing the Build</h2>
<p>There were a few things that we had to fine-tune after introducing our new build process. It took us a while to figure them out, but we’re moderately happy with the solutions that we arrived at.</p>
<h3 id="dead-code-elimination"><a href="#dead-code-elimination" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Dead Code Elimination</h3>
<p>The combination of Rollup and Google Closure Compiler already gets us pretty far in terms of stripping development-only code in production bundles. We <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L223-L226">replace</a> the <code>__DEV__</code> literal with a boolean constant during the build, and both Rollup together and Google Closure Compiler can strip out the <code>if (false) {}</code> code branches and even some more sophisticated patterns. However, there is one particularly nasty case:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">import</span> warning <span class="token keyword">from</span> <span class="token string">'fbjs/lib/warning'</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span>__DEV__<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">warning</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token string">'Blimey!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>This pattern is very common in the React source code. However <code>fbjs/lib/warning</code> is an external import that isn’t being bundled by Rollup for the CommonJS bundle. Therefore, even if <code>warning()</code> call ends up being removed, Rollup doesn’t know whether it’s safe to remove to the import itself. What if the module performs a side effect during initialization? Then removing it would not be safe.</p>
<p>To solve this problem, we use the <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L338-L340"><code>treeshake.pureExternalModules</code> Rollup option</a> which takes an array of modules that we can guarantee don’t have side effects. This lets Rollup know that an import to <code>fbjs/lib/warning</code> is safe to completely strip out if its value is not being used. However, if it <em>is</em> being used (e.g. if we decide to add warnings in production), the import will be preserved. That’s why this approach is safer than replacing modules with empty shims.</p>
<p>When we optimize something, we need to ensure it doesn’t regress in the future. What if somebody introduces a new development-only import of an external module, and not realize they also need to add it to <code>pureExternalModules</code>? Rollup prints a warning in such cases but we’ve <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L395-L412">decided to fail the build completely</a> instead. This forces the person adding a new external development-only import to <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/modules.js#L10-L22">explicitly specify whether it has side effects or not</a> every time.</p>
<h3 id="forking-modules"><a href="#forking-modules" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Forking Modules</h3>
<p>In some cases, different bundles need to contain slightly different code. For example, React Native bundles have a different error handling mechanism that shows a redbox instead of printing a message to the console. However, it can be very inconvenient to thread these differences all the way through the calling modules.</p>
<p>Problems like this are often solved with runtime configuration. However, sometimes it is impossible: for example, the React DOM bundles shouldn’t even attempt to import the React Native redbox helpers. It is also unfortunate to bundle the code that never gets used in a particular environment.</p>
<p>Another solution is to use dynamic dependency injection. However, it often produces code that is hard to understand, and may cause cyclical dependencies. It also defies some optimization opportunities.</p>
<p>From the code point of view, ideally we just want to “redirect” a module to its different “forks” for specific bundles. The “forks” have the exact same API as the original modules, but do something different. We found this mental model very intuitive, and <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/forks.js">created a fork configuration file</a> that specifies how the original modules map to their forks, and the conditions under which this should happen.</p>
<p>For example, this fork config entry specifies different <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared/ReactFeatureFlags.js">feature flags</a> for different bundles:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token string">'shared/ReactFeatureFlags'</span><span class="token punctuation">:</span> <span class="token punctuation">(</span>bundleType<span class="token punctuation">,</span> entry<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
  <span class="token keyword">switch</span> <span class="token punctuation">(</span>entry<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">case</span> <span class="token string">'react-native-renderer'</span><span class="token punctuation">:</span>
      <span class="token keyword">return</span> <span class="token string">'shared/forks/ReactFeatureFlags.native.js'</span><span class="token punctuation">;</span>
    <span class="token keyword">case</span> <span class="token string">'react-cs-renderer'</span><span class="token punctuation">:</span>
      <span class="token keyword">return</span> <span class="token string">'shared/forks/ReactFeatureFlags.native-cs.js'</span><span class="token punctuation">;</span>
    <span class="token keyword">default</span><span class="token punctuation">:</span>
      <span class="token keyword">switch</span> <span class="token punctuation">(</span>bundleType<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">case</span> FB_DEV<span class="token punctuation">:</span>
        <span class="token keyword">case</span> FB_PROD<span class="token punctuation">:</span>
          <span class="token keyword">return</span> <span class="token string">'shared/forks/ReactFeatureFlags.www.js'</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
</code></pre>
      </div>
<p>During the build, <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/plugins/use-forks-plugin.js#L40">our custom Rollup plugin</a> replaces modules with their forks if the conditions have matched. Since both the original modules and the forks are written as ES Modules, Rollup and Google Closure Compiler can inline constants like numbers or booleans, and thus efficiently eliminate dead code for disabled feature flags. In tests, when necessary, we <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-cs-renderer/src/__tests__/ReactNativeCS-test.internal.js#L15-L17">use <code>jest.mock()</code></a> to point the module to the appropriate forked version.</p>
<p>As a bonus, we might want to verify that the export types of the original modules match the export types of the forks exactly. We can use a <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared/forks/ReactFeatureFlags.native.js#L32-L36">slightly odd but totally working Flow trick</a> to accomplish this:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">import</span> <span class="token keyword">typeof</span> <span class="token operator">*</span> <span class="token keyword">as</span> FeatureFlagsType <span class="token keyword">from</span> <span class="token string">'shared/ReactFeatureFlags'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token keyword">typeof</span> <span class="token operator">*</span> <span class="token keyword">as</span> FeatureFlagsShimType <span class="token keyword">from</span> <span class="token string">'./ReactFeatureFlags.native'</span><span class="token punctuation">;</span>
type Check<span class="token operator">&lt;</span>_X<span class="token punctuation">,</span> Y<span class="token punctuation">:</span> _X<span class="token punctuation">,</span> X<span class="token punctuation">:</span> Y <span class="token operator">=</span> _X<span class="token operator">></span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
<span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">:</span> Check<span class="token operator">&lt;</span>FeatureFlagsShimType<span class="token punctuation">,</span> FeatureFlagsType<span class="token operator">></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
      </div>
<p>This works by essentially forcing Flow to verify that two types are assignable to each other (and thus are equivalent). Now if we modify the exports of either the original module or the fork without changing the other file, the type check will fail. This might be a little goofy but we found this helpful in practice.</p>
<p>To conclude this section, it is important to note that you can’t specify your own module forks if you consume React from npm. This is intentional because none of these files are public API, and they are not covered by the <a href="https://semver.org/">semver</a> guarantees. However, you are always welcome to build React from master or even fork it if you don’t mind the instability and the risk of divergence. We hope that this writeup was still helpful in documenting one possible approach to targeting different environments from a single JavaScript library.</p>
<h3 id="tracking-bundle-size"><a href="#tracking-bundle-size" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Tracking Bundle Size</h3>
<p>As a final build step, we now <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/rollup/build.js#L264-L272">record build sizes for all bundles</a> and write them to a file that <a href="https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/rollup/results.json">looks like this</a>. When you run <code>yarn build</code>, it prints a table with the results:</p>
<br>
<img src="https://user-images.githubusercontent.com/1519870/28427900-80487dbc-6d6f-11e7-828d-1b594bd1ddb5.png" style="max-width:100%" alt="Build results after running GCC">
<p><em>(It doesn’t always look as good as this. This was the commit that migrated React from Uglify to Google Closure Compiler.)</em></p>
<p>Keeping the file sizes committed for everyone to see was helpful for tracking size changes and motivating people to find optimization opportunities.</p>
<p>We haven’t been entirely happy with this strategy because the JSON file often causes merge conflicts on larger branches. Updating it is also not currently enforced so it gets out of date. In the future, we’re considering integrating a bot that would comment on pull requests with the size changes.</p>
<h2 id="simplifying-the-release-process"><a href="#simplifying-the-release-process" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Simplifying the Release Process</h2>
<p>We like to release updates to the open source community often. Unfortunately, the old process of creating a release was slow and would typically take an entire day. After some changes to this process, we’re now able to do a full release in less than an hour. Here’s what we changed.</p>
<h3 id="branching-strategy"><a href="#branching-strategy" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Branching Strategy</h3>
<p>Most of the time spent in the old release process was due to our branching strategy. The <code>master</code> branch was assumed to be unstable and would often contain breaking changes. Releases were done from a <code>stable</code> branch, and changes were manually cherry-picked into this branch prior to a release. We had <a href="https://github.com/facebook/react/pull/7330">tooling to help automate</a> some of this process, but it was still <a href="https://github.com/facebook/react/blob/b5a2a1349d6e804d534f673612357c0be7e1d701/scripts/release-manager/Readme.md">pretty complicated to use</a>.</p>
<p>As of version 16, we now release from the <code>master</code> branch. Experimental features and breaking changes are allowed, but must be hidden behind <a href="https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared/ReactFeatureFlags.js">feature flags</a> so they can be removed during the build process. The new flat bundles and dead code elimination make it possible for us to do this without fear of leaking unwanted code into open source builds.</p>
<h3 id="automated-scripts"><a href="#automated-scripts" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Automated Scripts</h3>
<p>After changing to a stable <code>master</code>, we created a new <a href="https://github.com/facebook/react/issues/10620">release process checklist</a>. Although much simpler than the previous process, this still involved dozens of steps and forgetting one could result in a broken release.</p>
<p>To address this, we created a new <a href="https://github.com/facebook/react/pull/11223">automated release process</a> that is <a href="https://github.com/facebook/react/tree/master/scripts/release#react-release-script">much easier to use</a> and has several built-in checks to ensure that we release a working build. The new process is split into two steps: <em>build</em> and <em>publish</em>. Here’s what it looks like the first time you run it:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/release-script-build-overview-adca79c3a0e003b317fe62e68ce9d4a0-a0a5f.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block; ; max-width: 822px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 45.37712895377128%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAAAsSAAALEgHS3X78AAAA4ElEQVQoz52S227DIAyGU3JogRAICQdpKR2EoVzk/Z9vf9ObXkxbtE/IsrCwf9tU8zxbY8dx1FpLKWfn4ZvZjErVdV39zk0banz/8YDD/XJV+kJIdZL6RknTdkK2/YDTUF6dh3NurRPDAP3qoOu6s49DeHDGqv9hjMk5L8sdNZGolLLv+7Zta0oxxs8YU0pSKmvtD4/zmr3zPeD8esAYo5T+PWrQtt1rT+j5ckAIgUUIVgiBEKxzrmma1/3bqijNeYXgEAJ0QohS2LFCRtSfpincEQnlqzx7WROmqw/wKb4BarITYyj4QEYAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Release Script overview"
        title=""
        src="/static/release-script-build-overview-adca79c3a0e003b317fe62e68ce9d4a0-a0a5f.png"
        srcset="/static/release-script-build-overview-adca79c3a0e003b317fe62e68ce9d4a0-d0a04.png 210w,
/static/release-script-build-overview-adca79c3a0e003b317fe62e68ce9d4a0-c8d6c.png 420w,
/static/release-script-build-overview-adca79c3a0e003b317fe62e68ce9d4a0-a0a5f.png 822w"
        sizes="(max-width: 822px) 100vw, 822px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>The <em>build</em> step does most of the work- verifying permissions, running tests, and checking CI status. Once it finishes, it prints a reminder to update the CHANGELOG and to verify the bundle using the <a href="#creating-manual-test-fixtures">manual fixtures</a> described above.</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-d15b8.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block; ; max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 95.52407932011332%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAATCAIAAAAf7rriAAAACXBIWXMAAAsSAAALEgHS3X78AAABlUlEQVQ4y5VTa2+sIBRc9yWKgjwVFMXV5qbJ7f//ex0xt19u624nhiA5E+bMGU7KKN/7GM00mbbr2raVUlJK67ouyzLPc5KT+/1++hbam8eyrOsaQgDh9CsII/phGELo+15pfT6ff0FWnR7HEXTOOaUVYwxqq6q6Xq+vkud51loLIfZWQX5Jwia7H5xz1racN2AWRYH7wadVBcOOyLWo4bC11rlGSl4mgLmvt9vtiFzokkiSizzLMvxmCWlz/tr/CPiEa7sEmyQYY9E/zpumYYwfNY88oEOealnC7hlJeGJbnoA6rCWlO2c/wbSeyIZOhMR5h2l57ykt85/C+D/QGMarE1JO6OVyyf5htxAr9H+jApGOcca6LMuw7SMkqARjjJRWyEGpKMQg5ESIIoXGR6u+KM0JRbvVKEVIX0rlF2Bv16kQxPIw62qVItYWUhLGCDxHF0dktOp9H6N/e3N/P6b39xXi8Uhh3pNsAnj6xgalg22Xzv2x7cOYeevnFSDS46hi1NO0+T3AF8mM4dvDwNwoPbj/E0RsJqoTdg3PAAAAAElFTkSuQmCC'); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Release Script build confirmation screen"
        title=""
        src="/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-acf85.png"
        srcset="/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-c1418.png 210w,
/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-5d5d8.png 420w,
/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-acf85.png 840w,
/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-de0cd.png 1260w,
/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-bd6c2.png 1680w,
/static/release-script-build-confirmation-17f44f353d82a22f6a18707956ad065f-d15b8.png 1765w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>All that’s left is to tag and publish the release to NPM using the <em>publish</em> script.</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/release-script-publish-confirmation-a3846d4b3e50d29415846b58612310f2-bd35c.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block; ; max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 125.12733446519523%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAZCAIAAAC+dZmEAAAACXBIWXMAAAsSAAALEgHS3X78AAACY0lEQVQ4y5WUaY+bMBCG06RJANtAgMQGmyOQa4+q+6X9/z+tj6GHEu1q6SuExsdc78x4cTCHY98fj33bNsCB2v/SNM2yjH8OCg+lZBAEaeKxWi05WshMcr2qKmOMNuagtVJqtVot5mArtrvdLsvzldgvVBXKBE+LmRC1jCrBJxsZFMHivzDlRlo4JOx0tyOlOI7zLGefVMdlIqWsbEWM6/X6nzL3uBSGIQdRFG2327kJA3T2+z0msI2MfynVyIIPR2vjN4sCu8vl8lEZbok8igTOkbHCvUkAuyybZExzgaMvD8rYFkJwwiUyjLzgFRJf5CJWik01GqXOd56xJ4RPdbPZhGHAchTCyc9fh8EIhDvCSHKiN0nSZPRGIJDsd+L4E8JOpxO9NZw8Xl5eaNXb09NjeB+BeyQ2OSQEDIVhJlWt4pZPxg3/JD2xI2Sl4k4qF0aHP6XKsuv1ej6fn56f69oNw6lp28vl0g/dzx/1+ZxoHX7oGbats34wSqbi4Gp9uRRNI/M8oPy0gNaRMVFRBEJIQqOjpJK/leGWXSidOpHbMD+3w+CpNOb19Vvvp/rIchiGrutIhOVdYd4NuyxLP/6uGAbT92XdDNo4Uz4naTfRNlLF324298Wjnngg5uPRXa+dcwdr8763TVOTy5xS5WoECftAqtJaOzvnshwz7JF5xm6321zC6FxtNDwz+23baq2xhQlog8JpvAEBfl2vH0edlm67DgU0v7+94ZyYaXQqX46ASescnVdZi+k7ZZ5O5hknJOzqGvLomblhM3QQNj5j+fSSwBkvmn+d03R6EhDf7Zxfl+pFob7eDqUAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Release Script publish confirmation screen"
        title=""
        src="/static/release-script-publish-confirmation-a3846d4b3e50d29415846b58612310f2-acf85.png"
        srcset="/static/release-script-publish-confirmation-a3846d4b3e50d29415846b58612310f2-c1418.png 210w,
/static/release-script-publish-confirmation-a3846d4b3e50d29415846b58612310f2-5d5d8.png 420w,
/static/release-script-publish-confirmation-a3846d4b3e50d29415846b58612310f2-acf85.png 840w,
/static/release-script-publish-confirmation-a3846d4b3e50d29415846b58612310f2-bd35c.png 1178w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>(You may have noticed a <code>--dry</code> flag in the screenshots above. This flag allows us to run a release, end-to-end, without actually publishing to NPM. This is useful when working on the release script itself.)</p>
<h2 id="in-conclusion"><a href="#in-conclusion" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>In Conclusion</h2>
<p>Did this post inspire you to try some of these ideas in your own projects? We certainly hope so! If you have other ideas about how React build, test, or contribution workflow could be improved, please let us know on <a href="https://github.com/facebook/react/issues">our issue tracker</a>.</p>
<p>You can find the related issues by the <a href="https://github.com/facebook/react/labels/Component%3A%20Build%20Infrastructure">build infrastructure label</a>. These are often great first contribution opportunities!</p>
<h2 id="acknowledgements"><a href="#acknowledgements" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Acknowledgements</h2>
<p>We would like to thank:</p>
<ul>
<li><a href="https://github.com/Rich-Harris">Rich Harris</a> and <a href="https://github.com/lukastaegert">Lukas Taegert</a> for maintaining Rollup and helping us integrate it.</li>
<li><a href="https://github.com/dimvar">Dimitris Vardoulakis</a>, <a href="https://github.com/ChadKillingsworth">Chad Killingsworth</a>, and <a href="https://github.com/MatrixFrog">Tyler Breisacher</a> for their work on Google Closure Compiler and timely advice.</li>
<li><a href="https://github.com/watadarkstar">Adrian Carolli</a>, <a href="https://github.com/rivenhk">Adams Au</a>, <a href="https://github.com/accordeiro">Alex Cordeiro</a>, <a href="https://github.com/HeroProtagonist">Jordan Tepper</a>, <a href="https://github.com/sjy">Johnson Shi</a>, <a href="https://github.com/misoguy">Soo Jae Hwang</a>, <a href="https://github.com/xjlim">Joe Lim</a>, <a href="https://github.com/yu-tian113">Yu Tian</a>, and others for helping prototype and implement some of these and other improvements.</li>
<li><a href="https://github.com/anushreesubramani">Anushree Subramani</a>, <a href="https://github.com/abiduzz420">Abid Uzair</a>, <a href="https://github.com/skiritsis">Sotiris Kiritsis</a>, <a href="https://github.com/timjacobi">Tim Jacobi</a>, <a href="https://github.com/aarboleda1">Anton Arboleda</a>, <a href="https://github.com/jeremenichelli">Jeremias Menichelli</a>, <a href="https://github.com/audyodi">Audy Tanudjaja</a>, <a href="https://github.com/gordyd">Gordon Dent</a>, <a href="https://github.com/enapupe">Iacami Gevaerd
</a>, <a href="https://github.com/sadpandabear">Lucas Lentz</a>, <a href="https://github.com/silvestrijonathan">Jonathan Silvestri</a>, <a href="https://github.com/mjw56">Mike Wilcox</a>, <a href="https://github.com/smaniotto">Bernardo Smaniotto</a>, <a href="https://github.com/douglasgimli">Douglas Gimli</a>, <a href="https://github.com/ethan-arrowood">Ethan Arrowood</a>, and others for their help porting the React test suite to use the public API.</li>
</ul>]]></description><link>https://reactjs.org/blog/2017/12/15/improving-the-repository-infrastructure.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/12/15/improving-the-repository-infrastructure.html</guid><pubDate>Fri, 15 Dec 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[Introducing the React RFC Process]]></title><description><![CDATA[<p>We’re adopting an RFC (“request for comments”) process for contributing ideas to React. </p>
<p>Inspired by <a href="https://github.com/yarnpkg/rfcs">Yarn</a>, <a href="https://github.com/emberjs/rfcs">Ember</a>, and <a href="https://github.com/rust-lang/rfcs">Rust</a>, the goal is to allow React core team members and community members to collaborate on the design of new features. It’s also intended to provide a clear path for ideas to enter the project:</p>
<ul>
<li>Create an RFC document detailing your proposal.</li>
<li>Submit a PR to the <a href="https://github.com/reactjs/rfcs">RFC repository</a>.</li>
<li>Incorporate feedback into the proposal.</li>
<li>After discussion, the core team may or may not accept the RFC.</li>
<li>If the RFC is accepted, the PR is merged.</li>
</ul>
<p>RFCs are accepted when they are approved for implementation in React. A more thorough description of the process is available in the repository’s <a href="https://github.com/reactjs/rfcs/blob/master/README.md">README</a>. The exact details may be refined in the future.</p>
<h2 id="who-can-submit-rfcs"><a href="#who-can-submit-rfcs" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Who Can Submit RFCs?</h2>
<p>Anyone! No knowledge of React’s internals is required, nor are you expected to implement the proposal yourself.</p>
<p>As with our other repositories, we do ask that you complete a <a href="https://github.com/reactjs/rfcs#contributor-license-agreement-cla">Contributor License Agreement</a> before we can accept your PR.</p>
<h2 id="what-types-of-changes-should-be-submitted-as-rfcs"><a href="#what-types-of-changes-should-be-submitted-as-rfcs" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>What Types of Changes Should Be Submitted As RFCs?</h2>
<p>Generally, any idea that would benefit from additional review or design before being implemented is a good candidate for an RFC. As a rule of thumb, this means any proposal that adds, changes, or removes a React API.</p>
<p>Not every change must go through the RFC process. Bug fixes or performance improvements that don’t touch the API can be submitted directly to the main library.</p>
<p>We now have several repositories where you can submit contributions to React:</p>
<ul>
<li><strong>Issues, bugfixes, and code changes to the main library</strong>: <a href="https://github.com/facebook/react">facebook/react</a></li>
<li><strong>Website and documentation</strong>: <a href="https://github.com/reactjs/reactjs.org">reactjs/reactjs.org</a></li>
<li><strong>Ideas for changes that need additional review before being implemented</strong>: <a href="https://github.com/reactjs/rfcs">reactjs/rfcs</a></li>
</ul>
<h2 id="rfc-for-a-new-context-api"><a href="#rfc-for-a-new-context-api" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>RFC for A New Context API</h2>
<p>Coinciding with the launch of our RFC process, we’ve submitted a <a href="https://github.com/reactjs/rfcs/pull/2">proposal for a new version of context</a>. The proposal has already received many valuable comments from the community that we will incorporate into the design of the new API.</p>
<p>The context PR is a good example of how a typical RFC should be structured. We’re excited to start receiving your proposals!</p>]]></description><link>https://reactjs.org/blog/2017/12/07/introducing-the-react-rfc-process.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/12/07/introducing-the-react-rfc-process.html</guid><pubDate>Thu, 07 Dec 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v16.2.0: Improved Support for Fragments]]></title><description><![CDATA[<p>React 16.2 is now available! The biggest addition is improved support for returning multiple children from a component’s render method. We call this feature <em>fragments</em>:</p>
<p>Fragments look like empty JSX tags. They let you group a list of children without adding extra nodes to the DOM:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token operator">&lt;</span><span class="token operator">></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildA</span> <span class="token punctuation">/></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildB</span> <span class="token punctuation">/></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildC</span> <span class="token punctuation">/></span></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token operator">></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>This exciting new feature is made possible by additions to both React and JSX.</p>
<h2 id="what-are-fragments"><a href="#what-are-fragments" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>What Are Fragments?</h2>
<p>A common pattern is for a component to return a list of children. Take this example HTML:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-html"><code>Some text.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>A heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
More text.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>Another heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
Even more text.
</code></pre>
      </div>
<p>Prior to version 16, the only way to achieve this in React was by wrapping the children in an extra element, usually a <code>div</code> or <code>span</code>:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token comment">// Extraneous div element :(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span>
      Some text<span class="token punctuation">.</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>A heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
      More text<span class="token punctuation">.</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>Another heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
      Even more text<span class="token punctuation">.</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>To address this limitation, React 16.0 added support for <a href="https://reactjs.org/blog/2017/09/26/react-v16.0.html#new-render-return-types-fragments-and-strings">returning an array of elements from a component’s <code>render</code> method</a>. Instead of wrapping the children in a DOM element, you can put them into an array:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
 <span class="token keyword">return</span> <span class="token punctuation">[</span>
  <span class="token string">"Some text."</span><span class="token punctuation">,</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>heading-1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>A heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>
  <span class="token string">"More text."</span><span class="token punctuation">,</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>heading-2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Another heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>
  <span class="token string">"Even more text."</span>
 <span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>However, this has some confusing differences from normal JSX:</p>
<ul>
<li>Children in an array must be separated by commas.</li>
<li>Children in an array must have a key to prevent React’s <a href="https://reactjs.org/docs/lists-and-keys.html#keys">key warning</a>.</li>
<li>Strings must be wrapped in quotes.</li>
</ul>
<p>To provide a more consistent authoring experience for fragments, React now provides a first-class <code>Fragment</code> component that can be used in place of arrays.</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
<span class="gatsby-highlight-code-line">    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Fragment</span><span class="token punctuation">></span></span>
</span>      Some text<span class="token punctuation">.</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>A heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
      More text<span class="token punctuation">.</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>Another heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
      Even more text<span class="token punctuation">.</span>
<span class="gatsby-highlight-code-line">    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Fragment</span><span class="token punctuation">></span></span>
</span>  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>You can use <code>&#x3C;Fragment /></code> the same way you’d use any other element, without changing the way you write JSX. No commas, no keys, no quotes.</p>
<p>The Fragment component is available on the main React object:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">const</span> Fragment <span class="token operator">=</span> React<span class="token punctuation">.</span>Fragment<span class="token punctuation">;</span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Fragment</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildA</span> <span class="token punctuation">/></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildB</span> <span class="token punctuation">/></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildC</span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Fragment</span><span class="token punctuation">></span></span>

<span class="token comment">// This also works</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>React.Fragment</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildA</span> <span class="token punctuation">/></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildB</span> <span class="token punctuation">/></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ChildC</span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>React.Fragment</span><span class="token punctuation">></span></span>
</code></pre>
      </div>
<h2 id="jsx-fragment-syntax"><a href="#jsx-fragment-syntax" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>JSX Fragment Syntax</h2>
<p>Fragments are a common pattern in our codebases at Facebook. We anticipate they’ll be widely adopted by other teams, too. To make the authoring experience as convenient as possible, we’re adding syntactical support for fragments to JSX:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
<span class="gatsby-highlight-code-line">    <span class="token operator">&lt;</span><span class="token operator">></span>
</span>      Some text<span class="token punctuation">.</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>A heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
      More text<span class="token punctuation">.</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span><span class="token punctuation">></span></span>Another heading<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">></span></span>
      Even more text<span class="token punctuation">.</span>
<span class="gatsby-highlight-code-line">    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token operator">></span>
</span>  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>In React, this desugars to a <code>&#x3C;React.Fragment/></code> element, as in the example from the previous section. (Non-React frameworks that use JSX may compile to something different.)</p>
<p>Fragment syntax in JSX was inspired by prior art such as the <code>XMLList() &#x3C;>&#x3C;/></code> constructor in <a href="https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/E4X_for_templating">E4X</a>. Using a pair of empty tags is meant to represent the idea it won’t add an actual element to the DOM.</p>
<h3 id="keyed-fragments"><a href="#keyed-fragments" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Keyed Fragments</h3>
<p>Note that the <code>&#x3C;>&#x3C;/></code> syntax does not accept attributes, including keys.</p>
<p>If you need a keyed fragment, you can use <code>&#x3C;Fragment /></code> directly. A use case for this is mapping a collection to an array of fragments — for example, to create a description list:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">function</span> <span class="token function">Glossary</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dl</span><span class="token punctuation">></span></span>
      <span class="token punctuation">{</span>props<span class="token punctuation">.</span>items<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>item <span class="token operator">=></span> <span class="token punctuation">(</span>
        <span class="token comment">// Without the `key`, React will fire a key warning</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Fragment</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dt</span><span class="token punctuation">></span></span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>term<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dt</span><span class="token punctuation">></span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span><span class="token punctuation">></span></span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>description<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Fragment</span><span class="token punctuation">></span></span>
      <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dl</span><span class="token punctuation">></span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p><code>key</code> is the only attribute that can be passed to <code>Fragment</code>. In the future, we may add support for additional attributes, such as event handlers.</p>
<h3 id="live-demo"><a href="#live-demo" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Live Demo</h3>
<p>You can experiment with JSX fragment syntax with this <a href="https://codepen.io/reactjs/pen/VrEbjE?editors=1000">CodePen</a>.</p>
<h2 id="support-for-fragment-syntax"><a href="#support-for-fragment-syntax" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Support for Fragment Syntax</h2>
<p>Support for fragment syntax in JSX will vary depending on the tools you use to build your app. Please be patient as the JSX community works to adopt the new syntax. We’ve been working closely with maintainers of the most popular projects:</p>
<h3 id="create-react-app"><a href="#create-react-app" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Create React App</h3>
<p>Experimental support for fragment syntax will be added to Create React App within the next few days. A stable release may take a bit longer as we await adoption by upstream projects.</p>
<h3 id="babel"><a href="#babel" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Babel</h3>
<p>Support for JSX fragments is available in <a href="https://github.com/babel/babel/releases/tag/v7.0.0-beta.31">Babel v7.0.0-beta.31</a> and above! If you are already on Babel 7, simply update to the latest Babel and plugin transform:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token comment"># for yarn users</span>
yarn upgrade @babel/core @babel/plugin-transform-react-jsx
<span class="token comment"># for npm users</span>
<span class="token function">npm</span> update @babel/core @babel/plugin-transform-react-jsx
</code></pre>
      </div>
<p>Or if you are using the <a href="https://www.npmjs.com/package/@babel/preset-react">react preset</a>:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token comment"># for yarn users</span>
yarn upgrade @babel/core @babel/preset-react
<span class="token comment"># for npm users</span>
<span class="token function">npm</span> update @babel/core @babel/preset-react
</code></pre>
      </div>
<p>Note that Babel 7 is technically still in beta, but a <a href="https://babeljs.io/blog/2017/09/12/planning-for-7.0">stable release is coming soon</a>.</p>
<p>Unfortunately, support for Babel 6.x is not available, and there are currently no plans to backport.</p>
<h4 id="babel-with-webpack-babel-loader"><a href="#babel-with-webpack-babel-loader" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Babel with Webpack (babel-loader)</h4>
<p>If you are using Babel with <a href="https://webpack.js.org/">Webpack</a>, no additional steps are needed because <a href="https://github.com/babel/babel-loader">babel-loader</a> will use your peer-installed version of Babel.</p>
<h4 id="babel-with-other-frameworks"><a href="#babel-with-other-frameworks" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Babel with Other Frameworks</h4>
<p>If you use JSX with a non-React framework like Inferno or Preact, there is a <a href="https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx#pragmafrag">pragma option available in babel-plugin-transform-react-jsx</a> that configures the Babel compiler to de-sugar the <code>&#x3C;>&#x3C;/></code> syntax to a custom identifier.</p>
<h3 id="typescript"><a href="#typescript" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>TypeScript</h3>
<p>TypeScript has full support for fragment syntax! Please upgrade to <a href="https://github.com/Microsoft/TypeScript/releases/tag/v2.6.2">version 2.6.2</a>. (Note that this is important even if you are already on version 2.6.1, since support was added as patch release in 2.6.2.)</p>
<p>Upgrade to the latest TypeScript with the command:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token comment"># for yarn users</span>
yarn upgrade typescript
<span class="token comment"># for npm users</span>
<span class="token function">npm</span> update typescript
</code></pre>
      </div>
<h3 id="flow"><a href="#flow" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Flow</h3>
<p><a href="https://flow.org/">Flow</a> support for JSX fragments is available starting in <a href="https://github.com/facebook/flow/releases/tag/v0.59.0">version 0.59</a>! Simply run</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token comment"># for yarn users</span>
yarn upgrade flow-bin
<span class="token comment"># for npm users</span>
<span class="token function">npm</span> update flow-bin
</code></pre>
      </div>
<p>to update Flow to the latest version.</p>
<h3 id="prettier"><a href="#prettier" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Prettier</h3>
<p><a href="https://github.com/prettier/prettier">Prettier</a> added support for fragments in their <a href="https://prettier.io/blog/2017/12/05/1.9.0.html#jsx-fragment-syntax-3237-https-githubcom-prettier-prettier-pull-3237-by-duailibe-https-githubcom-duailibe">1.9 release</a>.</p>
<h3 id="eslint"><a href="#eslint" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>ESLint</h3>
<p>JSX Fragments are supported by <a href="https://eslint.org/">ESLint</a> 3.x when it is used together with <a href="https://github.com/babel/babel-eslint">babel-eslint</a>:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token comment"># for yarn users</span>
yarn add eslint@3.x babel-eslint@7
<span class="token comment"># for npm users</span>
<span class="token function">npm</span> <span class="token function">install</span> eslint@3.x babel-eslint@7
</code></pre>
      </div>
<p>or if you already have it, then upgrade:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token comment"># for yarn users</span>
yarn upgrade eslint@3.x babel-eslint@7
<span class="token comment"># for npm users</span>
<span class="token function">npm</span> update eslint@3.x babel-eslint@7
</code></pre>
      </div>
<p>Ensure you have the following line inside your <code>.eslintrc</code>:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsxon"><code>"parser": "babel-eslint"</code></pre>
      </div>
<p>That’s it!</p>
<p>Note that <code>babel-eslint</code> is not officially supported by ESLint. We’ll be looking into adding support for fragments to ESLint 4.x itself in the coming weeks (see <a href="https://github.com/eslint/eslint/issues/9662">issue #9662</a>).</p>
<h3 id="editor-support"><a href="#editor-support" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Editor Support</h3>
<p>It may take a while for fragment syntax to be supported in your text editor. Please be patient as the community works to adopt the latest changes. In the meantime, you may see errors or inconsistent highlighting if your editor does not yet support fragment syntax. Generally, these errors can be safely ignored.</p>
<h4 id="typescript-editor-support"><a href="#typescript-editor-support" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>TypeScript Editor Support</h4>
<p>If you’re a TypeScript user — great news! Editor support for JSX fragments is already available in <a href="https://www.microsoft.com/en-us/download/details.aspx?id=48593">Visual Studio 2015</a>, <a href="https://www.microsoft.com/en-us/download/details.aspx?id=55258">Visual Studio 2017</a>, <a href="https://code.visualstudio.com/updates/v1_19#_jsx-fragment-syntax">Visual Studio Code</a> and <a href="https://packagecontrol.io/packages/TypeScript">Sublime Text via Package Control</a>.</p>
<h3 id="other-tools"><a href="#other-tools" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Other Tools</h3>
<p>For other tools, please check with the corresponding documentation to check if there is support available. However, if you’re blocked by your tooling, you can always start with using the <code>&#x3C;Fragment></code> component and perform a codemod later to replace it with the shorthand syntax when the appropriate support is available.</p>
<h2 id="installation"><a href="#installation" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Installation</h2>
<p>React v16.2.0 is available on the npm registry.</p>
<p>To install React 16 with Yarn, run:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code>yarn add react@^16.2.0 react-dom@^16.2.0
</code></pre>
      </div>
<p>To install React 16 with npm, run:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token function">npm</span> <span class="token function">install</span> --save react@^16.2.0 react-dom@^16.2.0
</code></pre>
      </div>
<p>We also provide UMD builds of React via a CDN:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">crossorigin</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>https://unpkg.com/react@16/umd/react.production.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">crossorigin</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>https://unpkg.com/react-dom@16/umd/react-dom.production.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
</code></pre>
      </div>
<p>Refer to the documentation for <a href="/docs/installation.html">detailed installation instructions</a>.</p>
<h2 id="changelog"><a href="#changelog" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Changelog</h2>
<h3 id="react"><a href="#react" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>React</h3>
<ul>
<li>Add <code>Fragment</code> as named export to React. (<a href="https://github.com/clemmy">@clemmy</a> in <a href="https://github.com/facebook/react/pull/10783">#10783</a>)</li>
<li>Support experimental Call/Return types in <code>React.Children</code> utilities. (<a href="https://github.com/MatteoVH">@MatteoVH</a> in <a href="https://github.com/facebook/react/pull/11422">#11422</a>)</li>
</ul>
<h3 id="react-dom"><a href="#react-dom" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>React DOM</h3>
<ul>
<li>Fix radio buttons not getting checked when using multiple lists of radios. (<a href="https://github.com/landvibe">@landvibe</a> in <a href="https://github.com/facebook/react/pull/11227">#11227</a>)</li>
<li>Fix radio buttons not receiving the <code>onChange</code> event in some cases. (<a href="https://github.com/jquense">@jquense</a> in <a href="https://github.com/facebook/react/pull/11028">#11028</a>)</li>
</ul>
<h3 id="react-test-renderer"><a href="#react-test-renderer" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>React Test Renderer</h3>
<ul>
<li>Fix <code>setState()</code> callback firing too early when called from <code>componentWillMount</code>. (<a href="https://github.com/accordeiro">@accordeiro</a> in <a href="https://github.com/facebook/react/pull/11507">#11507</a>)</li>
</ul>
<h3 id="react-reconciler"><a href="#react-reconciler" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>React Reconciler</h3>
<ul>
<li>Expose <code>react-reconciler/reflection</code> with utilities useful to custom renderers. (<a href="https://github.com/rivenhk">@rivenhk</a> in <a href="https://github.com/facebook/react/pull/11683">#11683</a>)</li>
</ul>
<h3 id="internal-changes"><a href="#internal-changes" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Internal Changes</h3>
<ul>
<li>Many tests were rewritten against the public API. Big thanks to <a href="https://github.com/facebook/react/issues/11299">everyone who contributed</a>!</li>
</ul>
<h2 id="acknowledgments"><a href="#acknowledgments" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Acknowledgments</h2>
<p>This release was made possible by our open source contributors. A big thanks to everyone who filed issues, contributed to syntax discussions, reviewed pull requests, added support for JSX fragments in third party libraries, and more!</p>
<p>Special thanks to the <a href="https://www.typescriptlang.org/">TypeScript</a> and <a href="https://flow.org/">Flow</a> teams, as well as the <a href="https://babeljs.io/">Babel</a> maintainers, who helped make tooling support for the new syntax go seamlessly.</p>
<p>Thanks to <a href="https://github.com/gajus/">Gajus Kuizinas</a> and other contributors who prototyped the <code>Fragment</code> component in open source.</p>]]></description><link>https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html</guid><pubDate>Tue, 28 Nov 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v16.0]]></title><description><![CDATA[<p>We’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 id="new-render-return-types-fragments-and-strings"><a href="#new-render-return-types-fragments-and-strings" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>New render return types: fragments and strings</h3>
<p>You can now return an array of elements from a component’s <code>render</code> method. Like with other arrays, you’ll need to add a key to each element to avoid the key warning:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// No need to wrap list items in an extra element!</span>
  <span class="token keyword">return</span> <span class="token punctuation">[</span>
    <span class="token comment">// Don't forget the keys :)</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>A<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>First item<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>B<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Second item<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">key</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>C<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Third item<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>
  <span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p><a href="/blog/2017/11/28/react-v16.2.0-fragment-support.html">Starting with React 16.2.0</a>, we are adding support for a special fragment syntax to JSX that doesn’t require keys.</p>
<p>We’ve added support for returning strings, too:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token string">'Look ma, no spans!'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p><a href="/docs/react-component.html#render">See the full list of supported return types</a>.</p>
<h3 id="better-error-handling"><a href="#better-error-handling" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’s render or lifecycle methods, the whole component tree is unmounted from the root. This prevents the display of corrupted data. However, it’s probably not the ideal user experience.</p>
<p>Instead of unmounting the whole app every time there’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="/blog/2017/07/26/error-handling-in-react-16.html">previous post on error handling in React 16</a>.</p>
<h3 id="portals"><a href="#portals" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// React does *not* create a new div. It renders the children into `domNode`.</span>
  <span class="token comment">// `domNode` is any valid DOM node, regardless of its location in the DOM.</span>
  <span class="token keyword">return</span> ReactDOM<span class="token punctuation">.</span><span class="token function">createPortal</span><span class="token punctuation">(</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>children<span class="token punctuation">,</span>
    domNode<span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>See a full example in the <a href="/docs/portals.html">documentation for portals</a>.</p>
<h3 id="better-server-side-rendering"><a href="#better-server-side-rendering" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Better server-side rendering</h3>
<p>React 16 includes a completely rewritten server renderer. It’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’s SSR improvements</a>. According to Sasha’s synthetic benchmarks, server rendering in React 16 is roughly <strong>three times faster</strong> than React 15. “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!” (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’t recommend that you render different content on the client versus the server, but it can be useful in some cases (e.g. timestamps). <strong>However, it’s dangerous to have missing nodes on the server render as this might cause sibling nodes to be created with incorrect attributes.</strong></p>
<p>See the <a href="/docs/react-dom-server.html">documentation for <code>ReactDOMServer</code></a> for more details.</p>
<h3 id="support-for-custom-dom-attributes"><a href="#support-for-custom-dom-attributes" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Support for custom DOM attributes</h3>
<p>Instead of ignoring unrecognized HTML and SVG attributes, React will now <a href="/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’s attribute whitelist, resulting in reduced file sizes.</p>
<h3 id="reduced-file-size"><a href="#reduced-file-size" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’s impact on bundle size is roughly consistent regardless of how you ship your app, whether it’s with Webpack, Browserify, the pre-built UMD bundles, or any other system.</p>
<h3 id="mit-licensed"><a href="#mit-licensed" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’ve also published React 15.6.2 under MIT, for those who are unable to upgrade immediately.</p>
<h3 id="new-core-architecture"><a href="#new-core-architecture" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>New core architecture</h3>
<p>React 16 is the first version of React built on top of a new core architecture, codenamed “Fiber.” 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’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’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>
<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’re not enabling any async features yet, but we’re excited to start rolling them out in the coming months. Stay tuned!</p>
<h2 id="installation"><a href="#installation" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="gatsby-highlight">
      <pre class="gatsby-code-bash"><code>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="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token function">npm</span> <span class="token function">install</span> --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="gatsby-highlight">
      <pre class="gatsby-code-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">crossorigin</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>https://unpkg.com/react@16/umd/react.production.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">crossorigin</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>https://unpkg.com/react-dom@16/umd/react-dom.production.min.js<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token script language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
</code></pre>
      </div>
<p>Refer to the documentation for <a href="/docs/installation.html">detailed installation instructions</a>.</p>
<h2 id="upgrading"><a href="#upgrading" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’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>
<p>For deprecations listed in <a href="#packaging">packaging</a> below, codemods are provided to automatically transform your deprecated code.
See the <a href="/blog/2017/04/07/react-v15.5.0.html">15.5.0</a> blog post for more information, or browse the codemods in the <a href="https://github.com/reactjs/react-codemod">react-codemod</a> project.</p>
<h3 id="new-deprecations"><a href="#new-deprecations" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>New deprecations</h3>
<p>Hydrating a server-rendered container now has an explicit API. If you’re reviving server-rendered HTML, use <a href="/docs/react-dom.html#hydrate"><code>ReactDOM.hydrate</code></a> instead of <code>ReactDOM.render</code>. Keep using <code>ReactDOM.render</code> if you’re just doing client-side rendering.</p>
<h3 id="react-addons"><a href="#react-addons" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>React Addons</h3>
<p>As previously announced, we’ve <a href="/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’t publish additional updates.</p>
<p>Refer to the previous announcement for <a href="/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’s likely that we’ll release a new version of this tool in the future. In the meantime, you can <a href="/docs/optimizing-performance.html#profiling-components-with-the-chrome-performance-tab">use your browser’s performance tools to profile React components</a>.</p>
<h3 id="breaking-changes"><a href="#breaking-changes" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Breaking changes</h3>
<p>React 16 includes a number of small breaking changes. These only affect uncommon use cases and we don’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_renderSubtreeIntoContainer</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>
<p><code>setState</code>:</p>
<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>&#x3C;A /></code> with <code>&#x3C;B /></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’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>
<li><code>ReactDOM.unstable_batchedUpdates</code> now only takes one extra argument after the callback.</li>
</ul>
<h3 id="packaging"><a href="#packaging" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="/blog/2017/04/07/react-v15.5.0.html">15.5.0</a> and <a href="/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>
<p>The names and paths to the single-file browser builds have changed to emphasize the difference between development and production builds. For example:</p>
<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 id="javascript-environment-requirements"><a href="#javascript-environment-requirements" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 &#x3C; 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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">import</span> <span class="token string">'core-js/es6/map'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token string">'core-js/es6/set'</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> React <span class="token keyword">from</span> <span class="token string">'react'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> ReactDOM <span class="token keyword">from</span> <span class="token string">'react-dom'</span><span class="token punctuation">;</span>

ReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span>Hello<span class="token punctuation">,</span> world<span class="token operator">!</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span><span class="token punctuation">,</span>
  document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'root'</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
      </div>
<p>React also depends on <code>requestAnimationFrame</code> (even in test environments).<br>
You can use the <a href="https://www.npmjs.com/package/raf">raf</a> package to shim <code>requestAnimationFrame</code>:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">import</span> <span class="token string">'raf/polyfill'</span><span class="token punctuation">;</span>
</code></pre>
      </div>
<h2 id="acknowledgments"><a href="#acknowledgments" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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><link>https://reactjs.org/blog/2017/09/26/react-v16.0.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/09/26/react-v16.0.html</guid><pubDate>Tue, 26 Sep 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v15.6.2]]></title><description><![CDATA[<p>Today we’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’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 id="installation"><a href="#installation" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’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="gatsby-highlight">
      <pre class="gatsby-code-bash"><code>yarn add react@^15.6.2 react-dom@^15.6.2
</code></pre>
      </div>
<p>To install React with npm, run:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token function">npm</span> <span class="token function">install</span> --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="/docs/optimizing-performance.html#use-the-production-build">use the production build</a>.</p>
<p>In case you don’t use a bundler, we also provide pre-built bundles in the npm packages which you can <a href="/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’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 id="changelog"><a href="#changelog" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Changelog</h2>
<h2 id="1562-september-25-2017"><a href="#1562-september-25-2017" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>15.6.2 (September 25, 2017)</h2>
<h3 id="all-packages"><a href="#all-packages" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>All Packages</h3>
<ul>
<li>Switch from BSD + Patents to MIT license</li>
</ul>
<h3 id="react-dom"><a href="#react-dom" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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><link>https://reactjs.org/blog/2017/09/25/react-v15.6.2.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/09/25/react-v15.6.2.html</guid><pubDate>Mon, 25 Sep 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[DOM Attributes in React 16]]></title><description><![CDATA[<p>In the past, React used to ignore unknown DOM attributes. If you wrote JSX with an attribute that React doesn’t recognize, React would just skip it. For example, this:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token comment">// Your code:</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">mycustomattribute</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>something<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
</code></pre>
      </div>
<p>would render an empty div to the DOM with React 15:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token comment">// React 15 output:</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token punctuation">/></span></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token comment">// React 16 output:</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">mycustomattribute</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>something<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
</code></pre>
      </div>
<h2 id="why-are-we-changing-this"><a href="#why-are-we-changing-this" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">tabIndex</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>-1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token comment">// ...</span>
summary<span class="token punctuation">:</span> <span class="token string">'summary'</span><span class="token punctuation">,</span>
tabIndex<span class="token punctuation">:</span> <span class="token string">'tabindex'</span>
target<span class="token punctuation">:</span> <span class="token string">'target'</span><span class="token punctuation">,</span>
title<span class="token punctuation">:</span> <span class="token string">'title'</span><span class="token punctuation">,</span>
<span class="token comment">// ...</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’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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token comment">// Yes, please</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">tabIndex</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>-1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>

<span class="token comment">// Warning: Invalid DOM property `tabindex`. Did you mean `tabIndex`?</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">tabindex</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>-1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
</code></pre>
      </div>
<p>In other words, the way you use DOM components in React hasn’t changed, but now you have some new capabilities.</p>
<h2 id="should-i-keep-data-in-custom-attributes"><a href="#should-i-keep-data-in-custom-attributes" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Should I Keep Data in Custom Attributes?</h2>
<p>No. We don’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 id="data-and-aria-attributes"><a href="#data-and-aria-attributes" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">data-foo</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>42<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">aria-label</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Close<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>onClose<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>
</code></pre>
      </div>
<p>This has not changed.</p>
<p><a href="/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 id="migration-path"><a href="#migration-path" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Migration Path</h2>
<p>We have included <a href="/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’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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">myData</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">'</span>[Object object]<span class="token punctuation">'</span></span> <span class="token punctuation">/></span></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’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 id="changes-in-detail"><a href="#changes-in-detail" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Changes in Detail</h2>
<p>We’ve made a few other changes to make the behavior more predictable and help ensure you’re not making mistakes. We don’t anticipate that these changes are likely to break real-world applications.</p>
<p><strong>These changes only affect DOM components like <code>&#x3C;div></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">mycustomattribute</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>value<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">mycustomattribute</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token number">42</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">mycustomattribute</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>myObject<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">tabindex</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>-1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>hi<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token boolean">false</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token operator">&lt;</span>div className<span class="token operator">=</span><span class="token punctuation">{</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">}</span> <span class="token operator">/</span><span class="token operator">></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token function">Symbol</span><span class="token punctuation">(</span><span class="token string">'foo'</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">tabIndex</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token number">0</span> <span class="token operator">/</span> <span class="token number">0</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>
</code></pre>
      </div>
<p>React 15: Converts <code>NaN</code>s to strings and passes them through.<br>
React 16: Converts <code>NaN</code>s to strings and passes them through with a warning.</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 id="try-it"><a href="#try-it" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="thanks"><a href="#thanks" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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:pr+author:nhunzaker+is:closed">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 id="future-work"><a href="#future-work" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’d like to help!</p>]]></description><link>https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html</guid><pubDate>Fri, 08 Sep 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[Error Handling in React 16]]></title><description><![CDATA[<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 id="behavior-in-react-15-and-earlier"><a href="#behavior-in-react-15-and-earlier" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="introducing-error-boundaries"><a href="#introducing-error-boundaries" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">class</span> <span class="token class-name">ErrorBoundary</span> <span class="token keyword">extends</span> <span class="token class-name">React<span class="token punctuation">.</span>Component</span> <span class="token punctuation">{</span>
  <span class="token function">constructor</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">super</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">=</span> <span class="token punctuation">{</span> hasError<span class="token punctuation">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

<span class="gatsby-highlight-code-line">  <span class="token function">componentDidCatch</span><span class="token punctuation">(</span>error<span class="token punctuation">,</span> info<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="gatsby-highlight-code-line">    <span class="token comment">// Display fallback UI</span>
</span><span class="gatsby-highlight-code-line">    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> hasError<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="gatsby-highlight-code-line">    <span class="token comment">// You can also log the error to an error reporting service</span>
</span><span class="gatsby-highlight-code-line">    <span class="token function">logErrorToMyService</span><span class="token punctuation">(</span>error<span class="token punctuation">,</span> info<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="gatsby-highlight-code-line">  <span class="token punctuation">}</span>
</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="gatsby-highlight-code-line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>hasError<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="gatsby-highlight-code-line">      <span class="token comment">// You can render any custom fallback UI</span>
</span><span class="gatsby-highlight-code-line">      <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">></span></span>Something went wrong<span class="token punctuation">.</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">></span></span><span class="token punctuation">;</span>
</span><span class="gatsby-highlight-code-line">    <span class="token punctuation">}</span>
</span>    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>children<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>Then you can use it as a regular component:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ErrorBoundary</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>MyWidget</span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ErrorBoundary</span><span class="token punctuation">></span></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 id="live-demo"><a href="#live-demo" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="where-to-place-error-boundaries"><a href="#where-to-place-error-boundaries" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="new-behavior-for-uncaught-errors"><a href="#new-behavior-for-uncaught-errors" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="component-stack-traces"><a href="#component-stack-traces" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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>

  <a class="gatsby-resp-image-link" href="/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-71000.png" style="display: block" target="_blank" rel="noopener">
  
  <span class="gatsby-resp-image-wrapper" style="position: relative; display: block; ; max-width: 840px; margin-left: auto; margin-right: auto;">
    <span class="gatsby-resp-image-background-image" style="padding-bottom: 17.114303560274827%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAIAAAAcOLh5AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAXUlEQVQI15VLzQoAERj0/o/lxkU2fEQS5aa1e96a5Q12a5rmlz3GwHukhBCwtHPQGjGCaCeLV7ustSjldm4SnVpf3s9a2V7kvD+tYc5fYOgdUoJzKAUhcBwY4+P5BZ10pgdBiIxYAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;">
      <img class="gatsby-resp-image-image" style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;" alt="Component stack traces in error message" title="" src="/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-acf85.png" srcset="/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-c1418.png 210w,
/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-5d5d8.png 420w,
/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-acf85.png 840w,
/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-de0cd.png 1260w,
/static/error-boundaries-stack-trace-f1276837b03821b43358d44c14072945-71000.png 1601w" sizes="(max-width: 840px) 100vw, 840px">
    </span>
  </span>
  
  </a>
    
<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>

  <a class="gatsby-resp-image-link" href="/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-4e7a0.png" style="display: block" target="_blank" rel="noopener">
  
  <span class="gatsby-resp-image-wrapper" style="position: relative; display: block; ; max-width: 840px; margin-left: auto; margin-right: auto;">
    <span class="gatsby-resp-image-background-image" style="padding-bottom: 16.46837820914214%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAIAAAAcOLh5AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAW0lEQVQI15WMPQrAIBSDvf+tHDuICD7/dVBci4WOhdR3gxY+QkJIxGMtQkAprNs7B605brPxHikhZxCh1tv75dxpzEW0ehdct8bdGFjrFwJz4jggJZTiixi/j1+ViaYQxC7NFgAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;">
      <img class="gatsby-resp-image-image" style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;" alt="Component stack traces with line numbers in error message" title="" src="/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-acf85.png" srcset="/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-c1418.png 210w,
/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-5d5d8.png 420w,
/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-acf85.png 840w,
/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-de0cd.png 1260w,
/static/error-boundaries-stack-trace-line-numbers-45611d4fdbd152829b28ae2348d6dcba-4e7a0.png 1597w" sizes="(max-width: 840px) 100vw, 840px">
    </span>
  </span>
  
  </a>
    
<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 id="why-not-use-try--catch"><a href="#why-not-use-try--catch" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token keyword">try</span> <span class="token punctuation">{</span>
  <span class="token function">showButton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// ...</span>
<span class="token punctuation">}</span>
</code></pre>
      </div>
<p>However, React components are declarative and specify <em>what</em> should be rendered:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-jsx"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Button</span> <span class="token punctuation">/></span></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 id="naming-changes-from-react-15"><a href="#naming-changes-from-react-15" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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><link>https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html</guid><pubDate>Wed, 26 Jul 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v15.6.0]]></title><description><![CDATA[<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 id="improving-inputs"><a href="#improving-inputs" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 ‘x’ button or right-click ‘delete’ 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 id="less-noisy-deprecation-warnings"><a href="#less-noisy-deprecation-warnings" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’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 id="installation"><a href="#installation" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’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="gatsby-highlight">
      <pre class="gatsby-code-bash"><code>yarn add react@^15.6.0 react-dom@^15.6.0
</code></pre>
      </div>
<p>To install React with npm, run:</p>
<div class="gatsby-highlight">
      <pre class="gatsby-code-bash"><code><span class="token function">npm</span> <span class="token function">install</span> --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="/docs/optimizing-performance.html#use-the-production-build">use the production build</a>.</p>
<p>In case you don’t use a bundler, we also provide pre-built bundles in the npm packages which you can <a href="/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’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 id="changelog"><a href="#changelog" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Changelog</h2>
<h2 id="1560-june-13-2017"><a href="#1560-june-13-2017" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>15.6.0 (June 13, 2017)</h2>
<h3 id="react"><a href="#react" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="react-dom"><a href="#react-dom" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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 id="react-addons"><a href="#react-addons" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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><link>https://reactjs.org/blog/2017/06/13/react-v15.6.0.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/06/13/react-v15.6.0.html</guid><pubDate>Tue, 13 Jun 2017 00:00:00 GMT</pubDate></item><item><title><![CDATA[What's New in Create React App]]></title><description><![CDATA[<p>Less than a year ago, we introduced <a href="/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 id="webpack-2"><a href="#webpack-2" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’t eject don’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’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="/cra-update-exports-d9aaae3589e6a7b6076b64de79f4bd13.gif" alt="Export validation"> </p>
<p>In the future, as the ecosystem around ES6 modules matures, you can expect more improvements to your app’s bundle size thanks to <a href="https://webpack.js.org/guides/tree-shaking/">tree shaking</a>.</p>
<h3 id="runtime-error-overlay"><a href="#runtime-error-overlay" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a> 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:
<br>
<img src="/cra-runtime-error-a0c1e436d1ea034c8ecaf48e8bcb2890.gif" alt="Runtime error overlay"> </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 id="progressive-web-apps-by-default"><a href="#progressive-web-apps-by-default" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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>
  <a
    class="gatsby-resp-image-link"
    href="/static/cra-pwa-cff5fa9b92de804e655ea669a53d4d9c-c9445.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block; ; max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 41.40893470790378%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAIAAAB2/0i6AAAACXBIWXMAABYlAAAWJQFJUiTwAAABKElEQVQY03VQyW7CMBT0/39OpUq9oCISQS/0Uji0EAIlC16y2Q7ZsNMJFJRD+04zoxn7vSH6Y0UpDUVVHkOtdZZlnPNctVVVMcaEEEopfp0kSeq6hpimKXSkSBzHRSHBYUIA0tbbge78PcD+cJBSFkWh/hrCOKeUrdbrOD4xxr82XhBGjAuEj0EQRbG/P2y2HpYqpIQTH5RlCR2ANE3T972xtm0NgO06a+0ArDXGjMFgGwHo5MHbdsj09/At9h+4YXKiDDXgia4zQiRaqSzP0yyrtL44r3Y+s2+uWTiX+Uw8P1XTSRCEMKOaYW10CI5mcCSaBMU9uKqevEgeiOidhcvTcZmyT3QR+d/In68DD+lHY6/zux7OcKd24eDn2+fYonOnl3P9MP8AucXBSjgQaVsAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Loading assets from service worker"
        title=""
        src="/static/cra-pwa-cff5fa9b92de804e655ea669a53d4d9c-acf85.png"
        srcset="/static/cra-pwa-cff5fa9b92de804e655ea669a53d4d9c-c1418.png 210w,
/static/cra-pwa-cff5fa9b92de804e655ea669a53d4d9c-5d5d8.png 420w,
/static/cra-pwa-cff5fa9b92de804e655ea669a53d4d9c-acf85.png 840w,
/static/cra-pwa-cff5fa9b92de804e655ea669a53d4d9c-c9445.png 1164w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
     </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 id="jest-20"><a href="#jest-20" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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="/cra-jest-search-bf7aa2c62ad1f43fca436bfb4d8b3a0f.gif" alt="Immersive test watcher"> </p>
<p>Additionally, Create React App now support configuring a few Jest options related to coverage reporting.</p>
<h3 id="code-splitting-with-dynamic-import"><a href="#code-splitting-with-dynamic-import" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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’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="/cra-dynamic-import-b967396662319e6aa6170dab232f0286.gif" alt="Creating chunks with dynamic import"></p>
<h3 id="better-console-output"><a href="#better-console-output" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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>
  <a
    class="gatsby-resp-image-link"
    href="/static/cra-better-output-5d3b4caf2ae115ca4ab1f15e6e19680d-a6f54.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block; ; max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 36%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAIAAACHqfpvAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA+ElEQVQY041Qy26DMBDkIwJpgzASSmMXsI0xfhBLiCPf0iMRDj3SHHrrN3cbqkqpcsjIWo/WMzsrB8vyNn7N75f5fPH+Y5o/z36ZvPfTNI0/OI3rdfolKweAKIh24TaJwqcwitcTQd08hkDKJr+CUqq1rqrKOccY67oOKqUlu/aV0gih/+YEIeeOGOO/VpHnnPMGoFRrrRBiGIYEJXeSsyyr6xrSYHbf95yz1SylhGTIBG6Mgac7Zmst7Ky0hrVXXdseIZUyplRDCIEpRVFAH5Rpmt6YCXkVtQD1fv9itDYWZLosS8g8YHzI811BY8qeMYkZD8Obv/wG1O5Pc7AJShcAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Better console output"
        title=""
        src="/static/cra-better-output-5d3b4caf2ae115ca4ab1f15e6e19680d-acf85.png"
        srcset="/static/cra-better-output-5d3b4caf2ae115ca4ab1f15e6e19680d-c1418.png 210w,
/static/cra-better-output-5d3b4caf2ae115ca4ab1f15e6e19680d-5d5d8.png 420w,
/static/cra-better-output-5d3b4caf2ae115ca4ab1f15e6e19680d-acf85.png 840w,
/static/cra-better-output-5d3b4caf2ae115ca4ab1f15e6e19680d-a6f54.png 1000w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
     </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 id="but-wait-theres-more"><a href="#but-wait-theres-more" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>But Wait… There’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 id="acknowledgements"><a href="#acknowledgements" aria-hidden="true" class="anchor"><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>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><link>https://reactjs.org/blog/2017/05/18/whats-new-in-create-react-app.html</link><guid isPermaLink="false">https://reactjs.org/blog/2017/05/18/whats-new-in-create-react-app.html</guid><pubDate>Thu, 18 May 2017 00:00:00 GMT</pubDate></item></channel></rss>