Skip to content

Commit

Permalink
fix(core): Fixed issue with multiple validation triggers and resolved…
Browse files Browse the repository at this point in the history
… setTimeout memory leak
  • Loading branch information
rjsdnql123 authored Sep 30, 2024
1 parent 3fee560 commit 1c40241
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export class FieldApi<
* @private
*/
prevState!: FieldState<TData>
timeoutId: ReturnType<typeof setTimeout> | null

/**
* Initializes a new `FieldApi` instance.
Expand All @@ -447,7 +448,7 @@ export class FieldApi<
) {
this.form = opts.form as never
this.name = opts.name as never

this.timeoutId = null
if (opts.defaultValue !== undefined) {
this.form.setFieldValue(this.name, opts.defaultValue as never, {
dontUpdateMeta: true,
Expand Down Expand Up @@ -891,7 +892,11 @@ export class FieldApi<
let rawError!: ValidationError | undefined
try {
rawError = await new Promise((rawResolve, rawReject) => {
setTimeout(async () => {
if (this.timeoutId) {
clearTimeout(this.timeoutId)
}

this.timeoutId = setTimeout(async () => {
if (controller.signal.aborted) return rawResolve(undefined)
try {
rawResolve(
Expand Down

0 comments on commit 1c40241

Please sign in to comment.