Skip to content
Source
Sign inSign up
TanStack/form

fix(FieldApi): onChangeListenTo should not block onChangeAsync validator on field it is listening to #1420

OpenPascalmh(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/1420/headopened

    1. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit b627e3dead4de94ed95f74d4b34566d6073bb12d.

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...❌ Failed59sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded<1sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-04-25 11:54:59 UTC

    2. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @tanstack/angular-form

      npm i https://pkg.pr.new/@tanstack/angular-form@1420

      @tanstack/form-core

      npm i https://pkg.pr.new/@tanstack/form-core@1420

      @tanstack/react-form

      npm i https://pkg.pr.new/@tanstack/react-form@1420

      @tanstack/lit-form

      npm i https://pkg.pr.new/@tanstack/lit-form@1420

      @tanstack/solid-form

      npm i https://pkg.pr.new/@tanstack/solid-form@1420

      @tanstack/svelte-form

      npm i https://pkg.pr.new/@tanstack/svelte-form@1420

      @tanstack/vue-form

      npm i https://pkg.pr.new/@tanstack/vue-form@1420

      commit: b627e3d

    3. It appears onBlurListenTo will cause the same issue with onBlurAsync

    4. I believe this error may be related to how linked fields contribute to the hasErrored property.

      Since the linked field errors, it no longer tries to perform the async error of the current field.

    5. I believe this can cause another problem, but I'm not confident I wrote the proper test case for it:

      If two fields share a common onChangeListenTo of a third field, then it could be that the sync error from one affects the async validator from the other.

    6. Running into similar issues with inter-dependant fields.

      new FieldApi({
        name: 'field_1',
        validators: {
          onChangeListenTo: ['field_2', 'field_3'],
          onChangeAsync: async (props) => {
            // magical async stuff
          }
        },
      })
      
      new FieldApi({
        name: 'field_2',
        validators: {
          onChangeListenTo: ['field_1'],
          onChangeAsync: async (props) => {
            // magical async stuff
          }
        },
      })
      
      new FieldApi({
        name: 'field_2',
        validators: {
          onChangeListenTo: ['field_1'],
          onChangeAsync: async (props) => {
            // magical async stuff
          }
        },
      })

      Shifting from using onChangeAsync to the non-async onChange seems to fix the issues... but means we loose async which is not ideal. Will have to do for now.

Sign in to join this conversation.