-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Add a feature flag to disable legacy context #16269
Conversation
ReactDOM: size: 0.0%, gzip: 🔺+0.1% Details of bundled changes.Comparing: 4279455...892df46 react-dom
react-art
react-test-renderer
react-reconciler
react-native-renderer
Generated by 🚫 dangerJS |
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 does this.context
point to when the flag is on? Or the second argument to function components?
I think they should be undefined
, instead of an empty object — i.e. it should behave the same as if legacy context never existed, no vestiges.
instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext; | ||
instance.__reactInternalMemoizedMaskedChildContext = maskedContext; | ||
if (disableLegacyContext) { | ||
invariant( |
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.
Can we make these dev-only warnings instead? Once everyone removes legacy context from their apps, we can remove the warning in a minor, whereas removing an invariant is an according-to-semver-pedants breaking change.
Previously, classes that weren't context consumers would get |
- invariant -> warning - Make this.context and context argument actually undefined
Right, and then we don't have to do a second breaking change later |
We could still remove the feature but keep it forever |
@gaearon It's the second argument to functions that I care more about, personally. We might want to use that for something else. Don't really care about classes. What's a class? 🤷♀️ |
Adds a feature flag that disables the legacy context API. The feature flag is turned off in open source builds. Strict Mode is already a mechanism that warns about it, but this feature flag actually makes
this.context
always an empty object, andcontext
argument to functions alwaysundefined
. So it's a way to enforce it. If we later offer "modern" builds, we can turn it on there by default. For now, I want to use this internally for newly written code.No whitespace: https://github.com/facebook/react/compare/master...gaearon:ctx?expand=1&w=1