Open History to see the last commit
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