-
-
Notifications
You must be signed in to change notification settings - Fork 438
"Cannot read properties of undefined" when removing array field #1323
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
Comments
This commit removes cumulativeFieldsErrorMap in favor of a much simpler validationSourceMap. The validationSourceMap is within the fieldMeta allowing it to shift with array actions. Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates async validators to ensure source map is synced with full coverage. Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
Determined that this issue actually plagues all validations post array shifting/inserting/moving/removing.... I have opened #1324 to resolve this in a much cleaner way. |
I'm having the same issue. |
Hope you guys like this approach, it'll allow us to fix the issue without a breaking change. Long term we may want to update this type though to include the source: export type ValidationErrorMap<
TOnMountReturn = unknown,
TOnChangeReturn = unknown,
TOnChangeAsyncReturn = unknown,
TOnBlurReturn = unknown,
TOnBlurAsyncReturn = unknown,
TOnSubmitReturn = unknown,
TOnSubmitAsyncReturn = unknown,
TOnServerReturn = unknown,
> = {
onMount?: {
error: TOnMountReturn
source: ValidationSource
}
onChange?: {
error: TOnChangeReturn | TOnChangeAsyncReturn
source: ValidationSource
}
onBlur?: {
error: TOnBlurReturn | TOnBlurAsyncReturn
source: ValidationSource
}
onSubmit?: {
error: TOnSubmitReturn | TOnSubmitAsyncReturn
source: ValidationSource
}
onServer?: {
error: TOnServerReturn
source: ValidationSource
}
} This way we minimize the use of memory and have a single source of truth. Once we get closer to V2 I'm happy to implement that if you like it. For now, we the current implementation of a separate errorSourceMap will work without breaking existing usages. |
This commit updates async validators to ensure source map is synced with full coverage. Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates async validators to ensure source map is synced with full coverage. Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates async validators to ensure source map is synced with full coverage. Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates async validators to ensure source map is synced with full coverage. Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates sync and async validation state to shift with FieldMeta Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates sync and async validation state to shift with FieldMeta Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates sync and async validation state to shift with FieldMeta Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
This commit updates sync and async validation state to shift with FieldMeta Fixes "Cannot read properties of undefined" when removing array field TanStack#1323
Describe the bug
When removing elements from array using the removeFieldValue api, we sometimes receive:
I am able to reproduce this when removing an element that contains a field inside that has an error.
At some point in the validation logic triggered within removeFieldValue, we're reaching out to get the errorMap for a field that's undefined at that point.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-ypgebmzr?file=src%2Fcomponents%2FForm.tsx
Steps to reproduce
Simply add a few rows, then delete at least 2. Take a look at the console and you will see:
Notice how when we push rows we are pushing a value that is not valid (per the form level schema) to the interestLevel field. If we were to push a valid value (greater than 5) the issue goes away.
Expected behavior
When I remove an array element, regardless of subfields containing errors or not, we should never be attempting to pull errorMap from undefined (resulting in the error message).
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
React, TypeScript,
TanStack Form adapter
None
TanStack Form version
v1.1.2
TypeScript version
v5.7.2
Additional context
This will affect any users that attempt to use a standard schema validator at form level and attempt to delete a row with subfields containing errors. I'm looking into fixing it already, please assign me the issue if you have access! Thanks!
The text was updated successfully, but these errors were encountered: