Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): fix broken sync/async validation state not shifting with array actions (remove,swap,shift,move...) #1324

Closedjuanvilladev(GitHub profile, opens in a new tab)wants to merge 0 commits intomain fromrefs/pull/1324/headopened

Previously we were using a cumulative field errors map maintained at the form api level. This PR removes that data structure in favor of a errorSourceMap data structure that lives within the FieldMeta for each field. This allows shifting/removing/deleting fields to automatically keep the errorSourceMap in sync.

This will fix #1323 and prevent other bugs from being raised around validation not working after other array actions like removing, shifting, swapping, moving, etc...

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

      View your CI Pipeline Execution ↗ for commit 6e7a961591e71ab156d193688dc9729238e2f0cd.

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded2m 28sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded22sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-04-02 00:00:06 UTC

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

      Codecov Report

      Attention: Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.

      Project coverage is 88.88%. Comparing base (4016a2b) to head (5e0f1ef). Report is 1 commits behind head on main.

      Files with missing linesPatch %Lines
      packages/form-core/src/FieldApi.ts87.50%1 Missing :warning:
      Additional details and impacted files
      @@            Coverage Diff             @@
      ##             main    #1324      +/-   ##
      ==========================================
      + Coverage   88.86%   88.88%   +0.01%     
      ==========================================
        Files          28       28              
        Lines        1275     1286      +11     
        Branches      332      340       +8     
      ==========================================
      + Hits         1133     1143      +10     
      - Misses        127      128       +1     
        Partials       15       15              

      :umbrella: View full report in Codecov by Sentry. :loudspeaker: Have feedback on the report? Share it here.

      :rocket: New features to boost your workflow:
      • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
      • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
  • Async validation & sync validation now is fully synced and thoroughly tested with the new errorSourceMap. This reduces the complexity of using the cumulative errors map significantly and fixes all the issues with validations running on the wrong fields when removing/inserting/moving/shifting array fields.

    Please review when you have time!

    Thanks!

  • juanvilladev(GitHub profile, opens in a new tab)commented

    Whoops messed up the rebase, will fix tomorrow

  • Updated! Please review when you have time!

  • Sign in to join this conversation.