Skip to content
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

Merged
merged 2 commits into from
Dec 13, 2023

Conversation

Birkbjo
Copy link
Member

@Birkbjo Birkbjo commented Sep 26, 2023

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

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Sep 26, 2023

🚀 Deployed on https://pr-358--dhis2-data-entry.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify September 26, 2023 11:29 Inactive
Copy link
Contributor

@KaiVandivier KaiVandivier left a 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 🙌

Comment on lines 71 to 72
/* Used to sync store with errors from form
In its own component to prevent unecessarily re-renders in the tree */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* 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
*/

@dhis2-bot dhis2-bot temporarily deployed to netlify December 11, 2023 13:28 Inactive
@Birkbjo Birkbjo merged commit 25e8d74 into master Dec 13, 2023
11 checks passed
dhis2-bot added a commit that referenced this pull request Dec 13, 2023
## [100.3.8](v100.3.7...v100.3.8) (2023-12-13)

### Bug Fixes

* prevent unnecessary renders when form has errors ([#358](#358)) ([25e8d74](25e8d74))
* **validator:** limits as warning instead of error ([#357](#357)) ([8e61906](8e61906))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 100.3.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants