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
React.memo() can be used to wrap functional components so that they act as PureComponents.
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.
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 andReact.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 newProfiler
tab (see item 2 below).Of course there are more goodies
React.memo()
can be used to wrap functional components so that they act as PureComponents.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 componentsuseState()
allows you to have multiple states:useEffect()
The equivalent ofcomponentDidMount
,componentDidUpdate
, andcomponentWillUnmount
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.useCallback()
,useMemo()
,useRef()
,useImperativeHandle()
,useLayoutEffect()
anduseDebugValue()
but you get the gist.Unsurprisingly there are a huge list of bug fixes and performance improvements
We will get 2 new lifecycle methods:
getDerivedStateFromProps()
getSnapshotBeforeUpdate()
Deprecated / renamed
UNSAFE_componentWillMount
- Use theconstructor()
insteadUNSAFE_componentWillReceiveProps
- Usestatic getDerivedStateFromProps()
insteadUNSAFE_componentWillUpdate
- UsegetDerivedStateFromProps()
The deprecated methods go away in 17.0 (
UNSAFE_
methods stay) so we should add theUNSAFE_
prefix to those we currently use Bug 1508688.React: What changed between 16.4.1 and 16.8.6?
React.forwardRef()
render function doesn't take exactly two argumentscreateElement()
by mistakeonRender()
until after mutationsReact.forwardRef()
receives an unexpected number of arguments.React.memo()
as an alternative toPureComponent
for functions.React.lazy()
for code splitting components.React.StrictMode
now warns about legacy context API.React.StrictMode
now warns aboutfindDOMNode()
.unstable_AsyncMode
tounstable_ConcurrentMode
.unstable_Placeholder
toSuspense
, anddelayMs
tomaxDuration
.useReducer()
Hook lazy initialization API.React DOM
react-dom/profiling
entry point alias for profiling in productiononAuxClick
event for browsers that support itmovementX
andmovementY
fields to mouse eventstangentialPressure()
and twist fields to pointer eventsfocusable
SVG attribute<noscript>
on the client when hydratinggridArea
to be treated as a unitless CSS property<option>
tagchecked
attribute not getting initially set on theinput
dangerouslySetInnerHTML()
when__html
is not a stringonChange
to fire on falsy values tooonSelect
event not being triggered after drag and droponClick
event not working inside a portal on iOS"false"
or"true"
is the value of a boolean DOM propthis.state
is initialized to propswindow.event
in IEfolder/index.js
naming conventiongetDerivedStateFromProps()
without initialized statetextarea
usage<webview>
tag without warningse.preventDefault()
was calledunstable_deferredUpdates
in favor ofunstable_scheduleWork
from scheduleisReactComponent()
.<iframe>
regression<textarea>
s no longer re-render when data is unchangedcontextType()
as a more ergonomic way to subscribe to context from a class.getDerivedStateFromError()
lifecycle method for catching errors in a future asynchronous server-side renderer.<Context>
is used instead of<Context.Consumer>
.window.event
in development.Suspense
keeps showing fallback even after everything finishes loading.Suspense
finishes loading in IE11.Suspense
andlazy
.React.memo
updates inReact DevTools
.Suspense
with theReact Profiler
.Suspense
.React.lazy
for large numbers of lazily-loaded components.react-dom/server@16.6
andreact@<16.6
.useState
anduseReducer
Hooks.Object.is
algorithm for comparinguseState
anduseReducer
values.useEffect
/useMemo
/useCallback
Hooks.React.lazy()
.undefined
or afunction
. All other values, includingnull
, are not allowed.ReactDOM.render
being ignored inside useEffect.useImperativeHandle
to work correctly when no deps are specified.crossOrigin
attribute to work in SVG image elements.Suspense
with Hooks.DevTools
caused a runtime error when inspecting a component that used auseContext
hook.useEffect(async () => ...)
warning message.useReducer()
.contextType
is set toContext.Consumer
instead ofContext
.contextType
is set to invalid values.React DOM Server
hasOwnProperty
. This fix is only available in react-dom@16.4.2.<option>
setTimeout
is missingReact.memo()
.contextType
.renderToNodeStream()
calls.useLayoutEffect
warning message when server rendering.React Test Renderer and Test Utils
ReactTestUtils.mockComponent()
helperReactDOM.createPortal
usage within the test rendererReact Shallow Renderer
setState
in shallow renderer to work with Hooks.React.memo
.forwardRef
.React ART
DevTools
Scheduler (Experimental)
schedule/tracking-profiling
.setTimeout
in testing environments.React Test Renderer and Test Utils
shouldComponentUpdate
in the presence ofgetDerivedStateFromProps
for Shallow Renderer.ReactTestRenderer.act()
andReactTestUtils.act()
for batching updates so that tests more closely match real behavior.act()
warning.ESLint Plugin: React Hooks