Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`isDefaultValue` is wrong when a field-level `defaultValue` is `null`

Aperta Adatta ai principianti
#2,427 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@fenet-as ci sta già lavorando.

Dal 12/10/2026.

  • #2429 di @fenet-as — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

Leggi la derivazione del valore predefinito in packages/form-core/src/FormApi.ts intorno alle righe 1236–1241 del collegamento, poi confrontala con la gestione dei valori predefiniti a livello di campo descritta per FieldApi e form.reset(). Riproduci il problema con lo snippet TypeScript che usa @tanstack/form-core. Il lavoro è concluso quando isDefaultValue è true esattamente per il valore ripristinato da reset, anche quando il valore predefinito del campo è null.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

When a field has defaultValue: null and the form-level default for that field is anything other than null (missing, undefined, or a different value), isDefaultValue does not match what form.reset() restores:

  • The field holds its default (null) but field.state.meta.isDefaultValue and form.state.isDefaultValue are false, right after mount and after form.reset().
  • Setting the value to the form-level default (or to undefined when there is none) reports isDefaultValue: true, although form.reset() then changes the value back to null.

Field-level defaults of 0, false, '' or any non-null value work as expected.

Your minimal, reproducible example

The snippet under "Steps to reproduce" is self-contained and only needs @tanstack/form-core.

Steps to reproduce
import { FieldApi, FormApi } from '@tanstack/form-core'

const form = new FormApi({
  defaultValues: { name: 'form' as string | null },
})
form.mount()

const field = new FieldApi({ form, name: 'name', defaultValue: null })
field.mount()

console.log(field.state.value, field.state.meta.isDefaultValue)
// null false   (expected: null true)

field.setValue('form')
console.log(field.state.meta.isDefaultValue)
// true         (expected: false)

form.reset()
console.log(field.state.value, field.state.meta.isDefaultValue)
// null false   (expected: null true)

Without a form-level default for the field (defaultValues: {} as { name?: string | null }), the result is the same, and field.setValue(undefined) reports isDefaultValue: true.

Expected behavior

isDefaultValue should be true exactly when the current value is the one form.reset() restores, as established in #1973 and #2006. With a field-level defaultValue: null that value is null.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS, reproduced in Node with Vitest (no browser involved)

TanStack Form adapter

vanilla

TanStack Form version

v1.33.5

TypeScript version

v5.9.3

Additional context

The derivation resolves the default with fieldDefault ?? formDefault, so a field-level null falls through to the form-level default:
https://github.com/TanStack/form/blob/2216fdedf0a5ff17e4ef8567e1321442639b96ca/packages/form-core/src/FormApi.ts#L1236-L1241

form.reset() and FieldApi treat a field-level default as set when it is !== undefined, so null is applied as a default there. This was introduced in #2006 (1.32.0) and noted in an unanswered review comment: https://github.com/TanStack/form/pull/2006#discussion_r3215386716

Related: #2425 fixes the same ?? in resetField. This issue is separate, since it also affects mount and form.reset().

Happy to open a PR if a fix is wanted on the 1.x line.

Lingua principale
TypeScript
Stelle
6.7k
Fork
695
Merge medio
1g 9h
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/form

Tutte le issue di TanStack/form

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.