Skip to content

Commit

Permalink
chore: fix timeout issues (#990)
Browse files Browse the repository at this point in the history
* chore: fix timeout issues

* ci: apply automated fixes and generate docs

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
crutchcorn and autofix-ci[bot] authored Oct 22, 2024
1 parent e07a6ba commit e4aebbd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/reference/classes/fieldapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ The field state store.

***

### timeoutId
### timeoutIds

```ts
timeoutId: null | Timeout;
timeoutIds: Record<ValidationCause, null | Timeout>;
```

#### Defined in
Expand Down
34 changes: 17 additions & 17 deletions docs/reference/classes/formapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ deleteField<TField>(field): void
#### Defined in
[packages/form-core/src/FormApi.ts:1082](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1082)
[packages/form-core/src/FormApi.ts:1083](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1083)
***
Expand All @@ -147,7 +147,7 @@ Gets the field info of the specified field.
#### Defined in
[packages/form-core/src/FormApi.ts:998](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L998)
[packages/form-core/src/FormApi.ts:999](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L999)
***
Expand All @@ -173,7 +173,7 @@ Gets the metadata of the specified field.
#### Defined in
[packages/form-core/src/FormApi.ts:989](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L989)
[packages/form-core/src/FormApi.ts:990](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L990)
***
Expand All @@ -199,7 +199,7 @@ Gets the value of the specified field.
#### Defined in
[packages/form-core/src/FormApi.ts:982](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L982)
[packages/form-core/src/FormApi.ts:983](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L983)
***
Expand All @@ -217,7 +217,7 @@ Handles the form submission, performs validation, and calls the appropriate onSu
#### Defined in
[packages/form-core/src/FormApi.ts:922](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L922)
[packages/form-core/src/FormApi.ts:923](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L923)
***
Expand Down Expand Up @@ -253,7 +253,7 @@ Inserts a value into an array field at the specified index, shifting the subsequ
#### Defined in
[packages/form-core/src/FormApi.ts:1114](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1114)
[packages/form-core/src/FormApi.ts:1115](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1115)
***
Expand Down Expand Up @@ -305,7 +305,7 @@ Moves the value at the first specified index to the second specified index withi
#### Defined in
[packages/form-core/src/FormApi.ts:1232](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1232)
[packages/form-core/src/FormApi.ts:1233](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1233)
***
Expand Down Expand Up @@ -338,7 +338,7 @@ Pushes a value into an array field.
#### Defined in
[packages/form-core/src/FormApi.ts:1096](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1096)
[packages/form-core/src/FormApi.ts:1097](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1097)
***
Expand Down Expand Up @@ -371,7 +371,7 @@ Removes a value from an array field at the specified index.
#### Defined in
[packages/form-core/src/FormApi.ts:1167](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1167)
[packages/form-core/src/FormApi.ts:1168](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1168)
***
Expand Down Expand Up @@ -407,7 +407,7 @@ Replaces a value into an array field at the specified index.
#### Defined in
[packages/form-core/src/FormApi.ts:1141](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1141)
[packages/form-core/src/FormApi.ts:1142](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1142)
***
Expand Down Expand Up @@ -449,7 +449,7 @@ resetFieldMeta<TField>(fieldMeta): Record<TField, FieldMeta>
#### Defined in
[packages/form-core/src/FormApi.ts:1032](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1032)
[packages/form-core/src/FormApi.ts:1033](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1033)
***
Expand All @@ -471,7 +471,7 @@ Updates the form's errorMap
#### Defined in
[packages/form-core/src/FormApi.ts:1256](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1256)
[packages/form-core/src/FormApi.ts:1257](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1257)
***
Expand Down Expand Up @@ -499,7 +499,7 @@ Updates the metadata of the specified field.
#### Defined in
[packages/form-core/src/FormApi.ts:1017](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1017)
[packages/form-core/src/FormApi.ts:1018](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1018)
***
Expand Down Expand Up @@ -532,7 +532,7 @@ Sets the value of the specified field and optionally updates the touched state.
#### Defined in
[packages/form-core/src/FormApi.ts:1056](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1056)
[packages/form-core/src/FormApi.ts:1057](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1057)
***
Expand Down Expand Up @@ -568,7 +568,7 @@ Swaps the values at the specified indices within an array field.
#### Defined in
[packages/form-core/src/FormApi.ts:1206](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1206)
[packages/form-core/src/FormApi.ts:1207](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L1207)
***
Expand Down Expand Up @@ -645,7 +645,7 @@ Validates the children of a specified array in the form starting from a given in
#### Defined in
[packages/form-core/src/FormApi.ts:610](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L610)
[packages/form-core/src/FormApi.ts:611](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L611)
***
Expand Down Expand Up @@ -673,4 +673,4 @@ Validates a specified field in the form using the correct handlers for a given v
#### Defined in
[packages/form-core/src/FormApi.ts:649](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L649)
[packages/form-core/src/FormApi.ts:650](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi.ts#L650)
10 changes: 5 additions & 5 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export class FieldApi<
* @private
*/
prevState!: FieldState<TData>
timeoutId: ReturnType<typeof setTimeout> | null
timeoutIds: Record<ValidationCause, ReturnType<typeof setTimeout> | null>

/**
* Initializes a new `FieldApi` instance.
Expand All @@ -448,7 +448,7 @@ export class FieldApi<
) {
this.form = opts.form as never
this.name = opts.name as never
this.timeoutId = null
this.timeoutIds = {} as Record<ValidationCause, never>
if (opts.defaultValue !== undefined) {
this.form.setFieldValue(this.name, opts.defaultValue as never, {
dontUpdateMeta: true,
Expand Down Expand Up @@ -892,11 +892,11 @@ export class FieldApi<
let rawError!: ValidationError | undefined
try {
rawError = await new Promise((rawResolve, rawReject) => {
if (this.timeoutId) {
clearTimeout(this.timeoutId)
if (this.timeoutIds[validateObj.cause]) {
clearTimeout(this.timeoutIds[validateObj.cause]!)
}

this.timeoutId = setTimeout(async () => {
this.timeoutIds[validateObj.cause] = setTimeout(async () => {
if (controller.signal.aborted) return rawResolve(undefined)
try {
rawResolve(
Expand Down
1 change: 1 addition & 0 deletions packages/form-core/src/FormApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ export class FormApi<
const fieldInstance = field.instance
// Validate the field
fieldValidationPromises.push(
// Remember, `validate` is either a sync operation or a promise
Promise.resolve().then(() => fieldInstance.validate(cause)),
)
// If any fields are not touched
Expand Down

0 comments on commit e4aebbd

Please sign in to comment.