fix: useField with object values now validates correctly (#5088)#5142
fix: useField with object values now validates correctly (#5088)#5142
Conversation
When a schema (e.g., yup) reports validation errors at nested sub-paths (like 'someObject.id') but the field is registered at a parent path (like 'someObject'), the errors were stored in extraErrorsBag and never cleaned up. This caused form.meta.valid to remain false even after resetForm with valid values. Two fixes: 1. In validateSchema callback, also clean up extraErrorsBag entries for the original error path when it gets hoisted to a parent field path. 2. In resetForm, clear extraErrorsBag before setting new errors to ensure stale nested-path errors don't persist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 2b5f759 The changes in this PR will be included in the next version bump. 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 |
✅ Deploy Preview for vee-validate-docs canceled.
|
✅ Deploy Preview for vee-validate-v5 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Fixes a vee-validate schema-validation edge case where nested-path schema errors (e.g. someObject.id) could be stored in extraErrorsBag and remain stale after subsequent validations/resets, causing form.meta.valid to stay false incorrectly.
Changes:
- Clean up
extraErrorsBagentries when schema errors are hoisted from a nested path to a parent field path during schema validation. - Clear
extraErrorsBagduringresetForm()to prevent stale unmounted-field errors from persisting across resets. - Add a regression test covering delayed field rendering +
resetForm()with valid object values and a yup schema.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/vee-validate/src/useForm.ts |
Deletes hoisted nested-path entries from extraErrorsBag during schema validation; clears extraErrorsBag on resetForm(). |
packages/vee-validate/tests/useForm.spec.ts |
Adds a regression test reproducing the stale nested-path error scenario with delayed rendering and resetForm(). |
.changeset/fix-5088-object-field-validation.md |
Adds a patch changeset entry for the fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Also clean up extra errors for the expected path when it was hoisted to a different path | ||
| // This handles cases where schema reports errors at nested sub-paths (e.g., 'someObject.id') | ||
| // but the field is registered at a parent path (e.g., 'someObject') | ||
| if (pathState && expectedPath !== path && extraErrorsBag.value[expectedPath]) { | ||
| delete extraErrorsBag.value[expectedPath]; | ||
| } |
There was a problem hiding this comment.
extraErrorsBag keys are stored using normalizeFormPath(), but this cleanup checks/deletes using the raw expectedPath. If the schema reports a path using dot-index notation (e.g. items.0.id) while extraErrorsBag stores items[0].id, the stale entry won’t be removed. Normalize expectedPath (and use it for the comparison) before reading/deleting from extraErrorsBag to ensure cleanup works for all path formats.
Summary
useFieldwith object values and a schema that reports validation errors at nested sub-paths (e.g., yup reporting errors atsomeObject.idfor a field registered assomeObject), the errors were stored inextraErrorsBagand never cleaned up during subsequent validations.form.meta.validto remainfalseeven afterresetFormwith valid values, because stale nested-path errors persisted in the extra error bag.validateSchemacallback, also clean upextraErrorsBagentries for the original error path when it gets hoisted to a parent field path.resetForm, clearextraErrorsBagbefore setting new errors to ensure stale nested-path errors don't persist across resets.Test plan
v-if, andresetFormwith valid values🤖 Generated with Claude Code