fix: resetForm properly resets fieldArray on subsequent resets (#5076)#5128
fix: resetForm properly resets fieldArray on subsequent resets (#5076)#5128
Conversation
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>
✅ Deploy Preview for vee-validate-docs canceled.
|
🦋 Changeset detectedLatest 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 |
✅ 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 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())toforceSetValuesso forced value replacement also regenerates field array entries. - Add a regression test covering repeated
resetFormcalls with{ force: true }whenuseFieldArrayis 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.
Summary
resetFormwith{ force: true }was not properly resettinguseFieldArrayafter the first reset when used inside a<Form>component.forceSetValues(used whenforce: true) did not callfieldArrays.forEach(f => f.reset())to regenerate field array entries, while the non-force path throughsetValuesdid.forceSetValuesto match the behavior ofsetValues.Test plan
useFieldArray.spec.tsthat reproduces the scenario: push items, reset with force, push again, reset again — verifying the second reset also correctly removes extra field array entries.🤖 Generated with Claude Code