Skip to content

Commit c526378

Browse files
fix(form-core): Prevent runtime errors during validation (#1948)
* chore(form-core): use conditional chains again * Fix runtime errors in form-core validation Prevent runtime errors that occur during form validation in the form-core package. * ci: apply automated fixes and generate docs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent d2ae76a commit c526378

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.changeset/dull-bees-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/form-core': patch
3+
---
4+
5+
fix(form-core): Prevent runtime errors during validation

packages/form-core/src/FormApi.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,8 +1696,11 @@ export class FormApi<
16961696
determineFormLevelErrorSourceAndValue({
16971697
newFormValidatorError,
16981698
isPreviousErrorFromFormValidator:
1699-
currentErrorMapSource[errorMapKey] === 'form',
1700-
previousErrorValue: currentErrorMap[errorMapKey],
1699+
// These conditional checks are required, otherwise we get runtime errors.
1700+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1701+
currentErrorMapSource?.[errorMapKey] === 'form',
1702+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1703+
previousErrorValue: currentErrorMap?.[errorMapKey],
17011704
})
17021705

17031706
if (newSource === 'form') {
@@ -1707,7 +1710,9 @@ export class FormApi<
17071710
}
17081711
}
17091712

1710-
if (currentErrorMap[errorMapKey] !== newErrorValue) {
1713+
// This conditional check is required, otherwise we get runtime errors.
1714+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1715+
if (currentErrorMap?.[errorMapKey] !== newErrorValue) {
17111716
this.setFieldMeta(field, (prev = defaultFieldMeta) => ({
17121717
...prev,
17131718
errorMap: {

0 commit comments

Comments
 (0)