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

Concurrent calls to setFieldValue results in field validator receiving stale value #3542

Open
yjwong opened this issue Apr 12, 2022 · 4 comments

Comments

@yjwong
Copy link

yjwong commented Apr 12, 2022

Bug report

Current Behavior

When calling setFieldValue in two field components based on changes to another field value, the validator of each field component may receive a stale field value.

Expected behavior

The field validator should be called with the latest value.

Reproducible example

https://codesandbox.io/s/green-sun-tekp6b?file=/index.js

Suggested solution(s)

I'm not exactly sure what to do here, as I'm not familiar with Formik internals.

Additional context

Your environment

Software Version(s)
Formik 2.2.9
React 17.0.2
TypeScript 4.5.2
Browser Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36
npm/Yarn Yarn v1.22.18
Operating System macOS Monterey 12.3
@johnrom
Copy link
Collaborator

johnrom commented Apr 12, 2022

This is resolved in #3231, which was never merged.

You're free to test it out here: https://www.npmjs.com/package/@johnrom/formik-v3/v/3.0.0-rc2

@jwalton
Copy link

jwalton commented Apr 12, 2022

I suspect this is related to #3275.

@yjwong
Copy link
Author

yjwong commented Apr 12, 2022

I think it might be worth mentioning, we first found this issue in Formik 2.1.4, but upgraded to 2.2.9 to see if it still persists. But interestingly, using version 2.2.6 as found in the issue that @jwalton linked works fine!

I also tried 2.2.7 and it's broken there so I suppose it's some change in between.

Version 2.2.5 also works fine, but it's broken for versions <= 2.2.4.

@jwalton
Copy link

jwalton commented Apr 12, 2022

Downgrading to 2.2.6 fixed it for me, too.

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

No branches or pull requests

3 participants