-
Notifications
You must be signed in to change notification settings - Fork 46.5k
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
Forbid readContext() during render-phase class setState() reducer form #14670
Conversation
expect(ReactNoop.flush).toThrow( | ||
'Context can only be read while React is rendering', | ||
), | ||
).toWarnDev('Cannot update during an existing state transition', { |
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.
We warn anyway so maybe it isn't worth it?
The reason to do this is because the semantics are currently undefined — what happens when context changes? Re-rendering will have no effect because the update already happened — and we want to preserve option value to possibly support it properly in the future. Like for code splitting reducers. Same reason we warn about reading context inside Hook reducer.
|
ReactDOM: size: 0.0%, gzip: 🔺+0.2% Details of bundled changes.Comparing: f0befae...d0fabf1 react-dom
react-art
react-native-renderer
react-test-renderer
react-reconciler
Generated by 🚫 dangerJS |
That's true but we already unconditionally warn for render phase I guess we probably mute that warning at FB though? |
Added a comment that I don’t think we should do this in prod. |
Yeah warning is sufficient |
Do we need an extra warning for this specifically? This test already warns with "Cannot update during an existing state transition". |
b555c33
to
d0fabf1
Compare
I made this depend on #14672 and added a similar DEV-only warning on top. |
It's annoying to have so many small ones. I'll send a combined one. |
Superseded by #14677 |
Depends on #14672
Addresses #14653 (comment) (I think?)
Not sure we want to actually do it but figured I'd send a PR.