Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): don't throw when a group validator errors an unmounted field #2233

Mergedmomomuchu(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2233/headmerged by crutchcorn(GitHub profile, opens in a new tab)

Showing 3 changed files with 49 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-formgroup-distribute-unmounted-field.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+Fix `FormGroupApi.distributeFieldErrors` throwing `TypeError: Cannot read properties of undefined` when a group validator returns errors for a field that is not mounted yet
1 addition and 1 deletionpackages/form-core/src/FormGroupApi.tsModified
View file
@@ -1750,7 +1750,7 @@
continue
- this.form.setFieldMeta(fullName as never, (prev) => ({
+ this.form.setFieldMeta(fullName as never, (prev = defaultFieldMeta) => ({
...prev,
errorMap: {
...prev.errorMap,
43 additions and 0 deletionspackages/form-core/tests/FormGroupApi.spec.tsModified
View file
@@ -542,6 +542,49 @@
expect(step1Group.state.meta.isValid).toBe(false)
​
+ it('Should not throw when a group validator returns field errors for a field that is not mounted yet', () => {
+ const form = new FormApi({
+ defaultValues: {
+ step1: { name: '', unmountedField: '' },
+ step2: { name: 'test2' },