Fix to skip updates when nextState is null or undefined#1785
Fix to skip updates when nextState is null or undefined#1785ljharb merged 2 commits intoenzymejs:masterfrom
Conversation
ljharb
left a comment
There was a problem hiding this comment.
Thanks, this looks great! Just two small tweaks (I'm happy to take care of it before merging)
| } | ||
|
|
||
| const wrapper = mount(<Foo />); | ||
| const spy = sinon.spy(wrapper.instance(), 'componentDidUpdate'); |
There was a problem hiding this comment.
i think we can check both null and undefined here by spying on componentDidUpdate?
| const prevContext = instance.context; | ||
|
|
||
| if (typeof state === 'function') { | ||
| state = state.call(instance, prevState, prevProps); |
There was a problem hiding this comment.
i'll tweak this to avoid reassignment
|
Travis is failed. |
b048ce3 to
6b51df7
Compare
|
@koba04 meaning, prior to react 16, it's an infinite loop? |
|
@ljharb Yeah, prior to react 16, This seems to cause an infinite loop. |
|
Sounds good, I'll finish this one up real quick. |
|
(I don't think an adapter flag is needed; the test just needs to run only in react 16+) |
|
It might be relevant to the test, not the patch itself. |
6b51df7 to
cba495f
Compare
|
actually i changed my mind; this should be in the adapter, so that react versions < 16 always get the infinite loop, even shallow-rendering when setState returns nullish. |
…h when adapters opt in.
|
I missed so many details in my issue... 😞 Thank you for noticing the version issue and fixing it too! You guys are really wonderfully awesome! |
- [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [New] Add `displayNameOfNode`, `isValidElementType` (#1701, @jquense) - [New] pass the adapter into `createMountWrapper` (#1592, @jquense) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - update deps - [meta] ensure a license and readme is present in all packages when published
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [New] Add `displayNameOfNode`, `isValidElementType` (#1701, @jquense) - [New] pass the adapter into `createMountWrapper` (#1592, @jquense) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - update deps - [meta] ensure a license and readme is present in all packages when published
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: prevent rerenders with PureComponents (#1786, @koba04) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - [Fix] `shallow`: `setState` after `setProps` calls `componentWillReceiveProps` (#1779, @peanutenthusiast) - [Fix] `mount`/`shallow`: be stricter on the wrapper’s setState/setProps callback - [Fix] `shallow`/`mount`: improve error message when wrapping invalid elements (#1759, @jgzuke) - update deps - [Refactor] remove most uses of lodash - [meta] ensure a license and readme is present in all packages when published
Fix #1783
This PR makes to prevent updates when setState returns
nullorundefined.But the callback of setState's 2nd arguments should always be called as well as a behavior of ReactDOM.