Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#2,427 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@fenet-as ya está trabajando en esto.

Desde el 12/10/2026.

  • #2429 de @fenet-as — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript
Área
frontend

Línea de trabajo

Lee la derivación del valor predeterminado en packages/form-core/src/FormApi.ts alrededor de las líneas enlazadas 1236–1241 y compárala con el manejo de valores predeterminados a nivel de campo descrito para FieldApi y form.reset(). Reproduce el problema con el fragmento de TypeScript que usa @tanstack/form-core. Se considera terminado cuando isDefaultValue es true exactamente para el valor que restaura reset, incluso cuando el valor predeterminado del campo es null.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
6.7k
Forks
693
Merge medio
1 d 9 h
PR fusionados (30 d)
12

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/form

Todos los issues de TanStack/form

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.