setFieldValue clears errorMap.onMount but leaves errorSourceMap.onMount stale
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- frontend
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.
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.
- Dominant language
- TypeScript
- Stars
- 6.7k
- Forks
- 682
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 7
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.
More from TanStack/form
-
Difficulty 2/5 1-2 days Newbie friendliness 72/100
-
area: runtime scope: devtools type: bug v2
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
area: runtime scope: core type: bug v1
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
FormApi: onSubmit/onServer error cleared on any non-matching validation cause, not just 'change' Openv1 v2: needs investigation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
v1 v2: needs investigation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·