Warn for Context.Consumer with contextType#14831
Merged
gaearon merged 1 commit intofacebook:masterfrom Mar 18, 2019
Merged
Conversation
gaearon
reviewed
Feb 12, 2019
| if (contextType.$$typeof !== REACT_CONTEXT_TYPE) { | ||
| const isContextConsumer = | ||
| contextType.$$typeof === REACT_CONTEXT_TYPE && | ||
| contextType._context !== undefined; |
Collaborator
There was a problem hiding this comment.
Was it also called context in some patch release?
Contributor
Author
There was a problem hiding this comment.
Yeah, it was changed to _context in #12501. Is it worth checking? I think a lot more would be broken if you were trying to render a tree created with a version of React that still used context since we don't check for it in the context code paths.
matthargett
approved these changes
Feb 13, 2019
gaearon
reviewed
Mar 18, 2019
| if (__DEV__) { | ||
| const isContextConsumer = | ||
| contextType.$$typeof === REACT_CONTEXT_TYPE && | ||
| contextType._context !== undefined; |
Collaborator
There was a problem hiding this comment.
What if context value actually is undefined?
Contributor
Author
There was a problem hiding this comment.
Isn't the context value tracked as _currentValue on this _context element?
gaearon
approved these changes
Mar 18, 2019
gaearon
pushed a commit
to gaearon/react
that referenced
this pull request
Mar 27, 2019
Closed
This was referenced Aug 12, 2019
This was referenced Feb 4, 2020
This was referenced Feb 17, 2020
This was referenced Feb 25, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14793
Extends the
contextTypewarning to includeContext.Consumer. For both theReactDOMandReactDomServer.Since
$$typeofalone can't be used to distinguish consumers from context objects, the heuristic I used to identify context consumers was to check for the_contextproperty which doesn't exist on the context object itself.