Describe the bug#
When removing array elements, currently subfields with falsy values on the last row are being changed to undefined. Added a condition to specifically check for undefined.
This is critical as the casting converting booleans or empty strings to undefined leads to uncontrolled inputs in React and overall strange behavior regarding validators that expect particular value types.
Your minimal, reproducible example#
https://stackblitz.com/edit/vitejs-vite-6huqeq8i?file=src%2FApp.tsx,src%2Fcomponents%2FForm.tsx
Steps to reproduce#
- Click the push value button twice so you have three rows.
- Click the Log button and inspect the console.
- Notice that interests logs:
[
{
"id": "01965a86-4995-768a-85b9-be02512c2208",
"interestName": ""
},
{
"id": "01965a86-4ab7-751b-9368-8ce7539f2e49"
"interestName": undefined
}
]
interestName is now missing! It was overwritten as undefined
Expected behavior#
Falsy values remain stable after removing field value.
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
Replicatable on any code sandbox/React environment
TanStack Form adapter#
react-form
TanStack Form version#
1.6.3
TypeScript version#
5.7.2
Additional context#
No response
Stumbled on the same error while using @tanstack/react-form-nextjs version 1.28.5.
In my case, the
onChangevalidation was triggered when removing item (another bug?), and the value got stuck in validation (it was expecting a boolean).It’s tricky because the UI representation of the item is removed, so there’s nowhere the error can be displayed. You can notice it because form submission is blocked due to the invalid field.
Any updates on this issue? Does anyone have ideas for a temporary workaround?