Skip to content

fix: preserve sibling fields in setFieldValue (#4999)#5130

Open
logaretm wants to merge 1 commit into
mainfrom
fix/4999-setfieldvalue-object-loss
Open

fix: preserve sibling fields in setFieldValue (#4999)#5130
logaretm wants to merge 1 commit into
mainfrom
fix/4999-setfieldvalue-object-loss

Conversation

@logaretm
Copy link
Copy Markdown
Owner

@logaretm logaretm commented Mar 4, 2026

Summary

  • Fixes Loss of object fields after calling setFieldValue #4999: setFieldValue losing object fields when updating a nested property within an array of objects
  • Normalizes paths in createPathState to ensure consistent comparison with UNSET_BATCH entries and pathStateLookup keys
  • Previously, paths using dot notation for array indices (e.g., items.0.name) would not match their bracket-normalized equivalents (e.g., items[0].name) in the UNSET_BATCH, preventing proper cancellation of pending unset operations

Changes

  • packages/vee-validate/src/useForm.ts: Normalize paths in createPathState for pathStateLookup access, UNSET_BATCH comparison, error lookup, and path state storage
  • packages/vee-validate/tests/useForm.spec.ts: Add 3 regression tests covering the issue scenario with various configurations (basic, Zod schema, FieldArray + Field components)
  • .changeset/fix-4999-setfieldvalue-object-loss.md: Changeset for patch release

Test plan

  • Existing test suite passes (358 tests, 3 pre-existing failures unrelated to this change)
  • New test: setFieldValue preserves sibling fields when updating nested property in array of objects
  • New test: setFieldValue preserves sibling fields with individually registered nested fields
  • New test: setFieldValue preserves sibling fields with Field components inside FieldArray

🤖 Generated with Claude Code

Normalize paths in createPathState to ensure consistent comparison with
the UNSET_BATCH entries and pathStateLookup keys. Previously, paths using
dot notation for array indices (e.g., 'items.0.name') would not match
their bracket-normalized equivalents (e.g., 'items[0].name') in the
UNSET_BATCH, preventing proper cancellation of pending unset operations
when a new path state was created via setFieldValue.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 4, 2026 06:13
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 463c27b

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

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 4, 2026

Deploy Preview for vee-validate-docs canceled.

Name Link
🔨 Latest commit 463c27b
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-docs/deploys/69a7cd6e06bb51000890cf0f

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 4, 2026

Deploy Preview for vee-validate-v5 ready!

Name Link
🔨 Latest commit 463c27b
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-v5/deploys/69a7cd6efbf3ef00078d0289
😎 Deploy Preview https://deploy-preview-5130--vee-validate-v5.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes vee-validate issue #4999 where calling setFieldValue on a nested property (especially within arrays of objects) could interact incorrectly with path-state bookkeeping due to inconsistent path formats (dot vs bracket array indices).

Changes:

  • Normalizes field paths inside createPathState to make pathStateLookup access and UNSET_BATCH cancellation consistent for array-indexed paths.
  • Adds regression tests covering the reported scenario across: basic usage, Zod schema, and FieldArray + Field component usage.
  • Adds a patch changeset for release notes/versioning.

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 Normalizes paths in createPathState when interacting with lookup and pending-unset bookkeeping.
packages/vee-validate/tests/useForm.spec.ts Adds three regression tests for nested updates within arrays of objects.
.changeset/fix-4999-setfieldvalue-object-loss.md Patch changeset entry for the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +321 to 324
if (errors.value[normalizedPathValue] && !initialErrors[normalizedPathValue]) {
nextTick(() => {
validateField(pathValue, { mode: 'silent' });
validateField(normalizedPathValue, { mode: 'silent' });
});
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

initialErrors is a raw copy of opts.initialErrors (not normalized), but this check now indexes it with normalizedPathValue. If a consumer provides initial errors using dot-index paths (e.g. items.0.name), initialErrors[normalizedPathValue] will be undefined and this will incorrectly trigger a silent validateField, potentially clearing/changing the intended initial error state. Consider normalizing initialErrors keys up front, or normalize on access here (e.g., check both raw + normalized forms consistently).

Copilot uses AI. Check for mistakes.
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.

Loss of object fields after calling setFieldValue

2 participants