Redux-Form - Validation function causes infinite loop

968 Views Asked by At

I have redux-form and I have a problem with the validation function. And this error only happens on my cloud servers, in local, I have no problems with this.

Here is the validation function :

function validate(values){
    const errors = {};
    let requiredFields = [
        'gender', 'first_name', 'last_name'
    ];
    requiredFields.forEach(field => {
        if (!values[field]) {
            errors[field] = 'Required';
        }
    });
    return errors;
}

And I call it just like this :

EditProfileForm = reduxForm({
    form: 'editProfile',
    validate
})(EditProfileForm);

And even when I run the production code in local, which for now simply does :

config.plugins.push(new webpack.optimize.UglifyJsPlugin({
        mangle: false
    })
)

It still works in local, it's only when the code is on the servers that I have the problem.

It dispatches the action : redux-form/UPDATE_SYNC_ERRORS to the infinite and I have to force shut down Chrome to stop this.

I have initialValues that is an object, and the error occurs only when values are empty, ie the DB doesn't return me the first_name for instance however. I don't understand why it's looping like this, and only on the cloud.

I also tried to set first_nameto undefined if it's not setted in DB, but still not ok.

The version of redux-form used is 6.4.2

Do you have any ideas ?

0

There are 0 best solutions below