Skip to content

removeFieldValue + pushFieldValue not properly deleting values #1840

@skeadr

Description

@skeadr

Describe the bug

I'm not 100% that this is a bug, but the behaviour is counter intuitive for me at least.

I have an array of objects in my data structure and show their values via form.Field mode="array" with useFieldContext.
When I delete an existing entry and add a new entry with undefined properties, properties from the deleted row are used.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-idrzagoh?file=src%2Fminimal.tsx

Steps to reproduce

Click the last row to remove it.
Click add.

Un/Comment lines 15-18.
Lines commented with "works fine" will display the empty value.
Lines commented with "does not work" will display the value from the previously removed row.

Expected behavior

I'd expect that the newly added row is empty, even if their properties are undefined.

How often does this bug happen?

Always

Platform

See Stackblitz example

TanStack Form version

1.23.8

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