firefox-devtools / rfcs

RFCs for changes to DevTools
15 stars 17 forks source link

Upgrading React to v16.8.6 #62

Closed MikeRatcliffe closed 5 years ago

MikeRatcliffe commented 5 years ago

Description

Over the last few days I have taken the time to look into a React upgrade from v16.4.1 to v16.8.6.

If we upgrade before the 17 release we should be in a better place to upgrade to 17 when it comes... of course they aim for no breaking changes but history has shown us that this isn't always possible.

What do y'all think? The upgrade should be completed within a few hours because I don't believe we will need to change anything in any of our components.

React 16.6 introduced React.lazy() for lazy loading components and React.Suspense() that can be used to temporarily display something until a component renders (skeleton screens). They could make a real impact on our real and perceived performance... especially when used with React DevTool's new Profiler tab (see item 2 below).

Of course there are more goodies

  1. React.memo() can be used to wrap functional components so that they act as PureComponents.
  2. React DevTools now has a profiler tab: See https://www.netlify.com/blog/2018/08/29/using-the-react-devtools-profiler-to-diagnose-react-app-performance-issues/.
  3. React hooks for functional components. There is also eslint-plugin-react-hooks to ensure they are used properly:

    • React.useState() - Instead of just letting you use state inside functional components useState() allows you to have multiple states:
    function example() {
    const [age, setAge] = useState(42);
    const [features, setFeatures] = useState({
      wrinkles: 110,
      ears: "large",
    });
    ...
    setAge(43);
    setFeatures({
      wrinkles: 510,
      ears: "extra-large",
    });
    ...
    return (
      <div>
        DOM stuff
      </div>
    )
    }
    • useEffect() The equivalent of componentDidMount, componentDidUpdate, and componentWillUnmount depending on how you use it.
    • useContext() allows a functional component to subscribe to React context.
    • useReducer() lets you manage local state of complex components with a reducer.
    • There is also useCallback(), useMemo(), useRef(), useImperativeHandle(), useLayoutEffect() and useDebugValue() but you get the gist.

Unsurprisingly there are a huge list of bug fixes and performance improvements

We will get 2 new lifecycle methods:

Deprecated / renamed

The deprecated methods go away in 17.0 (UNSAFE_ methods stay) so we should add the UNSAFE_ prefix to those we currently use Bug 1508688.

React: What changed between 16.4.1 and 16.8.6?

React DOM

React DOM Server

React Test Renderer and Test Utils

React Shallow Renderer

React ART

Scheduler (Experimental)

React Test Renderer and Test Utils

ESLint Plugin: React Hooks

juliandescottes commented 5 years ago

Looks like there are no breaking change with this upgrade. If try and DAMP are happy with this (and if you have time to work on it :) ), it sounds like a good thing to do.

MikeRatcliffe commented 5 years ago

This is now implemented, closing.