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