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 (#962)
  • Loading branch information
rjsdnql123 authored Oct 22, 2024
1 parent ebb6a3e commit 5e22635
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 5e22635

Please sign in to comment.