TanStack / TanStack/form

form.setFieldValue on an un-initialized field will create meta missing errors

Open
#1,078 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question v1 v2
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

Describe the bug

If you have a field that is displayed conditionally in the form, and use form.setFieldValue without dontUpdateMeta: true before it's initialization, it will create meta for this field without errors. I understand that makes more sense to update the value with dontUpdateMeta: true if the field wasn't initialized yet, but it can lead to some inconsistent behavior since we are not expecting errors to be undefined.

Your minimal, reproducible example

https://codesandbox.io/p/github/sinuheshinbr/tanstack-form-missing-errors/main?workspaceId=ws_NWHNzLQ8YDitxFDjr6vrpe

Steps to reproduce

go to: https://codesandbox.io/p/github/sinuheshinbr/tanstack-form-missing-errors/main?workspaceId=ws_NWHNzLQ8YDitxFDjr6vrpe
click on "setFieldValue"
then clikc on "Show"

Expected behavior

After clicking on setFieldValue meta shold include errors array even before the element initialization

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

OS: Manjaro Linux
Browser: Chrome
Version: 129.0.6668.100

TanStack Form adapter

react-form

TanStack Form version

0.40.2

TypeScript version

5.5.3

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the linked CodeSandbox and the react-form adapter, following the setFieldValue and conditional Show steps. Inspect the metadata update path for an uninitialized field, including the dontUpdateMeta option. Done means meta includes an errors array after setFieldValue and before the field is initialized.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.