-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Infinite loop (Maximum call stack size exceeded) when passing redux form as a prop #2629
Comments
+1 |
The webpack bin link is not working anymore for some reason. I've created a sample project to simulate this problem, can be accessed here (I've also updated the link on the original issue). While I was creating the project I've found some more information about when it occurs. 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 const mapStateToProps = state => ({
// This causes the error
clicks: { enhanced: true, count: state.clicks.count },
// This works
// clicks: state.clicks
}); I also found that the infinite recursion is happening here |
I did some more testing and I found what the problem really is. Basically it's an infinite dispatch loop, what happens is that the This will trigger react redux to check what are the components that need a rerender, and because I'm always returning a new object on I'm not sure whether this is a redux-form's problem or not, or if there's something we can do to prevent this error. Maybe we can check on Field's Or maybe we can just add a check there for recursion and raise a warning about this problem pointing to some documentation explaining it and how to avoid it. What do you think @erikras? |
I ran into this as well. I'm setting
Then in a component I have render like:
|
I think if you create the const initialvalues = [{}];
EventForm = connect(
state => ({ initialValues })
)(EventForm); The problem with your current approach is the same I've described in my last comment, it will cause an infinite dispatch loop. |
Yeah, dispatch loop it is. |
@erikras Any chance you can take a look at this? |
for me it happens if I use |
I have this same problem. I was able to fix it by overriding the the Example:
with Let me know if this helps anyone. |
I had the same issue. 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
|
I was running into the same problem, and reading this thread clarified my mistake. The component rendering the form I was using was mapping state to props like this: export default connect(state => state)(App) And I was able to fix "ignoring" the form's state, like this: export default connect( ({app}) => ({app}) )(App) What just happened is that I was recurring over the entire state, including the form's state, and somehow it couldn't manage well, leading to this infinite loop. Fortunately, my wrapper component—the one rendering the redux form—doesn't rely on its state and I was able to just skip it. If that's the case of someone facing this same issue, try to just skip it as I did. Otherwise, just for a matter of statement, these |
I've seen various errors in the past from dispatching during |
Gah! this keeps happening to me, I thought I'd fixed it but now its back isSymbol.js:24 Uncaught (in promise) RangeError: Maximum call stack size exceeded |
can confirm it was passing a redux-form component as a prop, not directly but as a child of the component that got passed as a prop. This was using the react router v4 |
also I have to say it happened on when the component was either a Class or Stateless Function. Now I've taken the Router away it isn't happening, but that leaves me with a new problem.... |
changed my render method from this
to this
and problem has gone away. While debugging I had a console.log on the components constructor and could see it was repeatedly being called, something in redux-form and router combo was causing the component to be re initialised, not idea what the details are but things are working now. |
Is this still an on-going open issue? It might be something subtly different, but I am seeing the same issue (Maximum call stack size exceeded) that is blowing up our This works:
This blows up:
|
We got similar problem in our repository after a long debug. The problem was some items of After use a |
To add some additional context. We "happen" to be using Interestingly the problem had NOTHING to do with Many days of hair pulling resulted in the discovery that something else unknown was causing a strange interaction. But hey, it's working now (for us) at least! :) |
I have run into this issue twice. It happens when I introduce a closure in my
The first time I just stopped using EDIT!!
|
I am having issues with infinite loops as well. I can reproduce by trying to call this.props.initialize in componentWillMount with undefined values, without a try/catch surrounding componentWillMount. I am using React 15.5.4, redux-form 7.0.3.
|
Please look into this issue @erikras or any other redux-form maintainer. The above comment from @tiagoengel seems to be spot on for many of the cases where I've encountered this bug. They all appear to be caused by instantiating things passed to redux-form in the render method. My team struggles with this issue every couple weeks and it is always a very lame time suck. The reason it is so bad is because there is no informative message about what might be going wrong. You usually have to dig for quite a while. Even if there isn't a way to stop the infinite render loop, at the very least we should be able to provide informative warning messages in the console about what might be causing things to loop. Linking some related issues here as well just to point out how common of an issue this really is: |
I am having this problem too, if in the same form I have a formValueSelector and field level validation (different fields). |
Hello, I've not checked internal code, but it's related to change of props above reduxForm HoC. The most likely it's related to Field registration and unregistration.
so infinite loop happens due state change on given path: reduxForm should not care about currentDateTime. Please feel free to point me if I have observed things incorrectly. |
I've found issue.
|
Hi, const renderMyArrayFields = ({ fields, meta: { touched, error } }) => (
// my array fields
)
class MyForm extends Component {
render () {
return (
<div>
<FieldArray name="myName" component={renderMyArrayFields} />
//... Sorry, for this absolute newby remark. I know it does not help you, but it helped me and it is worth sharing. There is not a lot of non-expert information available on redux-form. |
I did the same as @rostislav-simonik and put a function inline as props. Once I moved the function out of the component and referenced it - the looping craziness stopped. Thank you @rostislav-simonik ! |
Thanks @rostislav-simonik. Solved my problem. This side effect is happening because of the change implemented as a result of the issue #3012, this change: 0b578c7#diff-ca0d4d55e50da37455f88ffb85da436b. It is a change that can break existing codes when upgrading to redux-form version 7. |
Probably would be great to implement shallow equal for that prop.
…Sent from my iPhone
On 20 Sep 2018, at 18:19, Lucas Villela Neder Issa ***@***.***> wrote:
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 .
<Field
validate = { [
(value) => {},
] }
</Field>
Thanks @rostislav-simonik. Solved my problem. This side effect is happening because of the change implemented as a result of the issue #3012, this change: 0b578c7#diff-ca0d4d55e50da37455f88ffb85da436b. It is a change that can break existing codes when upgrading to redux-form version 7.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
The current version has this change: b02e8a4#diff-ca0d4d55e50da37455f88ffb85da436b, but the problem still almost the same. This last change will allow to create new array with the same functions (the same reference to the function), but if the same function is recreated (different reference) the problem still exists. For example: Will work fine:
May cause "Maximum call stack size exceeded" error:
|
@rostislav-simonik thank you for helping me solving my problem. Infinite loop causes:
Works fine by moving validation array outside render method, e.g.:
|
This means that dynamic validation, for example validation that confirm password field is equal to the value of password filed field, is not possible. |
Hey @yourGuy, Its totally possible! If they are part of the same form the validator function will be give all the form values in the second argument and then you can use the name to look up the value of the password field and check its equal. note you the logic will be coupled to the name field
If anyone else is still having trouble with this infinite loop. You can now use the new
|
@Multimo thank you, I didn't know that filed level validators execute with allValues, even though it's right there in the documentation :( |
You can close |
After trying every other way to solve this problem, I found this to be the simplest and optimal solution. |
You are right here. <Wrapper newMessageForm={() => <NewMessageForm onSubmit={handleSubmit} /> }/> Because of that redux store update circle and using an inline function, here you always return a new created form. That will try to register again, and the circle continues. Use the solution you provided <Wrapper newMessageForm={NewMessageForm}/> or constructor(props) {
super(props)
this.NewMessageForm = () => <NewMessageForm onSubmit={handleSubmit} />
}
render() {
.....
<Wrapper newMessageForm={this.NewMessageForm}/>
.....
}
On the initial issue you provided I don't think this is a For all other issues that were described here, please fill a new issue with a good description of the problem, or search maybe the issue already is created. I'll close this for now, feel free to comment. |
Still learning React. Often things like this make no sense to me. |
You'll get used to it. 🙂 |
For me, destroyOnUnmount: false resolve the issue. |
EDIT:
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:
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:
This error doesn't happen if the component is passed like this:
or even like this:
I have an example here
What's your environment?
Tested on chrome using redux-form@6.5.0
Other informations
Stack Trace:
I've tried to reproduce this bug in an unit test but, as for today, I wasn't able to.
The text was updated successfully, but these errors were encountered: