fix(form-core): don't throw when a group validator errors an unmounted field #2233
main fromrefs/pull/2233/head·merged by crutchcorn(GitHub profile, opens in a new tab) FormGroupApi.distributeFieldErrors throws TypeError: Cannot read properties of undefined (reading 'errorMap') when a FormGroup validator returns { fields } errors for a sub-field that is not mounted yet (no fieldMetaBase entry). This happens in multi-step forms where each step is a FormGroup and fields render progressively.
setFieldMeta's updater is invoked with prev.fieldMetaBase[field], which is undefined for a never-mounted field. The fix defaults the updater parameter to defaultFieldMeta ((prev = defaultFieldMeta) => ...), mirroring the same fix already applied in FormApi.ts for this bug class (#1706, #2056). The distributed error is stored and surfaces correctly when the field later mounts.
Added a FormGroupApi.spec.ts case: a group validator returns errors for an unmounted field, validate runs, and it must not throw. It throws the reported TypeError without the fix and passes with it. Full form-core suite (499 tests) and type tests pass, eslint and tsc clean.
Closes #2231
Summary by CodeRabbit#
Bug Fixes
- Fixed an issue where form group validation could fail when errors were returned for a field that had not been mounted yet.
- Error handling now works more reliably for fields that mount after validation, so previously hidden errors appear correctly once the field is available.
Tests
- Added coverage for mounting fields after group validation to ensure errors are distributed as expected.
- 1
View your CI Pipeline Execution ↗ for commit 16e2f941ab79f98e5fd3499ef6654a9b428bc758
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 36s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 40s View ↗
☁️ Nx Cloud last updated this comment at
2026-07-09 09:41:58UTCMore templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-multi-step-wizard
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-large-form
- @tanstack/form-example-lit-multi-step-wizard
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-preact-multi-step-wizard
- @tanstack/form-example-preact-simple
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-composition
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/form-example-react-expo
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-multi-step-wizard
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-next-server-actions-zod
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-remix
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-devtools
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-multi-step-wizard
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-large-form
- @tanstack/form-example-svelte-multi-step-wizard
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-multi-step-wizard
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2233@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2233@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2233@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2233@tanstack/preact-form
npm i https://pkg.pr.new/@tanstack/preact-form@2233@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2233@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2233@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2233@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@2233@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2233@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2233@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2233@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2233@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2233commit:
16e2f94:warning: Please install the
to ensure uploads and comments are reliably processed by Codecov.
Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.71%. Comparing base (
6892ed0) to head (16e2f94). :warning: Report is 238 commits behind head on main. :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.Additional details and impacted files
@@ Coverage Diff @@ ## main #2233 +/- ## ========================================== - Coverage 90.35% 89.71% -0.64% ========================================== Files 38 65 +27 Lines 1752 3200 +1448 Branches 444 806 +362 ========================================== + Hits 1583 2871 +1288 - Misses 149 295 +146 - Partials 20 34 +14:umbrella: View full report in Codecov by Harness. :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.
crutchcorn(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
961478ce-ac3b-4554-b510-b480b6066c76📥 Commits
Reviewing files that changed from the base of the PR and between 6a73479f2c2659550a6c8b456e3e139bf0d2142e and f7e12e5a6ef3ab4d8af7e628379547bcd65f6095.
📒 Files selected for processing (3)
.changeset/fix-formgroup-distribute-unmounted-field.mdpackages/form-core/src/FormGroupApi.tspackages/form-core/tests/FormGroupApi.spec.ts📝 Walkthrough
Walkthrough#
Fixes a TypeError in FormGroupApi.distributeFieldErrors that occurred when a group validator returned errors for a field not yet mounted, by defaulting the previous field meta to defaultFieldMeta. Adds a regression test and a changeset entry.
Changes#
FormGroupApi Unmounted Field Fix
packages/form-core/src/FormGroupApi.tssetFieldMetaupdater indistributeFieldErrorsnow defaultsprevtodefaultFieldMetawhen undefined, preventing aTypeErrorwhen mergingerrorMap/errorSourceMapfor unmounted fields.packages/form-core/tests/FormGroupApi.spec.ts,.changeset/fix-formgroup-distribute-unmounted-field.mdmount()does not throw when a group validator returns errors for an unmounted field and that the error surfaces once the field mounts; adds a changeset entry documenting the patch.Estimated code review effort: 1 (Trivial) | ~5 minutes
Sequence Diagram(s)#
Related issues:
#2231(FormGroup validator returning sub-field errors for unmounted fields throws "Cannot read properties of undefined (reading 'errorMap')")Suggested labels: bug, form-core, patch
Suggested reviewers: none identified from provided context
🐰 A field not yet born, no meta to its name, The validator scolds it just the same, Now defaults step in, no more the crash, Errors wait patiently till the field's next flash.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#2231by defaulting missing meta and preventing the unmounted-field crash.✨ Finishing Touches
🧪 Generate unit tests (beta)
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