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(2172)!: validateOnMount initialize isValid to false until validation performed #3984

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anonkey
Copy link

@anonkey anonkey commented Aug 26, 2024

Related to 2172
Maybe it could be extended to use cases without validateOnMount but with validate function or validationSchema ?

Copy link

changeset-bot bot commented Aug 26, 2024

🦋 Changeset detected

Latest commit: 33818d3

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

This PR includes changesets to release 3 packages
Name Type
formik Major
formik-native Patch
fdocs3 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

Copy link

vercel bot commented Aug 26, 2024

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

Name Status Preview Comments Updated (UTC)
formik-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 26, 2024 10:26pm

Copy link

codesandbox-ci bot commented Aug 26, 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.

@anonkey anonkey changed the title fix(formik): validateOnMount initialize isValid to false until validation performed Draft: fix(formik): validateOnMount initialize isValid to false until validation performed Aug 26, 2024
@anonkey anonkey force-pushed the fix/validateonmount-initialize-isvalid-to-false branch from affb616 to 33818d3 Compare August 26, 2024 22:24
@anonkey anonkey changed the title Draft: fix(formik): validateOnMount initialize isValid to false until validation performed fix(formik): validateOnMount initialize isValid to false until validation performed Aug 26, 2024
@anonkey anonkey changed the title fix(formik): validateOnMount initialize isValid to false until validation performed fix(2172): validateOnMount initialize isValid to false until validation performed Aug 26, 2024
@anonkey anonkey changed the title fix(2172): validateOnMount initialize isValid to false until validation performed fix(2172)!: validateOnMount initialize isValid to false until validation performed Aug 26, 2024
@@ -152,6 +152,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
const initialTouched = React.useRef(props.initialTouched || emptyTouched);
const initialStatus = React.useRef(props.initialStatus);
const isMounted = React.useRef<boolean>(false);
const validated = React.useRef<boolean>(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think your move to add a ref here is right, but we should be running validation synchronously on mount if validateOnMount is set such that validation has occurred within the first render pass and there is no potential for the boolean to flip either way.

Copy link
Author

@anonkey anonkey Sep 9, 2024

Choose a reason for hiding this comment

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

How should i run validation synchronously since it may be async ?

Copy link
Author

Choose a reason for hiding this comment

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

@quantizor any hint ? this cause annoying UI issue for me

Copy link
Author

Choose a reason for hiding this comment

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

Any chance to fix it ? I really need this fix

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