Skip to content

Field-level defaultValue overrides Form-level defaultValues (conflicts with Async Initial Values workflow) #1897

@esultanovvalley

Description

@esultanovvalley

Describe the bug

I am encountering an issue where defining a defaultValue at the Field level takes precedence over the defaultValues defined in the useForm hook.

This becomes problematic when trying to follow the "Async Initial Values" documentation. When fetching async data to populate the form's defaultValues, the specific fields ignore that data if they have their own defaultValue prop set, effectively "locking" them to the hardcoded field default instead of updating with the async form data.

Is this expected behavior? If so, it seems to make the Async Initial Values workflow difficult if any fields have local defaults defined.

Your minimal, reproducible example

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

Steps to reproduce

  1. Initialize a form using useForm and provide a set of defaultValues (e.g., { firstName: 'Form Level Default' }).

  2. Render a for that same key (firstName).

  3. Add a defaultValue prop to that component (e.g., defaultValue="Field Level Default").

  4. Render the component.

Expected behavior

I expected the Form-level defaultValues to take precedence, especially when they are populated (either synchronously or asynchronously). The Field-level defaultValue should ideally act as a fallback only if the Form-level value is undefined, or there should be a clear merge strategy documented.

Currently, the Field's local defaultValue overrides the Form's data, making it impossible to seed the field from the Form's state if the Field prop exists.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

OS: Mac
Chrome: Latest

TanStack Form adapter

react-form

TanStack Form version

Latest

TypeScript version

No response

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