DATA Virtual DOM (JS) - $ React elements Real DOM - $$$ HTML elements b div p a i b div p a i PROPS CHANGED span RECONCILER (REACT) NEW DATA span RENDERER (REACT-DOM) span
stack Browser main thread POTENTIAL LONG FRAME We cannot. How can we pause this process and resume later from where we left off? Can we split this work into chunks?
thread REACT FIBER Cooperative scheduling and requestIdleCallback Browser main thread React Fiber is a reimplementation of the React reconciler. It allows high priority updates to jump ahead low priority updates. It is built with full backward compatibility in mind Its new algorithm is a great foundation for async rendering features. It can pause visiting the tree at any time and restart later from where it left off.
div. It renders the children into `domNode`. // `domNode` is any valid DOM node, regardless of its location in the DOM. return ReactDOM.createPortal( this.props.children, domNode, ); } Portals are a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. Please prefer using portals over using multiple react roots.
minimal React codemod to update code which used the old api - import React, { PropTypes, Component } from 'react'; + import React, { Component } from 'react'; + import PropTypes from 'prop-types'; $ jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js <path>
you a warning for 3rd party libraries which have React 15 as a peer dependency. In our case these libraries worked fine after the upgrade to React 16. Anyhow we updated them to fix the package manager warnings. npm WARN [email protected] requires a peer of react@^15 but none is installed.
Enzyme 3+ const Enzyme = require('enzyme'); const Adapter = require('enzyme-adapter-react-16'); Enzyme.configure({ adapter: new Adapter() }); In our case fixing unit tests was the area which took the most effort.
but it still does not take fully advantage of it just yet. At the moment Fiber is used on compatibility mode with the old React stack reconciler and all updates are treated synchronously. Upgrading to React 16 seems to be pretty painless and it brings some performance benefits especially if you are doing SSR. A new stable version of the context API will be available in React 16.3. Time Slicing and Suspense are the two main async rendering features the React core team is working on. Hopefully they will be ready by the end of the year, but you can start playing with them today cloning my demos from Github.