-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
Describe the bug
In React, if setState
returns null
, cDU is not called and so following does not make infinite loop even after cDU is called. (You can check it on this codesandbox by typing text on the input. It prints only one console log at a time.)
export class TestComponent extends Component {
constructor(props) {
super(props);
this.state = {};
}
componentDidUpdate() {
this.setState(() => {
return null;
});
}
render() {
return null;
}
}
However, in enzyme
, when I update component, i.e., invoking cDU with above component, will gives me infinite loop like
at withSetStateAllowed (node_modules/enzyme/build/Utils.js:296:21)
at ShallowWrapper.<anonymous> (node_modules/enzyme/build/ShallowWrapper.js:511:42)
at ShallowWrapper.single (node_modules/enzyme/build/ShallowWrapper.js:1735:25)
at ShallowWrapper.setState (node_modules/enzyme/build/ShallowWrapper.js:510:14)
at TestComponent.ShallowWrapper.instance.setState (node_modules/enzyme/build/ShallowWrapper.js:190:35)
at TestComponent.setState [as componentDidUpdate] (TestComponent.js:11:10)
at node_modules/enzyme/build/ShallowWrapper.js:548:28
at withSetStateAllowed (node_modules/enzyme/build/Utils.js:300:3)
at ShallowWrapper.<anonymous> (node_modules/enzyme/build/ShallowWrapper.js:511:42)
at ShallowWrapper.single (node_modules/enzyme/build/ShallowWrapper.js:1735:25)
at ShallowWrapper.setState (node_modules/enzyme/build/ShallowWrapper.js:510:14)
at TestComponent.ShallowWrapper.instance.setState (node_modules/enzyme/build/ShallowWrapper.js:190:35)
at TestComponent.setState [as componentDidUpdate] (TestComponent.js:11:10)
at node_modules/enzyme/build/ShallowWrapper.js:548:28
// and repeat from line 1 to line 7
To Reproduce
git clone https://github.com/Ailrun/enzyme-issue1783
npm i
npm test
Expected behavior
Does not give infinite loop.
Desktop (please complete the following information):
- OS: Manjaro
- Browser: is not used
- Version: >=3.4.2, specifically, after Fix to call cDU when an instance calls setState #1742.