-
-
Notifications
You must be signed in to change notification settings - Fork 523
Open
Description
Describe the bug
When calling field.handleChange(undefined)
in a framework, it will revert the field's value back to the default value after 1 rerender. It is because the .update()
method will overwrite undefined
.
- Since it occurs in
FieldApi.update
, this error does not happen in form-core, but in framework adapters. - Calling
field.handleChange(null)
works as expected. - If the default value is also
undefined
, the change is unnoticeable.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-wbyrntnr?file=src%2FApp.tsx
Steps to reproduce
- There are two checkboxes per type of form (AppForm, Form)
- Uncheck the first one to set the value to
undefined
. It will revert to the default value instead ofundefined
. - Uncheck the second one to set the value to
null
. It properly sets the value tonull
.
Expected behavior
As a user, I expect to be able to use undefined
as an override value regardless of what the default Value is. Use cases include:
- Libraries such as
react-day-picker
which useundefined
instead ofnull
as their state - Personal implementations that use
undefined
, such as optional select menus.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
It's related to the library itself, so the browser or framework has no impact.
TanStack Form adapter
None
TanStack Form version
v1.14.1
TypeScript version
v5.8.3
Additional context
Unit tests for adapters are lackluster. Simply removing the 'faulty' block on its own will not do. Make sure you don't accidentally break something else.
Jaime02, romulovalez, jwesselink and nshaikhinurov
Metadata
Metadata
Assignees
Labels
No labels