-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Warn for Context.Consumer with contextType #14831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if (contextType.$$typeof !== REACT_CONTEXT_TYPE) { | ||
| const isContextConsumer = | ||
| contextType.$$typeof === REACT_CONTEXT_TYPE && | ||
| contextType._context !== undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it also called context in some patch release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| if (__DEV__) { | ||
| const isContextConsumer = | ||
| contextType.$$typeof === REACT_CONTEXT_TYPE && | ||
| contextType._context !== undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if context value actually is undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the context value tracked as _currentValue on this _context element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right.
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.