FormApi: onSubmit/onServer error cleared on any non-matching validation cause, not just 'change'
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- api
Direzione di ricerca
Inizia in packages/form-core/src/FormApi.ts ed esegui la sequenza FormApi/FieldApi fornita, verificando i blocchi che cancellano gli errori di submit e del server durante blur e le altre cause di validazione. Il lavoro è completato quando gli errori di submit e del server rimangono fino a una modifica del valore, mentre il comportamento esistente della validazione di submit continua a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
FormApi's sync validation has the same bug that #2211 is fixing at the field level, just one level up. In packages/form-core/src/FormApi.ts, the block that's supposed to clear a stale onSubmit error "as soon as the user enters a valid value" checks cause !== 'submit' instead of cause === 'change':
const submitErrKey = getErrorMapKey('submit')
if (
this.state.errorMap?.[submitErrKey] &&
cause !== 'submit' &&
!hasErrored
) {
this.baseStore.setState((prev) => ({
...prev,
errorMap: { ...prev.errorMap, [submitErrKey]: undefined },
}))
}
ValidationCause is 'change' | 'blur' | 'submit' | 'mount' | 'server' | 'dynamic', so this clears the submit error on blur, mount, server, and dynamic validation runs too, not just when the user actually changes a value. The comment right above it says the intent is "clear the error as soon as the user enters a valid value in the field", which only 'change' represents.
The exact same block exists again a few lines down for onServer errors, with the same shape (cause !== 'server'), so it has the analogous problem: a server-side error can get cleared by a blur or an unrelated dynamic revalidation instead of only by the user actually changing the value.
I think this is what #1472 was really running into. That issue was closed as a React Native Web quirk (RNW fires a blur event on submit, and blurOnSubmit={false} was suggested as the workaround), but the underlying reason blur clears the error at all is this condition, so the same symptom is reachable on plain web too, any blur on a field with an existing submit error clears it, RNW's extra blur-on-submit event just makes it show up immediately and consistently.
Your minimal, reproducible example
Not a runnable repro since this is internal form-core logic, but here's the sequence that reaches the bug directly through the public API:
const form = new FormApi({ defaultValues: { name: '' } })
form.mount()
const field = new FieldApi({
form,
name: 'name',
validators: { onSubmit: ({ value }) => (value.length > 0 ? undefined : 'required') },
})
field.mount()
await form.handleSubmit() // form.state.errorMap.onSubmit is now set
field.handleBlur() // no value change, just a blur
// form.state.errorMap.onSubmit is cleared here, even though nothing was fixed
Steps to reproduce
- Create a form with an
onSubmitvalidator on a field. - Submit without satisfying the validator so
errorMap.onSubmitgets set. - Blur the field (or trigger any
mount/server/dynamicvalidation) without changing its value. form.state.errorMap.onSubmitis cleared, even though the underlying problem wasn't fixed.
Expected behavior
The submit-level error should only clear when the cause is 'change', matching the comment's stated intent and consistent with how #2211 is fixing the identical check at the field level.
Platform
n/a (form-core logic, framework-agnostic)
TanStack Form version
current main, packages/form-core/src/FormApi.ts
- Lingua principale
- TypeScript
- Stelle
- 6.7k
- Fork
- 682
- Merge medio
- 5g 18h
- PR unite (30g)
- 7
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/form
-
Difficoltà 2/5 1-2 giorni Idoneità per principianti 72/100
-
area: runtime scope: devtools type: bug v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
area: runtime scope: core type: bug v1
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
v1 v2: needs investigation
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
v1 v2: needs investigation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Tutte le issue di TanStack/form
Issue simili
-
Browser Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
getsentry/sentry-javascript#24577 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
agilepathway/label-checker#640 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
copse-dev/agent-pane#2953 ·
-
[aw] Upgrade available Apertaagentic-workflows
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
githubnext/rig#534 ·
-
automation missing-model model-sync provider:pioneer
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
anomalyco/models.dev#7701 ·