Skip to content
Source
Sign inSign up
TanStack/form

[v2] A synchronous change validator renders its field twice per keystroke #2446

OpenTarekkharsa(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

On the v2 alpha, a field with a synchronous change validator renders about twice per keystroke:

  • once for the new value, with meta.isValidating: true;
  • then again a microtask later, with the validation result and isValidating: false.

The same field without a validator renders once per keystroke, and on 1.33.5 a validated field renders once too.

This happens for a plain function validator and for a Standard Schema that validates synchronously. In the repro, typing three characters renders the validated field 8 times and the unvalidated field 3 times.

Your minimal, reproducible example

https://github.com/Tarekkharsa/tanstack-form-v2-sync-validation-double-render-repro

Steps to reproduce

  1. Clone the repro, then run pnpm i and pnpm test.
  2. The test builds a Vite app with the same three fields on v1 (1.33.5) and on v2 (2.0.0-alpha.3):
    • no validator;
    • a sync function validator;
    • a sync z.string().min(2) schema.
  3. It types abc into each field and counts renders.

Output:

@tanstack/react-form 1.33.5
  ok   no validator                     3 renders for 3 keystrokes
  ok   sync function validator          3 renders for 3 keystrokes
  ok   sync Standard Schema validator   3 renders for 3 keystrokes
@tanstack/react-form 2.0.0-alpha.3
  ok   no validator                     3 renders for 3 keystrokes
  FAIL sync function validator          8 renders for 3 keystrokes
  FAIL sync Standard Schema validator   8 renders for 3 keystrokes

Expected behavior

A field with a synchronous change validator renders as often as the same field without one, with the validation result in the same render as the value, as on 1.33.5.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • macOS
  • Chromium (Playwright 1.62.1)
  • React 19.2.8
  • Vite 8.3.1

TanStack Form adapter

react-form

TanStack Form version

2.0.0-alpha.3 (also on alpha at 3545d8c)

TypeScript version

5.9

Additional context

Every step of change and blur validation is asynchronous, even when nothing in it is:

  • executeValidator (form-core/src/validation/execution.lib.ts) is async, and parseStandardSchema wraps the schema result in Promise.resolve(...).
  • runMaybeDebouncedValidator always goes through Promise.race in executeWithAbort.
  • runValidatorPipeline (pipeline.lib.ts) awaits every result before calling onResult.
  • FieldApi._runFieldValidation lowers the validation count in a finally after await.

Mount validation already handles this. _runMountValidation and runFieldMountValidatorPipeline apply synchronous results synchronously through isPromiseLike. Applying the same pattern to change and blur validation brings v2 back to one render per keystroke in the repro, even when only @tanstack/form-core is overridden. I'm opening a PR with that change.

  1. The pipeline will be adjusted anyways, so this is good to keep in mind when refactoring it.

Sign in to join this conversation.