Infinite loop (Maximum call stack size exceeded) when passing redux form as a prop
See original GitHub issueEDIT:
Apparently it only happens when the component where the form is being rendered is connected to the redux store and one of the properties is being enhanced on the mapStateToProps function, for example:
const mapStateToProps = state => ({
// This causes the error
clicks: { enhanced: true, count: state.clicks.count },
// This works
// clicks: state.clicks
});
Passing a redux form component as a prop to another component is causing an infinite loop. This only happens if you pass it using an anonymous function (functional component).
Here is an example:
const NewMessageForm = reduxForm({
form: 'newMessageForm'
})(({ handleSubmit }) => (
<Form onSubmit={handleSubmit}>
<Field
name="text"
component="input"
placeholder="Add your message here"
/>
</Form>
));
function Wrapper({ newMessageForm: NewMessageForm }) {
return (
<div className="wrapper">
<NewMessageForm />
</div>
);
}
function handleSubmit(values) {
console.log('submit', values);
}
function Counter () {
return (
<div>
<h1>Hello World!</h1>
// Here is where the problem happens
<Wrapper newMessageForm={() => <NewMessageForm onSubmit={handleSubmit} /> }/>
</div>
);
}
This error doesn’t happen if the component is passed like this:
<Wrapper newMessageForm={NewMessageForm}/>
or even like this:
constructor(props) {
super(props)
this.NewMessageForm = () => <NewMessageForm onSubmit={handleSubmit} />
}
render() {
.....
<Wrapper newMessageForm={this.NewMessageForm}/>
.....
}
I have an example here
What’s your environment?
Tested on chrome using redux-form@6.5.0
Other informations
Stack Trace:
Uncaught RangeError: Maximum call stack size exceeded
at traverseAllChildrenImpl (traverseAllChildren.js:65)
at traverseAllChildrenImpl (traverseAllChildren.js:93)
at traverseAllChildren (traverseAllChildren.js:172)
at flattenChildren (flattenChildren.js:66)
at ReactDOMComponent._reconcilerUpdateChildren (ReactMultiChild.js:204)
at ReactDOMComponent._updateChildren (ReactMultiChild.js:312)
at ReactDOMComponent.updateChildren (ReactMultiChild.js:299)
at ReactDOMComponent._updateDOMChildren (ReactDOMComponent.js:936)
at ReactDOMComponent.updateComponent (ReactDOMComponent.js:754)
at ReactDOMComponent.receiveComponent (ReactDOMComponent.js:716)
I’ve tried to reproduce this bug in an unit test but, as for today, I wasn’t able to.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:56
- Comments:40 (4 by maintainers)
Top Results From Across the Web
Developers - Infinite loop (Maximum call stack size exceeded ...
Infinite loop (Maximum call stack size exceeded) when passing redux form as a prop.
Read more >React-Redux Maximum call stack size exceeded when adding ...
I am creating a simple game react app and when I try to add a player to my players list it seems to...
Read more >Error RangeError: Maximum call stack size exceeded
Data is passed to control using props. We get " RangeError: Maximum call stack size exceeded" if we do following steps.
Read more >React boilerplate : Maximum call stack size exceeded-Reactjs
Coding example for the question React boilerplate : Maximum call stack size exceeded-Reactjs.
Read more >RangeError: Maximum call stack size exceeded - Educative.io
The most common source for this error is infinite recursion. You must have a recursive function in your code whose base case is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve found issue.
validate
on Field element must point to the same reference otherwise given Field is reregistered. Following code caused given issue with construction that I’ve mention in comment above .I had the same issue. My form was re-rendering infinitely when the user added an object to a FieldArray.
The nextProps/this.props and nextState/this.state were all the sames in shouldComponentUpdate, but it was still re-rendering.
I was able to fix this by overriding
shouldComponentUpdate
and check if nextProps/this.props and nextState/this.state were not strictly equal.