-
-
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
Re-mounting a Field component erases the field-level validation function #3566
Comments
Status on this? |
To add some context: I get the same problem on all 7.x.x versions. Works as expected on 6.8.0 React: 15.6.2 |
Yes, I have the same problem. It was because componentWillUnmount call after componentWillMount. -> componentWillMount First I think redux-form must call register function when componentDidMount. I can try make PR for this? But I don't know what's can broke if register function will move in componentDidMount... related links: |
I solve this problem via destroyOnUnmount: false, but I don't know what's wrong if you use it in your own project. |
I used destroyOnUnmount: false too as a temporary workaround, but a side-effect is that the form keep the submitted values as initialValues... |
Any news on this? |
Hi folks, I also have this issue. Thanks to @Luchanso , I am using workaround. Do you have any news on this issue? |
I can't use the |
@Elliot128 we also had same issue. We first thought about clearing values by firing change action, but this approach will keep the validation errors. So we decided to register/deregister fields manually, until we find a good solution. |
I believe that #3500 also relates to this |
@erikras @gustavohenke I think @sandkampderek suggestion to use I tested registering Field in Reactjs docs say that we should avoid @erikras @gustavohenke |
Seems that we should use
Then error is printed to console: |
I met this issue as well, but I found a intreating solution:
Someone can explain this? The only diff is one use < />, another one use {func()} |
Fix released in |
@erikras
|
…#3566) (#3956) * Use componentDidMount instead of componentWillMount to register Field, Fields, FieldArray. Fixes #3566 * Test field validate prop after unregister and register Field #3566 * PR improvement, remove duplicate code. * PR improvement. lint, remove semicolons * Use constructor instead of componentWillMount to register Field, Fields, FieldArray. PR comment: #3956 (comment) * Revert "Use constructor instead of componentWillMount to register Field, Fields, FieldArray. PR comment: #3956 (comment)" This reverts commit 82781c0
Hi, is this issue resolved? I am facing similar issue and still need to depend on onDestroyUnmount: false workaround. |
Hi, thanks for any help to resolve these issues |
This issue is still reproducable on redux-form 8.2 enableReinitialize : true solve the issue |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Are you submitting a bug report or a feature request?
Bug report
What is the current behavior?
When a Field with a field-level validation function attached to it is unmounted and immediately re-mounted, that validation function will never be run again.
In the example below, when the key changes, the Field will be unmounted and re-mounted, and the validation function will never be run again:
Perhaps a more common method of unmounting and remounting fields is conditional rendering of fields with the same name. In the example below, when this.state.shouldRenderTextArea changes, the validate function will never be run again:
What is the expected behavior?
After the field is re-mounted, its validation function should run.
Sandbox Link
https://codesandbox.io/s/m7l1lyzyoy
What's your environment?
redux-form 7.1.1
react 16.0.0
Other information
The problem appears to be that Field registers the validate function in componentWillMount, and erases the validate function in componentWillUnmount. However, React 16 will always run componentWillMount of the new component BEFORE componentWillUnmount of the old component. That means that we register the new validate function, and immediately delete it.
Would there be any problem with having Field register itself it componentDidMount instead?
The text was updated successfully, but these errors were encountered: