Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields re-render twice on each keystroke, based on validation state #1130

Open
aditya-lenze opened this issue Jan 27, 2025 · 0 comments
Open

Comments

@aditya-lenze
Copy link

Describe the bug

While trying out the Simple example on the website in the docs, as well as locally, I stumbled upon the following behavior, which I am finding difficult to reason about:

  • If there is a validation defined on the Field, it renders once on each onChange, as long as the data is invalid.
    • Once the data becomes valid, it starts rendering twice on each keystroke.
  • If there is no validation defined, the Field renders twice on each keystroke.

Please note that:

  • React.strictMode, which runs all effects twice, is not used.
  • Renders are measured using a simple RenderCount component and console.log, both of which are in the CSB link below.
  • This is issue is not linked to the number of inputs. For example, even with 3, 4, 5 inputs, the re-render occurs twice.

CSB details:

  • Contains two fields, firstName and lastName.
  • firstName has no validation defined.
  • lastName has a validation of minimum length: 5.

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/great-yonath-3z6vqt

Steps to reproduce

  1. Go to the CSB link.
  2. Try typing a firstName, observe the render count and console.logs. They should increment by two each time.
  3. Try typing a lastName. As long as it is invalid and error message is displayed, it will render once on each keystroke. Once length > 5, and input is valid, it will start re-rendering twice.

Expected behavior

  • I would expect that the inputs are re-rendered only once on each keystroke, instead of two.
  • This problem becomes peculiar when paired with validation, i.e., the issue happens only if the field is valid or no validation defined.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: 131.0.6778.265

TanStack Form adapter

react-form

TanStack Form version

0.41.3

TypeScript version

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant