Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): clear errorSourceMap.onMount alongside errorMap.onMount #2362

Openalliasgher(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2362/headopened

🎯 Changes

Fixes #2294.

FormApi.setFieldValue clears errorMap.onMount on the field's meta but leaves errorSourceMap.onMount untouched, so field.state.meta.errorSourceMap.onMount keeps reporting a source ('field' or 'form') for an error that no longer exists in errorMap. Every other field-meta write in FormApi.ts updates the two maps together, so this reads as an omission rather than intent.

This adds the matching errorSourceMap update inside the same setFieldMeta call, and two regression tests in FormApi.spec.ts covering the 'field' source (field-level onMount validator) and the 'form' source (form-level onMount validator emitting a field error).

alpha is not affected: errorSourceMap does not appear in any package on that branch, so there is nothing to port to v2.

Note that #2245 edits the same block for an unrelated reason. There is no functional overlap; happy to rebase if it lands first.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Clearing a field value now consistently removes its initial validation errors, including errors originating from field- or form-level validation.
    • Updated field state now stays synchronized after values are changed.
    1. Review Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 533bc64b-7798-4859-a71e-706df265d339

      📥 Commits

      Reviewing files that changed from the base of the PR and between 57a855b42b9b99cee5ca12890b70c7df84e2982c and ec0512d8000293d1b1b2a766e4f96b15eefd4de5.

      📒 Files selected for processing (3)
      • .changeset/olive-forms-clear.md
      • packages/form-core/src/FormApi.ts
      • packages/form-core/tests/FormApi.spec.ts

      Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


      📝 Walkthrough

      Walkthrough

      setFieldValue now clears errorSourceMap.onMount together with errorMap.onMount. Tests cover field-sourced and form-sourced errors. A changeset records a patch release for @tanstack/form-core.

      Changes

      Form error clearing

      Layer / File(s)Summary
      Synchronize onMount error metadata
      packages/form-core/src/FormApi.ts, .changeset/olive-forms-clear.md
      setFieldValue clears errorSourceMap.onMount when it clears errorMap.onMount. The changeset records a patch release.
      Validate field and form error sources
      packages/form-core/tests/FormApi.spec.ts
      Tests verify that field-sourced and form-sourced onMount errors and source markers clear after setting a field value.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Merge Risk: ⚪ Minimal · up to ec051

      This localized change clears stale field-error source metadata alongside the error itself and adds regression coverage for both supported sources; no actionable merge-blocking risk remains.

      Suggested reviewers: pascalmh

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the primary fix: clearing errorSourceMap.onMount with errorMap.onMount.
      Description check✅ PassedThe description follows the required template. It explains the change, references issue #2294, documents testing, and confirms the changeset.
      Linked Issues check✅ PassedThe implementation satisfies issue #2294 by clearing errorSourceMap.onMount in setFieldValue and adding regression tests for field-level and form-level error sources.
      Out of Scope Changes check✅ PassedThe changes are limited to the reported bug, regression tests, and the required changeset. No unrelated code changes are present.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      Full details: Docstring Coverage

      Explanation

      No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. Fix looks right for #2294. I traced the other field-meta writes to check the "every other write updates both maps together" claim: FieldApi.ts:889-890, 1324-1328, 1362-1366, 1561-1566 all pair errorMap with errorSourceMap, and FormApi.ts:2073-2077, 2289-2293, 2992-2996 do too. So setFieldValue was the one field-level omission and this closes it.

      One spot that stays asymmetric after this PR: FormApi.ts:1566, errorMap = Object.assign(errorMap, { onMount: undefined }) in the base-store derived state (shouldInvalidateOnMount branch). That clears the form-level errorMap.onMount with no matching errorSourceMap write. It's only fine if the form-level base store has no errorSourceMap field at all (the errorSourceMap writes I found are all field-meta, none form-level). Could you confirm that's the case, so it's clear this isn't a second instance of the same bug one scope up? Separately, that line mutates currBaseStore.errorMap in place rather than copying, which is a pre-existing smell in a .state read but not something this PR needs to touch.

    3. Confirmed, errorSourceMap is field-only. BaseFormState has none, so 1566 is fine.

Sign in to join this conversation.