Skip to content

Deleted fields with defaultValue are restored on re-render after deleteField() #1808

@kusiewicz

Description

@kusiewicz

Describe the bug

When calling form.deleteField('fieldName') on a field that has a defaultValue defined, the field is successfully removed from form.state.values. However, after React re-renders, the field automatically reappears with its defaultValue, making it impossible to truly delete fields with default values.

Your minimal, reproducible example

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

Steps to reproduce

  1. Go to the StackBlitz example
  2. Click remove fullname button
  3. Look on live state

Expected behavior

After calling form.deleteField('fieldName'), the field should:

  • Be permanently removed from form.state.values
  • Stay removed even after React re-renders
  • Not be restored by any internal lifecycle methods

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

everywhere

TanStack Form adapter

None

TanStack Form version

1.23.4

TypeScript version

^5

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