-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: prevent unnecessary renders when form has errors #358
Conversation
🚀 Deployed on https://pr-358--dhis2-data-entry.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still find it weird the component is declared below where it is used 😉 but it works 🙌
src/data-workspace/entry-form.js
Outdated
/* Used to sync store with errors from form | ||
In its own component to prevent unecessarily re-renders in the tree */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Used to sync store with errors from form | |
In its own component to prevent unecessarily re-renders in the tree */ | |
/** | |
* Used to sync global store with errors from final-form. | |
* Because of the `errors` subscription in `useFormState`, this re-renders | |
* on every form input change if there is an error in the form. Therefore, this | |
* has its own component to prevent unnecessary re-renders below it in the tree | |
*/ |
🎉 This PR is included in version 100.3.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
While working on #357 , I noticed the entire form was being re-rendered on each input. We've spent quite a lot of time to optimize this, but I realized it only happened when the form contained an error. The culprit was the logic to keep the zustand-store up to date with the form-errors. I've now moved this to its own component, so the hook won't re-render the entire form.
Before:
Screen.Recording.2023-09-26.at.13.33.59.mov
After:
Screen.Recording.2023-09-26.at.13.37.38.mov