fix(form-core): prevent runtime errors when using `deleteField` #1706
main fromrefs/pull/1706/head·merged by LeCarbonator(GitHub profile, opens in a new tab) During implementing this and testing deleteField I found out that this method does not work.
When a form field has onChange validation and the deleteField method is called on it, an error appears.
FormApi.ts:1586 Uncaught TypeError: Cannot read properties of undefined (reading 'errorMap')
at FormApi.ts:1586:27
at functionalUpdate (utils.ts:26:8)
at FormApi.ts:2058:20
error: https://bolt.new/~/vitejs-vite-ceu2fl73
I think flow look like this:
- Remove button click =>
form.deleteField('firstName'). - Delete function changes
valuessoonChangevalidator runs. - This validator runs on the form level and still tries to set
errors.fields.email = 'error message'- sovalidateSynctries to update metadata of deleted field. setFieldMetacallsfunctionalUpdatewithundefined(since field does not exists infieldMetaBase).- Updater tries to do
...prevwhereprevnow is undefined -> error.
So validateSync iterates through field list that already semes to be outdated. There is a check if (!fieldMeta) in this function but I guess we have to add as well if (!fieldMetaBase).
- 1
More templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-next-server-actions
- @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-large-form
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@1706@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@1706@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@1706@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@1706@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@1706@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@1706@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@1706@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@1706@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@1706commit:
842956eCodecov Report#
:x: Patch coverage is
75.00000%with1 linein your changes missing coverage. Please review. :white_check_mark: Project coverage is 90.44%. Comparing base (6892ed0) to head (842956e). :warning: Report is 24 commits behind head on main.Files with missing lines Patch % Lines packages/form-core/src/FormApi.ts 75.00% 1 Missing :warning: Additional details and impacted files
@@ Coverage Diff @@ ## main #1706 +/- ## ========================================== + Coverage 90.35% 90.44% +0.09% ========================================== Files 38 38 Lines 1752 1790 +38 Branches 444 453 +9 ========================================== + Hits 1583 1619 +36 - Misses 149 151 +2 Partials 20 20: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.
Please, verify the idea. If I'm thinking in a proper direction I will proceed and add unit tests.
@LeCarbonator? :)
Will try to review this in the coming days
LeCarbonator(GitHub profile, opens in a new tab) approved these changes
I'm not convinced this would be the ideal solution, but this minor fix helps catch the irritating runtime errors. Thanks for the step-by-step explanation!
🦋 Changeset detected#
Latest commit: 842956e56a8c3e94d53f7b2721723818251ab6db
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 9 packages
Name Type @tanstack/form-core Patch @tanstack/angular-form Patch @tanstack/form-devtools Patch @tanstack/lit-form Patch @tanstack/react-form Patch @tanstack/solid-form Patch @tanstack/svelte-form Patch @tanstack/vue-form Patch @tanstack/react-form-devtools Patch Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
LeCarbonator(GitHub profile, opens in a new tab) changed the title
LeCarbonator(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit 842956e56a8c3e94d53f7b2721723818251ab6db
nx affected --targets=test:sherif,test:knip,tes...nx run-many --target=build --exclude=examples/**☁️ Nx Cloud last updated this comment at
2025-10-07 06:01:31UTC