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(useForm): leave formState flags in a consistent state when throwing in handleSubmit onValid #11214

Conversation

anonkey
Copy link
Contributor

@anonkey anonkey commented Nov 21, 2023

Proposed Changes

onValid function given to handleSubmit from useForm is often the way to send request to server but when this function throw it leave isSubmitting flag true and isSubmitted flag on false what is inconsistent.

This change keep the current behavior of bubbling up the error but fix the inconsistent formState

Fixes #11084

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

Copy link

codesandbox bot commented Nov 21, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@anonkey
Copy link
Contributor Author

anonkey commented Nov 21, 2023

Had problem to run
pnpm tsd and pnpm e2e locally
Hope this will be checked by CI

@anonkey anonkey changed the title fix(useForm): leave formState flags in a consistent state when throwing in handleSubmit onValid Draft: fix(useForm): leave formState flags in a consistent state when throwing in handleSubmit onValid Nov 21, 2023
@anonkey anonkey changed the title Draft: fix(useForm): leave formState flags in a consistent state when throwing in handleSubmit onValid fix(useForm): leave formState flags in a consistent state when throwing in handleSubmit onValid Nov 21, 2023
@anonkey anonkey force-pushed the fix-useform-invalid-formstate-throwing-in-onvalid branch from f2c3da1 to a3d7507 Compare November 23, 2023 13:31
@bluebill1049
Copy link
Member

thanks for the PR, i think this is what i had before but users complain about errors being swallowed by handleSubmit.

@anonkey
Copy link
Contributor Author

anonkey commented Dec 7, 2023

With this there is still error bubbling up just it set the isSubmitting state before rethrowing the error, no swallow happens

@anonkey
Copy link
Contributor Author

anonkey commented Dec 29, 2023

Since error are not swallowed like before, is there any chance to have this MR merged ?

Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

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

LGTM. let me know if you are happy with this as well @Moshyfawn

@Moshyfawn
Copy link
Member

LGTM. let me know if you are happy with this as well @Moshyfawn

This is fine as a behaviour fix 👍

@bluebill1049 bluebill1049 merged commit f18c147 into react-hook-form:master Jan 15, 2024
7 checks passed
@anonkey
Copy link
Contributor Author

anonkey commented Jan 25, 2024

Thanks a lot for the PR and for your work

@pianomansam
Copy link

When will this get released?

Pardon my ignorance, as I'm a user of the project and not yet a contributor. I stumbled across this issue because I'm experiencing isSubmitting still being true after a rejected promise in the onSubmit handler.

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.

issue: formState is incorrect after submission - fix is an ugly hack
4 participants