Skip to content

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

Open
alliasgher wants to merge 1 commit into
TanStack:mainfrom
alliasgher:fix/form-core-clear-error-source-map-onmount
Open

fix(form-core): clear errorSourceMap.onMount alongside errorMap.onMount#2362
alliasgher wants to merge 1 commit into
TanStack:mainfrom
alliasgher:fix/form-core-clear-error-source-map-onmount

Conversation

@alliasgher

@alliasgher alliasgher commented Aug 29, 2026

Copy link
Copy Markdown

🎯 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.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

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 57a855b and ec0512d.

📒 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 name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix: clearing errorSourceMap.onMount with errorMap.onMount.
Description check ✅ Passed The description follows the required template. It explains the change, references issue #2294, documents testing, and confirms the changeset.
Linked Issues check ✅ Passed The 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 ✅ Passed The changes are limited to the reported bug, regression tests, and the required changeset. No unrelated code changes are present.
Docstring Coverage ✅ Passed 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…
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.

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.

setFieldValue clears errorMap.onMount but leaves errorSourceMap.onMount stale

1 participant