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
DestroyOnUnregister incompatible with StrictMode in React18 #1031
Comments
Strict Mode is a Breaking Change in React 18... There are workarounds out there e.g. https://blog.ag-grid.com/avoiding-react-18-double-mount/ Willing to accept a PR that fixes this behaviour. |
Hi! It's a bit complicated to try and handle correctly the behavior when you have dependencies or changing effect function ( the code in the link broke quite a lot of tests in final-form I've managed to have a version that works here ( and for which the tests passes on react-final-form ) I'm not sure I'm not missing some weird edge cases that would break the regular behavior of useEffect. It looks like it would be hard to bring the tests in react-final-form as they are only valid for react 18. |
Type of issue
Bug
What is the current behavior?
When opening a form with the attribute 'destroyOnUnregister' in StrictMode locally, the initial Values are not displayed.
What is the expected behavior?
When opening a form with the attribute 'destroyOnUnregister' in StrictMode locally, the initial Values are displayed.
Sandbox Link
See https://codesandbox.io/s/inspiring-cori-smyfhm?file=/src/App.js
What's your environment?
react-final-form: 6.5.9
final-form: 4.20.9
react: 18.2
Other information
As far as I can see, the values are rendered in the first cycle. Then StrictMode unmounts the fields, causing them to be removed from the form model (caused by 'destroyOnUnregister'). On the second mount, the initial values are considered to be identical, hence the fields will not be filled again but remain empty.
When running in production (i.e. w/o StrictMode) the form is filled. The form will also work correctly if:
The text was updated successfully, but these errors were encountered: