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

Avoid unnecessary re-renders by comparing errors to previous errors #2069

Merged
merged 1 commit into from
Nov 27, 2019

Conversation

mvestergaard
Copy link
Contributor

@mvestergaard mvestergaard commented Nov 26, 2019

This addresses part of #1974

Each time any field is touched (onChange, onBlur) the errors on the context changed, causing all fields to re-render once more than needed (2 renders per change)

This fix will compare the new errors object being assigned to the existing one, and only change the state if they are different.

FastField is still fundamentally broken, because it will re-render on each change to the context. Should be fixed in #2070

@vercel
Copy link

vercel bot commented Nov 26, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/jared/formik-docs/otylk2i62
🌍 Preview: https://formik-docs-git-fork-mvestergaard-performance-fix.jared.now.sh

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5ded232:

Sandbox Source
Formik TypeScript Playground Configuration

@mvestergaard
Copy link
Contributor Author

I tried my best to write a test that reproduces the problem, but it's really difficult, if not impossible in a "fake context".
Use the FastField story in the formik storybook to compare the behavior to before.

@jaredpalmer jaredpalmer merged commit f4ff028 into jaredpalmer:master Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants