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

index.ts

32 lines981 Bytes

1import { schemaErrorsOnUnmountedDescendants } from './schemaErrorsOnUnmountedDescendants'
2import { validatorsWithoutTriggers } from './validatorsWithoutTriggers'
3import type { FieldDebugCase, FieldDebugCaseContext } from './types'
4import type { FieldDebugSuspicion } from '../../../eventClientTypes'
5​
6export type { FieldDebugCase } from './types'
7​
8const fieldDebugCases = [
9 schemaErrorsOnUnmountedDescendants,
10 validatorsWithoutTriggers,
11] satisfies ReadonlyArray<FieldDebugCase>
12​
13export function getFieldDebugSuspicions(
14 context: FieldDebugCaseContext,
15 cases: ReadonlyArray<FieldDebugCase> = fieldDebugCases,
16): Array<FieldDebugSuspicion> {
17 if (
18 !context.field._isMounted ||
19 context.field.state.meta.original.errors.length > 0
20 ) {
21 return []
22 }
23​
24 const suspicions: Array<FieldDebugSuspicion> = []
25​
26 for (const debugCase of cases) {
27 const suspicion = debugCase.evaluate(context)
28 if (suspicion) suspicions.push(suspicion)
29 }
30​
31 return suspicions