setFieldValue clears errorMap.onMount but leaves errorSourceMap.onMount stale
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 682
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 7
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in FormApi.ts at setFieldValue, where the field metadata clears errorMap.onMount. Reproduce the stale-state case with the FormApi and FieldApi setup described in the issue, then verify that changing the field value clears both errorMap.onMount and errorSourceMap.onMount.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100