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

Make formik sync when validation functions are sync #3976

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

fbarbare
Copy link

@fbarbare fbarbare commented Jun 25, 2024

When the given validation function are synchronous there is no reason to make them async. Making them async actually makes the whole code much slower and creates unecessary re-renders.

Copy link

vercel bot commented Jun 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
formik-docs ⬜️ Ignored (Inspect) Visit Preview Oct 15, 2024 1:37pm

Copy link

codesandbox-ci bot commented Jun 25, 2024

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.

Copy link

changeset-bot bot commented Jun 25, 2024

🦋 Changeset detected

Latest commit: a0b17a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
formik Minor
formik-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@fbarbare
Copy link
Author

@jaredpalmer This change goes in the direction that you are mentioning in #2140 but is backwards compatible since it's not removing any functionality. The deprecation of the async validation methods could be done in a later stage so we can first make things more synchronous (which will improve performance of a lot of apps) and then proceed with the removal of the async stuff.
Any thoughts?

Copy link
Contributor

@bonimba bonimba left a comment

Choose a reason for hiding this comment

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

👏🏻 Well done. Amazing update

packages/formik/src/Formik.tsx Outdated Show resolved Hide resolved
@quantizor
Copy link
Collaborator

@fbarbare could you update against main when you get a moment? This branch looks awesome!

@quantizor
Copy link
Collaborator

Would love to see the benchmarks run for this vs current main as well

@fbarbare
Copy link
Author

@quantizor Thanks for looking at this PR! I have updated the branch with main and also added a changeset.

@@ -0,0 +1,5 @@
---
'formik': minor
Copy link
Author

Choose a reason for hiding this comment

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

@quantizor we might want to make this a major version bumb in the end.

I had not thought of that initially but if anyone implemented things as setFieldValue(..).catch(...) then it would break if their validation functions would be sync. It would be completely fine if they would implement it as await setFieldValue(..) or void setFieldValue(..) though.

What are your thoughts?

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.

3 participants