Skip to content

fix: resetForm properly resets fieldArray on subsequent resets (#5076)#5128

Open
logaretm wants to merge 1 commit intomainfrom
fix/5076-resetform-fieldarray
Open

fix: resetForm properly resets fieldArray on subsequent resets (#5076)#5128
logaretm wants to merge 1 commit intomainfrom
fix/5076-resetform-fieldarray

Conversation

@logaretm
Copy link
Copy Markdown
Owner

@logaretm logaretm commented Mar 4, 2026

Summary

  • Fixes resetForm not resetting fieldArray's correctly #5076: resetForm with { force: true } was not properly resetting useFieldArray after the first reset when used inside a <Form> component.
  • The root cause was that forceSetValues (used when force: true) did not call fieldArrays.forEach(f => f.reset()) to regenerate field array entries, while the non-force path through setValues did.
  • Added the field array reset call to forceSetValues to match the behavior of setValues.

Test plan

  • Added test in useFieldArray.spec.ts that reproduces the scenario: push items, reset with force, push again, reset again — verifying the second reset also correctly removes extra field array entries.
  • All existing tests continue to pass.

🤖 Generated with Claude Code

When resetForm was called with { force: true }, it used forceSetValues which
did not reset field arrays, unlike the non-force path through setValues.
This caused useFieldArray fields to not properly sync after the first reset.

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

netlify Bot commented Mar 4, 2026

Deploy Preview for vee-validate-docs canceled.

Name Link
🔨 Latest commit 0987b74
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-docs/deploys/69a7ca98c54de80008f964dd

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 0987b74

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-v5 ready!

Name Link
🔨 Latest commit 0987b74
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-v5/deploys/69a7ca98d35d45000812ee1b
😎 Deploy Preview https://deploy-preview-5128--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 a bug in vee-validate where resetForm(..., { force: true }) did not fully reset useFieldArray state after the first reset when used via the <Form> (VForm) component slot API (issue #5076). The fix aligns the “force” reset path with the non-force setValues behavior by regenerating field array entries whenever forced values replacement occurs.

Changes:

  • Add fieldArrays.forEach(f => f && f.reset()) to forceSetValues so forced value replacement also regenerates field array entries.
  • Add a regression test covering repeated resetForm calls with { force: true } when useFieldArray is used inside a child component under <VForm>.
  • Add a changeset to publish the fix as a patch.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/vee-validate/src/useForm.ts Ensures the forceSetValues path resets field arrays to match setValues, fixing subsequent forced resets.
packages/vee-validate/tests/useFieldArray.spec.ts Adds a regression test reproducing the “second forced reset” field array stale entries scenario.
.changeset/fix-5076-resetform-fieldarray.md Records a patch-level release note for the fix.

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

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.

resetForm not resetting fieldArray's correctly

2 participants