Skip to content

Commit 1b5c6d3

Browse files
Sunil Paigaearon
andauthored
Blog post for v16.13.0 (#2779)
* Blogpost for v16.13.0 * Tweak * Update 2020-03-02-react-v16.13.0.md * update react/react-dom versions Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
1 parent bba6229 commit 1b5c6d3

File tree

8 files changed

+229
-16
lines changed

8 files changed

+229
-16
lines changed

content/authors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ steveluscher:
7676
tesseralis:
7777
name: Nat Alison
7878
url: https://twitter.com/tesseralis
79+
threepointone:
80+
name: Sunil Pai
81+
url: https://twitter.com/threepointone
7982
timer:
8083
name: Joe Haddad
8184
url: https://twitter.com/timer150
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
title: "React v16.13.0"
3+
author: [threepointone]
4+
---
5+
6+
Today we are releasing React 16.13.0. It contains bugfixes and new deprecation warnings to help prepare for a future major release.
7+
8+
## New Warnings {#new-warnings}
9+
10+
### Warnings for some updates during render {#warnings-for-some-updates-during-render}
11+
12+
A React component should not cause side effects in other components during rendering.
13+
14+
It is supported to call `setState` during render, but [only for *the same component*](/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops). If you call `setState` during a render on a different component, you will now see a warning:
15+
16+
```
17+
Warning: Cannot update a component from inside the function body of a different component.
18+
```
19+
20+
**This warning will help you find application bugs caused by unintentional state changes.** In the rare case that you intentionally want to change the state of another component as a result of rendering, you can wrap the `setState` call into `useEffect`.
21+
22+
### Warnings for conflicting style rules
23+
24+
When dynamically applying a `style` that contains longhand and shorthand versions of CSS properties, particular combinations of updates can cause inconsistent styling. For example:
25+
26+
```js
27+
<div style={toggle ?
28+
{ background: 'blue', backgroundColor: 'red' } :
29+
{ backgroundColor: 'red' }
30+
}>
31+
...
32+
</div>
33+
```
34+
35+
You might expect this `<div>` to always have a red background, no matter the value of `toggle`. However, on alternating the value of `toggle` between `true` and `false`, the background color start as `red`, then alternates between `transparent` and `blue`, [as you can see in this demo](https://codesandbox.io/s/suspicious-sunset-g3jub).
36+
37+
**React now detects conflicting style rules and logs a warning.** To fix the issue, don't mix shorthand and longhand versions of the same CSS property in the `style` prop.
38+
39+
### Warnings for some deprecated string refs {#warnings-for-some-deprecated-string-refs}
40+
41+
[String Refs is an old legacy API](/docs/refs-and-the-dom.html#legacy-api-string-refs) which is discouraged and is going to be deprecated in the future:
42+
43+
```js
44+
<Button ref="myRef" />
45+
```
46+
47+
(Don't confuse String Refs with refs in general, which **remain fully supported**.)
48+
49+
In the future, we will provide an automated script (a "codemod") to migrate away from String Refs. However, some rare cases can't be migrated automatically. This release adds a new warning **only for those cases** in advance of the deprecation.
50+
51+
For example, it will fire if you use String Refs together with the Render Prop pattern:
52+
53+
```jsx
54+
class ClassWithRenderProp extends React.Component {
55+
componentDidMount() {
56+
doSomething(this.refs.myRef);
57+
}
58+
render() {
59+
return this.props.children();
60+
}
61+
}
62+
63+
class ClassParent extends React.Component {
64+
render() {
65+
return (
66+
<ClassWithRenderProp>
67+
{() => <Button ref="myRef" />}
68+
</ClassWithRenderProp>
69+
);
70+
}
71+
}
72+
```
73+
74+
Code like this often indicates bugs. (You might expect the ref to be available on `ClassParent`, but instead it gets placed on `ClassWithRenderProp`).
75+
76+
**You most likely don't have code like this**. If you do and it is intentional, convert it to [`React.createRef()`](/docs/refs-and-the-dom.html#creating-refs) instead:
77+
78+
```jsx
79+
class ClassWithRenderProp extends React.Component {
80+
myRef = React.createRef();
81+
componentDidMount() {
82+
doSomething(this.myRef.current);
83+
}
84+
render() {
85+
return this.props.children(this.myRef);
86+
}
87+
}
88+
89+
class ClassParent extends React.Component {
90+
render() {
91+
return (
92+
<ClassWithRenderProp>
93+
{myRef => <Button ref={myRef} />}
94+
</ClassWithRenderProp>
95+
);
96+
}
97+
}
98+
```
99+
100+
> Note
101+
>
102+
> To see this warning, you need to have the [babel-plugin-transform-react-jsx-self](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx-self) installed in your Babel plugins. It must _only_ be enabled in development mode.
103+
>
104+
> If you use Create React App or have the "react" preset with Babel 6+, you already have this plugin installed by default.
105+
106+
### Deprecating `React.createFactory` {#deprecating-reactcreatefactory}
107+
108+
[`React.createFactory`](/docs/react-api.html#createfactory) is a legacy helper for creating React elements. This release adds a deprecation warning to the method. It will be removed in a future major version.
109+
110+
Replace usages of `React.createFactory` with regular JSX. Alternately, you can copy and paste this one-line helper or publish it as a library:
111+
112+
```jsx
113+
let createFactory = type => React.createElement.bind(null, type);
114+
```
115+
116+
It does exactly the same thing.
117+
118+
### Deprecating `ReactDOM.unstable_createPortal` in favor of `ReactDOM.createPortal` {#deprecating-reactdomunstable_createportal-in-favor-of-reactdomcreateportal}
119+
120+
When React 16 was released, `createPortal` became an officially supported API.
121+
122+
However, we kept `unstable_createPortal` as a supported alias to keep the few libraries that adopted it working. We are now deprecating the unstable alias. Use `createPortal` directly instead of `unstable_createPortal`. It has exactly the same signature.
123+
124+
## Other Improvements {#other-improvements}
125+
126+
### Component stacks in hydration warnings {#component-stacks-in-hydration-warnings}
127+
128+
React adds component stacks to its development warnings, enabling developers to isolate bugs and debug their programs. This release adds component stacks to a number of development warnings that didn't previously have them. As an example, consider this hydration warning from the previous versions:
129+
130+
![A screenshot of the console warning, simply stating the nature of the hydration mismatch: "Warning: Expected server HTML to contain a matching div in div."](../images/blog/react-v16.13.0/hydration-warning-before.png)
131+
132+
While it's pointing out an error with the code, it's not clear where the error exists, and what to do next. This release adds a component stack to this warning, which makes it look like this:
133+
134+
![A screenshot of the console warning, stating the nature of the hydration mismatch, but also including a component stack : "Warning: Expected server HTML to contain a matching div in div, in div (at pages/index.js:4)..."](../images/blog/react-v16.13.0/hydration-warning-after.png)
135+
136+
This makes it clear where the problem is, and lets you locate and fix the bug faster.
137+
138+
### Notable bugfixes {#notable-bugfixes}
139+
140+
This release contains a few other notable improvements:
141+
142+
- In Strict Development Mode, React calls lifecycle methods twice to flush out any possible unwanted side effects. This release adds that behaviour to `shouldComponentUpdate`. This shouldn't affect most code, unless you have side effects in `shouldComponentUpdate`. To fix this, move the code with side effects into `componentDidUpdate`.
143+
144+
- In Strict Development Mode, the warnings for usage of the legacy context API didn't include the stack for the component that triggered the warning. This release adds the missing stack to the warning.
145+
146+
- `onMouseEnter` now doesn't trigger on disabled `<button>` elements.
147+
148+
- ReactDOM was missing a `version` export since we published v16. This release adds it back. We don't recommend using it in your application logic, but it's useful when debugging issues with mismatching / multiple versions of ReactDOM on the same page.
149+
150+
We’re thankful to all the contributors who helped surface and fix these and other issues. You can find the full changelog [below](#changelog).
151+
152+
## Installation {#installation}
153+
154+
### React {#react}
155+
156+
React v16.13.0 is available on the npm registry.
157+
158+
To install React 16 with Yarn, run:
159+
160+
```bash
161+
yarn add react@^16.13.0 react-dom@^16.13.0
162+
```
163+
164+
To install React 16 with npm, run:
165+
166+
```bash
167+
npm install --save react@^16.13.0 react-dom@^16.13.0
168+
```
169+
170+
We also provide UMD builds of React via a CDN:
171+
172+
```html
173+
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
174+
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
175+
```
176+
177+
Refer to the documentation for [detailed installation instructions](/docs/installation.html).
178+
179+
## Changelog {#changelog}
180+
181+
### React {#react}
182+
183+
- Warn when a string ref is used in a manner that's not amenable to a future codemod ([@lunaruan](https://github.com/lunaruan) in [#17864](https://github.com/facebook/react/pull/17864))
184+
- Deprecate `React.createFactory()` ([@trueadm](https://github.com/trueadm) in [#17878](https://github.com/facebook/react/pull/17878))
185+
186+
### React DOM {#react-dom}
187+
188+
- Warn when changes in `style` may cause an unexpected collision ([@sophiebits](https://github.com/sophiebits) in [#14181](https://github.com/facebook/react/pull/14181), [#18002](https://github.com/facebook/react/pull/18002))
189+
- Warn when a function component is updated during another component's render phase ([@acdlite](<(https://github.com/acdlite)>) in [#17099](https://github.com/facebook/react/pull/17099))
190+
- Deprecate `unstable_createPortal` ([@trueadm](https://github.com/trueadm) in [#17880](https://github.com/facebook/react/pull/17880))
191+
- Flush all passive effect (`useEffect`) destroy functions before calling subsequent create functions ([@bvaughn](https://github.com/bvaughn) in [#17925](https://github.com/facebook/react/pull/17925), [#17947](https://github.com/facebook/react/pull/17947))
192+
- Fix `onMouseEnter` being fired on disabled buttons ([@AlfredoGJ](https://github.com/AlfredoGJ) in [#17675](https://github.com/facebook/react/pull/17675))
193+
- Call `shouldComponentUpdate` twice when developing in `StrictMode` ([@bvaughn](https://github.com/bvaughn) in [#17942](https://github.com/facebook/react/pull/17942))
194+
- Add `version` property to ReactDOM ([@ealush](https://github.com/ealush) in [#15780](https://github.com/facebook/react/pull/15780))
195+
- Don't call `toString()` of `dangerouslySetInnerHTML` ([@sebmarkbage](https://github.com/sebmarkbage) in [#17773](https://github.com/facebook/react/pull/17773))
196+
- Show component stacks in more warnings ([@gaearon](https://github.com/gaearon) in [#17922](https://github.com/facebook/react/pull/17922), [#17586](https://github.com/facebook/react/pull/17586))
197+
198+
### Concurrent Mode (Experimental) {#concurrent-mode-experimental}
199+
200+
- Warn for problematic usages of `ReactDOM.createRoot()` ([@trueadm](https://github.com/trueadm) in [#17937](https://github.com/facebook/react/pull/17937))
201+
- Remove `ReactDOM.createRoot()` callback params and added warnings on usage ([@bvaughn](https://github.com/bvaughn) in [#17916](https://github.com/facebook/react/pull/17916))
202+
- Don't group Idle/Offscreen work with other work ([@sebmarkbage](https://github.com/sebmarkbage) in [#17456](https://github.com/facebook/react/pull/17456))
203+
- Adjust `SuspenseList` CPU bound heuristic ([@sebmarkbage](https://github.com/sebmarkbage) in [#17455](https://github.com/facebook/react/pull/17455))
204+
- Add missing event plugin priorities ([@trueadm](https://github.com/trueadm) in [#17914](https://github.com/facebook/react/pull/17914))
205+
- Fix `isPending` only being true when transitioning from inside an input event ([@acdlite](https://github.com/acdlite) in [#17382](https://github.com/facebook/react/pull/17382))
206+
- Fix `React.memo` components dropping updates when interrupted by a higher priority update ([@acdlite](<(https://github.com/acdlite)>) in [#18091](https://github.com/facebook/react/pull/18091))
207+
- Don't warn when suspending at the wrong priority ([@gaearon](https://github.com/gaearon) in [#17971](https://github.com/facebook/react/pull/17971))
208+
- Fix a bug with rebasing updates ([@acdlite](https://github.com/acdlite) and [@sebmarkbage](https://github.com/sebmarkbage) in [#17560](https://github.com/facebook/react/pull/17560), [#17510](https://github.com/facebook/react/pull/17510), [#17483](https://github.com/facebook/react/pull/17483), [#17480](https://github.com/facebook/react/pull/17480))
Loading
Loading

content/versions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- title: '16.13.0'
2+
changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#16130-march-2-2020
13
- title: '16.12.0'
24
changelog: https://github.com/facebook/react/blob/master/CHANGELOG.md#16120-november-14-2019
35
- title: '16.11'

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
"normalize.css": "^8.0.0",
4848
"prettier": "^1.7.4",
4949
"prismjs": "^1.15.0",
50-
"react": "^16.12.0",
51-
"react-dom": "^16.12.0",
50+
"react": "^16.13.0",
51+
"react-dom": "^16.13.0",
5252
"react-helmet": "^5.2.0",
5353
"react-live": "1.8.0-0",
5454
"remarkable": "^1.7.1",

src/site-constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// NOTE: We can't just use `location.toString()` because when we are rendering
99
// the SSR part in node.js we won't have a proper location.
1010
const urlRoot = 'https://reactjs.org';
11-
const version = '16.12.0';
11+
const version = '16.13.0';
1212
const babelURL = 'https://unpkg.com/babel-standalone@6.26.0/babel.min.js';
1313

1414
export {babelURL, urlRoot, version};

yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10241,15 +10241,15 @@ react-dev-utils@^4.2.1:
1024110241
strip-ansi "3.0.1"
1024210242
text-table "0.2.0"
1024310243

10244-
react-dom@^16.12.0:
10245-
version "16.12.0"
10246-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.12.0.tgz#0da4b714b8d13c2038c9396b54a92baea633fe11"
10247-
integrity sha512-LMxFfAGrcS3kETtQaCkTKjMiifahaMySFDn71fZUNpPHZQEzmk/GiAeIT8JSOrHB23fnuCOMruL2a8NYlw+8Gw==
10244+
react-dom@^16.13.0:
10245+
version "16.13.0"
10246+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.0.tgz#cdde54b48eb9e8a0ca1b3dc9943d9bb409b81866"
10247+
integrity sha512-y09d2c4cG220DzdlFkPTnVvGTszVvNpC73v+AaLGLHbkpy3SSgvYq8x0rNwPJ/Rk/CicTNgk0hbHNw1gMEZAXg==
1024810248
dependencies:
1024910249
loose-envify "^1.1.0"
1025010250
object-assign "^4.1.1"
1025110251
prop-types "^15.6.2"
10252-
scheduler "^0.18.0"
10252+
scheduler "^0.19.0"
1025310253

1025410254
react-error-overlay@^3.0.0:
1025510255
version "3.0.0"
@@ -10303,10 +10303,10 @@ react-side-effect@^1.1.0:
1030310303
exenv "^1.2.1"
1030410304
shallowequal "^1.0.1"
1030510305

10306-
react@^16.12.0:
10307-
version "16.12.0"
10308-
resolved "https://registry.yarnpkg.com/react/-/react-16.12.0.tgz#0c0a9c6a142429e3614834d5a778e18aa78a0b83"
10309-
integrity sha512-fglqy3k5E+81pA8s+7K0/T3DBCF0ZDOher1elBFzF7O6arXJgzyu/FW+COxFvAWXJoJN9KIZbT2LXlukwphYTA==
10306+
react@^16.13.0:
10307+
version "16.13.0"
10308+
resolved "https://registry.yarnpkg.com/react/-/react-16.13.0.tgz#d046eabcdf64e457bbeed1e792e235e1b9934cf7"
10309+
integrity sha512-TSavZz2iSLkq5/oiE7gnFzmURKZMltmi193rm5HEoUDAXpzT9Kzw6oNZnGoai/4+fUnm7FqS5dwgUL34TujcWQ==
1031010310
dependencies:
1031110311
loose-envify "^1.1.0"
1031210312
object-assign "^4.1.1"
@@ -11019,10 +11019,10 @@ sax@>=0.6.0, sax@^1.2.4, sax@~1.2.1, sax@~1.2.4:
1101911019
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
1102011020
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
1102111021

11022-
scheduler@^0.18.0:
11023-
version "0.18.0"
11024-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.18.0.tgz#5901ad6659bc1d8f3fdaf36eb7a67b0d6746b1c4"
11025-
integrity sha512-agTSHR1Nbfi6ulI0kYNK0203joW2Y5W4po4l+v03tOoiJKpTBbxpNhWDvqc/4IcOw+KLmSiQLTasZ4cab2/UWQ==
11022+
scheduler@^0.19.0:
11023+
version "0.19.0"
11024+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.0.tgz#a715d56302de403df742f4a9be11975b32f5698d"
11025+
integrity sha512-xowbVaTPe9r7y7RUejcK73/j8tt2jfiyTednOvHbA8JoClvMYCp+r8QegLwK/n8zWQAtZb1fFnER4XLBZXrCxA==
1102611026
dependencies:
1102711027
loose-envify "^1.1.0"
1102811028
object-assign "^4.1.1"

0 commit comments

Comments
 (0)