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

schemaErrorsOnUnmountedDescendants.ts

33 lines983 Bytes

1import { visitFieldSubtree } from '@tanstack/form-core/internals'
2import { getDevtoolsFieldErrors } from '../detailSnapshot'
3import type { FieldDebugCase } from './types'
4​
5export const schemaErrorsOnUnmountedDescendants = {
6 evaluate: ({ field }) => {
7 const unmountedDescendantPaths: Array<string> = []
8​
9 visitFieldSubtree(field, (candidate) => {
10 if (candidate === field || candidate._isKilled || candidate._isMounted) {
11 return
12 }
13​
14 const hasSchemaError = getDevtoolsFieldErrors(
15 candidate,
16 candidate.state,
17 'messages',
18 ).some(({ source }) => source.validatorType === 'schema')
19​
20 if (hasSchemaError) unmountedDescendantPaths.push(candidate.name)
21 })
22​
23 if (unmountedDescendantPaths.length === 0) return undefined
24​
25 return {
26 kind: 'schema-errors-on-unmounted-descendants',
27 evidence: {
28 fieldPath: field.name,
29 unmountedDescendantPaths,
30 },
31 }
32 },
33} satisfies FieldDebugCase