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

fix(form-core): #1182 remove stale form level validation errors. Main… #1186

Conversation

juanvilladev
Copy link
Contributor

@juanvilladev juanvilladev commented Feb 26, 2025

…tain cummulative errorMap instead of snapshot of previous validation cycle.

Problem
Currently, prevFieldsErrorMap, was being assigned to the current validation cycle's newErrorMap see here. This caused issues because when we run the validator we do not receive a value for fields with no errors. This meant that on subsequent validation cycles, when the error was cleared, our prevFieldsErrorMap did NOT have a value for the field thus not clearing the error when this loop executes.

Changes

  1. Renamed prevFieldsErrorMap to cumulativeFieldsErrorMap to better reflect its purpose
  2. Updated JSDoc comments to clearly explain the data structure's role
  3. Update cumulativeFieldsErrorMap as we iterate through the new field errors and through error clearing loops. Ensuring we're accumulating the validations not simply assigning the new field errors like we were before!
  4. Added a test that will explicitly check for the new behavior and tackle the exact example provided on Form-level validation does not always clear errors #1182
  5. Additionally, I made sure that we're setting the map and doing updates within the batch calls to ensure we don't hit weird race conditions.

Previously we would set prevFieldsErrorMap to an empty object if no fieldErrors on current cycle. With these changes now we set it to:

   {
      firstName: {
        onChange: undefined,
      },
      lastName: {
        onChange: undefined,
      },
    }

…rs. Maintain cummulative errorMap instead of snapshot of previous validation cycle.
Copy link

nx-cloud bot commented Feb 26, 2025

View your CI Pipeline Execution ↗ for commit 6edfc44.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 2s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 23s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-01 07:15:38 UTC

Copy link

pkg-pr-new bot commented Feb 26, 2025

Open in Stackblitz

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/lit-form

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

@tanstack/react-form

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

@tanstack/solid-form

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

@tanstack/vue-form

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

commit: 6edfc44

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.50%. Comparing base (0734926) to head (6edfc44).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1186   +/-   ##
=======================================
  Coverage   88.49%   88.50%           
=======================================
  Files          28       28           
  Lines        1252     1253    +1     
  Branches      326      327    +1     
=======================================
+ Hits         1108     1109    +1     
  Misses        129      129           
  Partials       15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@crutchcorn crutchcorn merged commit 30b90a6 into TanStack:main Mar 1, 2025
8 checks passed
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

Successfully merging this pull request may close these issues.

2 participants