Describe the bug
FormApi.setFieldValue clears a field's stale onMount error when the field's own value changes, but only clears it from errorMap, not from errorSourceMap, so the two maps can end up out of sync.
// FormApi.ts, setFieldValue
this.setFieldMeta(field, (prev) => ({
...prev,
isTouched: true,
isDirty: true,
errorMap: {
...prev?.errorMap,
onMount: undefined,
},
}))
errorSourceMap.onMount is never touched here. Both maps are surfaced to consumers directly, for example useField in react-form exposes errorSourceMap: reactiveMetaErrorSourceMap as part of field.state.meta alongside errorMap, so this isn't just internal bookkeeping, application code can read meta.errorSourceMap.onMount directly.
After a value change clears a field's onMount error, meta.errorMap.onMount correctly becomes undefined, but meta.errorSourceMap.onMount keeps whatever source ('form' or 'field') was last recorded there. Code that checks errorSourceMap.onMount to decide something (which validator layer an error came from, for instance) would see a source for an error that no longer exists in errorMap.
Steps to reproduce
const form = new FormApi({
defaultValues: { name: '' },
validators: {
onMount: () => 'Required',
},
})
const field = new FieldApi({ form, name: 'name', validators: { onMount: () => 'Required' } })
form.mount()
field.mount()
console.log(field.state.meta.errorMap.onMount) // 'Required'
console.log(field.state.meta.errorSourceMap.onMount) // 'field'
field.setValue('something')
console.log(field.state.meta.errorMap.onMount) // undefined, cleared
console.log(field.state.meta.errorSourceMap.onMount) // still 'field', not cleared
Expected behavior
errorSourceMap.onMount should be cleared alongside errorMap.onMount in setFieldValue, the same way #2244 (currently open) clears both together for the linked-field revalidation case.
Actual behavior
errorSourceMap.onMount is left stale after setFieldValue clears the corresponding errorMap.onMount.
Describe the bug
FormApi.setFieldValueclears a field's staleonMounterror when the field's own value changes, but only clears it fromerrorMap, not fromerrorSourceMap, so the two maps can end up out of sync.errorSourceMap.onMountis never touched here. Both maps are surfaced to consumers directly, for exampleuseFieldinreact-formexposeserrorSourceMap: reactiveMetaErrorSourceMapas part offield.state.metaalongsideerrorMap, so this isn't just internal bookkeeping, application code can readmeta.errorSourceMap.onMountdirectly.After a value change clears a field's
onMounterror,meta.errorMap.onMountcorrectly becomesundefined, butmeta.errorSourceMap.onMountkeeps whatever source ('form'or'field') was last recorded there. Code that checkserrorSourceMap.onMountto decide something (which validator layer an error came from, for instance) would see a source for an error that no longer exists inerrorMap.Steps to reproduce
Expected behavior
errorSourceMap.onMountshould be cleared alongsideerrorMap.onMountinsetFieldValue, the same way #2244 (currently open) clears both together for the linked-field revalidation case.Actual behavior
errorSourceMap.onMountis left stale aftersetFieldValueclears the correspondingerrorMap.onMount.