Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

schemaErrorOnUnmountedField.ts

28 lines781 Bytes

1import { visitFieldAndAncestors } from '@tanstack/form-core/internals'
2import type { FieldErrorDebugCase } from './types'
3​
4export const schemaErrorOnUnmountedField = {
5 evaluate: ({ field, error }) => {
6 if (field._isMounted || error.source.validatorType !== 'schema') {
7 return undefined
8 }
9​
10 let mountedAncestorPath: string | undefined
11 visitFieldAndAncestors(field, (candidate, stop) => {
12 if (candidate === field || !candidate._isMounted) return
13​
14 mountedAncestorPath = candidate.name
15 return stop
16 })
17​
18 if (!mountedAncestorPath) return undefined
19​
20 return {
21 kind: 'schema-error-on-unmounted-field',
22 evidence: {
23 fieldPath: field.name,
24 mountedAncestorPath,
25 },
26 }
27 },
28} satisfies FieldErrorDebugCase