From 5489231540c2c33266f860811f3ab08df765a80d Mon Sep 17 00:00:00 2001 From: Maks Pikov Date: Tue, 21 Apr 2026 22:13:10 +0000 Subject: [PATCH] fix(form-core): clear stale onMount error on linked-field revalidation --- packages/form-core/src/FieldApi.ts | 48 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts index a064a83de..dbd60a612 100644 --- a/packages/form-core/src/FieldApi.ts +++ b/packages/form-core/src/FieldApi.ts @@ -1735,17 +1735,28 @@ export class FieldApi< // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (field.state.meta.errorMap?.[errorMapKey] !== newErrorValue) { - field.setMeta((prev) => ({ - ...prev, - errorMap: { + field.setMeta((prev) => { + const nextErrorMap = { ...prev.errorMap, [errorMapKey]: newErrorValue, - }, - errorSourceMap: { - ...prev.errorSourceMap, - [errorMapKey]: newSource, - }, - })) + } + // Clear stale onMount error when a later validator confirms the field is valid + if ( + !newErrorValue && + errorMapKey !== 'onMount' && + prev.errorMap.onMount + ) { + nextErrorMap.onMount = undefined + } + return { + ...prev, + errorMap: nextErrorMap, + errorSourceMap: { + ...prev.errorSourceMap, + [errorMapKey]: newSource, + }, + } + }) } if (newErrorValue) { hasErrored = true @@ -1934,13 +1945,22 @@ export class FieldApi< } field.setMeta((prev) => { + const nextErrorMap = { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + ...prev?.errorMap, + [errorMapKey]: newErrorValue, + } + // Clear stale onMount error when a later validator confirms the field is valid + if ( + !newErrorValue && + errorMapKey !== 'onMount' && + prev.errorMap.onMount + ) { + nextErrorMap.onMount = undefined + } return { ...prev, - errorMap: { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - ...prev?.errorMap, - [errorMapKey]: newErrorValue, - }, + errorMap: nextErrorMap, errorSourceMap: { ...prev.errorSourceMap, [errorMapKey]: newSource,