Forbid readContext() during render-phase class setState() reducer form#14670
Forbid readContext() during render-phase class setState() reducer form#14670gaearon wants to merge 2 commits intofacebook:masterfrom
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.
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.