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 SetError to Preserve Existing Errors elsewhere in the object #11888

Merged

Conversation

SimonJTurner
Copy link
Contributor

When calling setError, if a call was made to set an error on a descendant within a form (foo.bar.baz), then a later call was made to set an error on the ancestor (foo.bar), the previous error would be lost.

This was the run of pnpm test after the first commit, which only contained the test:
image

Following the update to setError, we make sure you don't lose the errors that are further down the tree by including them in the call to set. To be fair, one /could/ consider just spreading in the entire currentError, but by destructuring and omitting message and type we make sure that they get overwritten by the current error.

Copy link

codesandbox bot commented May 15, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@bluebill1049
Copy link
Member

thanks for the contribution.

@bluebill1049 bluebill1049 merged commit 48f8822 into react-hook-form:master May 19, 2024
6 of 7 checks passed
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.

None yet

2 participants