Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#2,427 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@fenet-as is already working on this.

Since Oct 12, 2026.

  • #2429 by @fenet-as — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
frontend

Research direction

Read the default-value derivation in packages/form-core/src/FormApi.ts around the linked lines 1236–1241, then compare it with the field-level default handling described for FieldApi and form.reset(). Reproduce the issue with the TypeScript snippet using @tanstack/form-core. Done means isDefaultValue is true exactly for the value reset restores, including when the field default is null.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
6.7k
Forks
693
Avg merge
1d 9h
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TanStack/form

All issues in TanStack/form

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.