Skip to content

Falsy values are being turned into undefined upon removing array field #1439

Open
@juanvilladev

Description

@juanvilladev

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

  1. Click the push value button twice so you have three rows.
  2. Click the Log button and inspect the console.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions