Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
444896e
Initial draft for 16.3 release blog
bvaughn Feb 5, 2018
141de66
Wording changes in response to PR feedback
bvaughn Feb 5, 2018
ce57928
Added entry for createRef API
bvaughn Feb 6, 2018
da29d89
Added note about string ref API to strict mode section
bvaughn Feb 6, 2018
a55480b
Small wording nit
bvaughn Feb 6, 2018
935d2a1
Minor edits in response to PR feedback
bvaughn Feb 6, 2018
ab62e88
Formatted example
bvaughn Feb 7, 2018
08d444e
Wordsmithing in response to PR feedback
bvaughn Feb 12, 2018
5a1d653
Incorporated Sophie's PR feedback
bvaughn Feb 13, 2018
8494428
Added example of before/after context API
bvaughn Feb 13, 2018
c08533a
Removed context-before example
bvaughn Feb 13, 2018
33ff167
Wordsmith nit
bvaughn Feb 13, 2018
c09a284
Added React.createRef doc
trueadm Feb 22, 2018
ee78358
address feedback
trueadm Feb 22, 2018
b049931
revised content as per PR feedback
trueadm Mar 4, 2018
9bc1932
updated line numbers
trueadm Mar 4, 2018
6627687
Describe what a ref is at the top of the doc
Mar 4, 2018
0e7243f
Merge intro paragraphs
Mar 4, 2018
c07a6b0
Merge pull request #1 from alexkrolick/create-ref-patch
trueadm Mar 4, 2018
7b02740
Create "Accessing refs" section above specific examples
Mar 4, 2018
d7b34d4
Merge pull request #2 from alexkrolick/create-ref-patch-2
trueadm Mar 4, 2018
8075ce2
Make the callback example more similar to the new API
Mar 4, 2018
96fe82c
Declare setRef method outside render
alexkrolick Mar 6, 2018
96b10a7
Grammar
alexkrolick Mar 6, 2018
962ef9a
Highlight deprecation notice
alexkrolick Mar 6, 2018
4b939d2
~~All things considered~~
alexkrolick Mar 6, 2018
04c7f16
Wording
alexkrolick Mar 6, 2018
b1adba0
Recommend old API when applicable
alexkrolick Mar 6, 2018
9b869fa
Update leading sentence
alexkrolick Mar 6, 2018
566406e
Add docs for new Context API (R16.3)
alexkrolick Mar 6, 2018
a89e6b8
Added link to context API docs
bvaughn Mar 6, 2018
5e0901d
Merge pull request #3 from alexkrolick/create-ref-patch-3
trueadm Mar 6, 2018
3f304b9
Merge pull request #4 from alexkrolick/create-ref-patch4
trueadm Mar 6, 2018
f6e5d65
Fixed off-by-one line highlights.
bvaughn Mar 7, 2018
6e35810
Merge branch 'master' into 16.3-release-blog-post
bvaughn Mar 7, 2018
6a1ba97
Moved 16.3 release date arbitrarily forward
bvaughn Mar 7, 2018
1de2e33
Fixed links
bvaughn Mar 7, 2018
c7a61e6
Imported StrictMode docs (and examples) from PR #596
bvaughn Mar 7, 2018
fecb153
Merge pull request #1 from trueadm/create-ref
bvaughn Mar 7, 2018
866ef01
Prettier
bvaughn Mar 7, 2018
12d7c16
Updated createRef 'value' attributes to 'current'
bvaughn Mar 14, 2018
e5bf594
Unnest callback ref example code
alexkrolick Mar 15, 2018
2f97f48
Fixed docs
bvaughn Mar 15, 2018
a357b64
Added React.forwardRef to 16.3 release blog post
bvaughn Mar 15, 2018
a937c46
Typo fixes
bvaughn Mar 15, 2018
201fcad
Added React.forwardRef to API and docs
bvaughn Mar 16, 2018
2b1de01
Rebuild Netlify
bvaughn Mar 16, 2018
22d0ec1
Updated forwardRef example to use named function
bvaughn Mar 16, 2018
fe033f6
Added StrictMode to docs sidenav
bvaughn Mar 16, 2018
f14f147
Renamed ref in example
bvaughn Mar 18, 2018
5d5a5d2
StrictMode title => Strict Mode
bvaughn Mar 19, 2018
2ead10e
Update nav
gaearon Mar 19, 2018
29d6592
Update React.Component reference to show deprecations and new lifecycles
bvaughn Mar 20, 2018
0780f72
Reorganize examples & legacy docs
alexkrolick Mar 21, 2018
a5022da
Add in-page TOC
alexkrolick Mar 21, 2018
fe3d0a4
Typo
alexkrolick Mar 21, 2018
808e5bd
Rephrase and reorganize
alexkrolick Mar 21, 2018
de22379
Syntax tweaks
alexkrolick Mar 21, 2018
291b2fd
Wording tweaks
alexkrolick Mar 21, 2018
6aa1995
Add solution to motivation problem
alexkrolick Mar 21, 2018
7c6688c
Highlight createContext()
alexkrolick Mar 21, 2018
b49f99b
Highlight whole createContext() call
alexkrolick Mar 21, 2018
dbce488
Merge pull request #3 from alexkrolick/new-context-api
bvaughn Mar 22, 2018
2f9b77a
16.4 -> 16.x
bvaughn Mar 22, 2018
e9ae68f
remove confusing {}
alexkrolick Mar 23, 2018
53d604f
~deprecated~ legacy
alexkrolick Mar 23, 2018
fec6d6c
Add mutliple contexts example
alexkrolick Mar 23, 2018
7b5764f
Add ref forwarding, lifecycle examples
alexkrolick Mar 23, 2018
0d32f18
Kill highlight
alexkrolick Mar 23, 2018
7db107b
+ "default value" comment
alexkrolick Mar 23, 2018
da091e6
Add note about how changes are determined
alexkrolick Mar 23, 2018
6eb29a1
Combine basic examples
alexkrolick Mar 23, 2018
9f54997
Update highlights
alexkrolick Mar 23, 2018
4e1282e
Add to "when to use context"
alexkrolick Mar 23, 2018
f588bd6
Update "legacy" wording
alexkrolick Mar 23, 2018
ccc1f26
Replace "deprecated" with "legacy" for now
alexkrolick Mar 23, 2018
3af89c9
Merge pull request #4 from alexkrolick/context-tweaks
bvaughn Mar 23, 2018
01c2691
Replaced cWRP in forwardRef example with cDU
bvaughn Mar 23, 2018
f5d5139
Formatted a Note
bvaughn Mar 23, 2018
5864093
Updated context-in-lifecycles example
bvaughn Mar 23, 2018
d66d3a2
Updated TODO for later
bvaughn Mar 23, 2018
ef23c49
Updated multi-context example to show more indirection
bvaughn Mar 23, 2018
b25276a
Updated forward-refs example to use class component
bvaughn Mar 23, 2018
c41bb29
Added DevTools name consideration to forwardRef examples
bvaughn Mar 23, 2018
1ead060
17 -> future version
alexkrolick Mar 23, 2018
d58c892
+ "same algo"
alexkrolick Mar 23, 2018
e689824
Add notes about composing multiple contexts
alexkrolick Mar 23, 2018
509b126
Explain context in lifecycle a bit more
alexkrolick Mar 23, 2018
fe84e09
Explain why you need forwardRef
alexkrolick Mar 23, 2018
9e4442a
typo
alexkrolick Mar 23, 2018
3c44882
Use function keyword
alexkrolick Mar 23, 2018
f9225e2
Remove propTypes
alexkrolick Mar 23, 2018
fb8e9e8
kill class props
alexkrolick Mar 23, 2018
6919801
Use functional component
alexkrolick Mar 23, 2018
c9d50e3
Remove lib link
alexkrolick Mar 23, 2018
7ac0712
Updated 16.3 blog post to account for getSnapshotBeforeUpdate lifecycle
bvaughn Mar 23, 2018
920b4f4
Replace divs with some fake components
alexkrolick Mar 23, 2018
349446d
Add caveats section
alexkrolick Mar 23, 2018
b0e8604
Prettier
alexkrolick Mar 23, 2018
8437e37
Fix syntax
alexkrolick Mar 23, 2018
587ad93
Merge pull request #5 from alexkrolick/16.3-release-blog-post
bvaughn Mar 23, 2018
f11a149
Added DevTools naming consideration to React.forwardRef reference doc…
bvaughn Mar 24, 2018
bd06bbc
Added context HOC example to reference
bvaughn Mar 24, 2018
b7b97c0
Merge branch 'master' into 16.3-release-blog-post
bvaughn Mar 27, 2018
6d77836
Linked to async blog post
bvaughn Mar 27, 2018
e5cf31a
Renamed blog post
bvaughn Mar 27, 2018
a29098e
Merge branch 'master' into 16.3-release-blog-post
bvaughn Mar 28, 2018
57eb7cc
Tweaked message about what goes into state
bvaughn Mar 29, 2018
28b2b76
Tweaked state-and-lifecycle wording more
bvaughn Mar 29, 2018
691cd45
Added inline child function caveat to Context docs
bvaughn Mar 29, 2018
032576c
Prettier
bvaughn Mar 29, 2018
797a792
Revert "Prettier"
bvaughn Mar 29, 2018
3a36a40
Revert "Added inline child function caveat to Context docs"
bvaughn Mar 29, 2018
e5ca13e
Cross-link to async update post
bvaughn Mar 29, 2018
992a756
Missing 'we'
bvaughn Mar 29, 2018
5a587d1
Tweaked link to Context API
bvaughn Mar 29, 2018
ac1d767
Fixed link
bvaughn Mar 29, 2018
aa9810f
Fixed some links and improved a recommendation
bvaughn Mar 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions content/blog/2018-02-07-react-v-16-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: "React v16.3.0: New lifecycles and context"
author: [bvaughn]
---

This release includes a new class component lifecycle (`getDerivedStateFromProps`), a new `StrictMode` component, an official context API, and a new ergonomic ref API!

For the past few months, the React team has been working on support for [asynchronous rendering](#). We are excited about the new features this will enable, and we've learned that some changes will be required to the way we write React components.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/some changes will be/some long-term changes will be/ maybe?


We're releasing version 16.3 primarily so that open source maintainers can start incorporating these changes into their libraries well in advance of the next major release. **However, you should not feel pressured to make changes to your application code yet.** We respect semver and will not ship breaking changes in a minor version!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly this paragraph right here reads to me as a little alarmist since you haven't even told me what you're changing. Can we move this down into the lifecycle section maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some reassurance that we won't break anything in a minor release belongs near the top, where people are most likely to see it.

Maybe I can shorten and soften the wording slightly to make it less alarmist?

Copy link
Contributor Author

@bvaughn bvaughn Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something more like this:


For the past few months, the React team has been working on support for asynchronous rendering. We are excited about the new features it will enable.

We’ve also learned that some long-term changes will be required to the way we write React components. However, we respect semver and will not ship breaking changes in a minor version!


Read on to learn more about the release.

## Official Context API

For many years, React has offered an experimental API for context. Although it was a powerful tool, our advice was mostly to [avoid using it](/docs/context.html#why-not-to-use-context) because of potential problems with the API. We've always intended to replace the experimental API with a better one, and as of version 16.3 the new API is available!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the why not context was actually focused on people using it as an alternative for props and it was discouraged because it can make code hard to follow, not because of its instability. Can we just say like "Although it was a powerful tool, its use was discouraged, in part because the API had inherent problems in its design from the start, and we always intended to replace the experimental API with a better one. In version 16.3, we're introducing a new context API that supports static type checking and deep updates as well as being more efficient."


> **Note**
>
> The old context API will keep working for all React 16 minor releases, so you will have time to migrate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"all React 16.x releases"? In case "minor" isn't universally clear.


[Learn more about the new context API here.](#)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/docs/context.html#api with #665

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Thanks~


## `createRef` API

Previously, React provided two ways for managing refs: the legacy string ref API and the callback API. Although the string ref API was the more convenient of the two, it had [several downsides](https://github.com/facebook/react/issues/1373) and so our official recomendation was to [use the callback form instead](https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs).

Version 16.3 adds a new option for managing refs that offers the convenience of a string ref without any of the downsides:
`embed:16-3-release-blog-create-ref.js`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still add

Callback refs will continue to be supported alongside this API for the foreseeable future. You don’t need to change the code using callback refs to the new API. Callback refs are slightly more flexible so they will stay as an advanced feature.

> **Note:**
>
> Callback refs will continue to be supported in addition to the new `createRef` API.
>
> You don't need to replace callback refs in your components. They are slightly more flexible, so they will remain as an advanced feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the upgrade path? Is there a codemod?

Copy link
Contributor Author

@bvaughn bvaughn Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No codemod. I proposed one initially, but a codemod couldn't properly handle this case:

class App extends React.Component {
  render() {
    return (
      <OtherComponent
        renderThing={() =>
          <div ref='refThatShouldBelongToOtherComponentInstance' />
        }
      />
    );
  }
}

I guess we could still write a codemod that bailed out on that case, but it didn't seem like there was a lot of support for one when I mentioned it during last week's sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I was unclear; I am very supportive of the codemod that handles simple cases correctly, as long as it's solid in the bailouts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't thinking of you specifically, just the general impression I got was a lack of interest.

I'm not necessarily volunteering to do it myself, but I'll add it to the quip as a non-16.3-release-blocking step. 😄

[Learn more about the new `createRef` API here.](#)

## Component Lifecycle Changes

React's class component API has been around for years with little change. However, as we add support for more advanced features (such as [error boundaries](/docs/react-component.html#componentdidcatch) and the upcoming [async rendering mode](#)) we stretch this model in ways that it was not originally intended.

For example, with the current API, it is too easy to block the initial render with non-essential logic. In part this is because there are too many ways to accomplish a given task, and it can be unclear which is best. We've observed that the interrupting behavior of error handling is often not taken into consideration and can result in memory leaks—(something that will also impact the upcoming async rendering mode). The current class component API also complicates other efforts, like our work on a React compiler.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove em dash

work on a React compiler -> "work on prototyping a React compiler"? don't want people to get hopes up too much. link it to https://twitter.com/trueadm/status/944908776896978946 too tho?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.


Many of these issues are exacerbated by a subset of the component lifecycles (`componentWillMount`, `componentWillReceiveProps`, and `componentWillUpdate`). These also happen to be the lifecycles that cause the most confusion within the React community. For these reasons, we are going to deprecate those methods in favor of better alternatives.

We recognize that this change will impact many existing components. (At Facebook, we maintain more than 50,000 React components, and we can't tell our engineers to rewrite them either.) Because of this, the migration path will be as gradual as possible, and will provide escape hatches.

> **Note:**
>
> Deprecation warnings will be enabled in version 16.4, **but the legacy lifecycles will continue to work until version 17**.
>
> After version 17, it will still be possible to use them, but they will be aliased with an "UNSAFE_" prefix to indicate that they might cause issues. We have also prepared an [automated script to rename them](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) in existing code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/After version 17/Even in version 17/


We are also adding a new static lifecycle, `getDerivedStateFromProps`, as a safer alternative to the legacy `componentWillReceiveProps`.

[Learn more about these lifecycle changes here.](#)

## `StrictMode` Component

`StrictMode` is a tool for highlighting potential problems in an application. Like `Fragment`, `StrictMode` does not render any visible UI. It simply activates additional checks and warnings for its descendants.

> **Note:**
>
> `StrictMode` checks are run in development mode only; they do not impact the production build.

Although it is not possible for strict mode to catch all problems (e.g. certain types of mutation), it can help with many. If you see warnings in strict mode, those things will likely cause bugs for async rendering.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mentioning "mutation" as a problem is going to seriously worry MobX users. What is our messaging here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. I can soften this? ("certain types of mutations")

In version 16.3, `StrictMode` helps with:
* Identifying components with unsafe lifecycles
* Warning about legacy string ref API usage
* Detecting unexpected side effects

Additional functionality will be added with future releases of React.

[Learn more about the `StrictMode` component here.](#)
14 changes: 14 additions & 0 deletions examples/16-3-release-blog-create-ref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class MyComponent extends React.Component {
// highlight-next-line
divRef = React.createRef();

render() {
// highlight-next-line
return <input type="text" ref={this.divRef} />;
}

componentDidMount() {
// highlight-next-line
this.divRef.value.focus();
}
}