React-admin: Cyclic form re-rendering until crash after AOR 1.3.0

Created on 20 Sep 2017  路  6Comments  路  Source: marmelab/react-admin

The thing is like this:
Why make two form for edit and add if they are same?
So i made one BaseForm and include it in Create and Edit

Before 1.3.0 it worked fine, but after update to 1.3.0 the app started crashing on Create.
(Funny thing: if you remove the minLength validator then it works (does same for max and min/max-Value))

Example: https://gist.github.com/natrim/863c0ec93f2d86df0fe170ddb05d5ffb
Just create-react-app, copy files and try to create post

bug

All 6 comments

What does "crash" mean? Can you locate the error and paste the message?

Uncaught RangeError: Maximum call stack size exceeded

i am assuming it has something to do with changing of how default values are set as it does work fine in edit mode

Workaround until we figure this out: declare your validation rules outside the component render, for example:

const titleValidate = [required, minLength(3)];

const BaseForm = (props) => {
    return (
        <SimpleForm {...props}>
            <TextInput source="title" validate={titleValidate} />
            <LongTextInput source="body" />
        </SimpleForm>
    );
};

any progress? I was going crazy until I figured out that validation rules array causes infinite render after upgrade

bit late probably, but anyway ;) :
I am working on a custom component wrapping SimpleForm (AOR 1.3.2 now), and had similar problem.
(it was constant flow of UNREGISTER_FIELD/REGISTER_FIELD in redux-form 7.0.4)
Setting validation rules outside render loop fixes it , and i found a comment explaining exactly how it works
https://github.com/erikras/redux-form/issues/3211#issuecomment-318420350

btw. according to release notes there were quite a lot of changes lately in redux-form
https://github.com/erikras/redux-form/releases
soo.. are there any plans on upgrade dependecy if I may ask ? ;)

This won't be fixed in v1 but has been in react-admin v2. Until v2 is out, you'll have to declare your validators outside the render method of your components as suggested in redux-form documentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kmaschta picture Kmaschta  路  22Comments

Weakky picture Weakky  路  20Comments

olegweb picture olegweb  路  23Comments

fzaninotto picture fzaninotto  路  79Comments

josephktcheung picture josephktcheung  路  22Comments