Skip to content

Commit

Permalink
fix: assign distinct initial values to both errors and warnings t…
Browse files Browse the repository at this point in the history
…o prevent `isEqual` from encountering circular references (#650)
  • Loading branch information
jackblackevo authored Dec 21, 2024
1 parent f9ac280 commit bccc22a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from './utils/valueUtil';

const EMPTY_ERRORS: any[] = [];
const EMPTY_WARNINGS: any[] = [];

export type ShouldUpdate<Values = any> =
| boolean
Expand Down Expand Up @@ -146,7 +147,7 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
private prevValidating: boolean;

private errors: string[] = EMPTY_ERRORS;
private warnings: string[] = EMPTY_ERRORS;
private warnings: string[] = EMPTY_WARNINGS;

// ============================== Subscriptions ==============================
constructor(props: InternalFieldProps) {
Expand Down Expand Up @@ -268,7 +269,7 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
this.dirty = true;
this.validatePromise = null;
this.errors = EMPTY_ERRORS;
this.warnings = EMPTY_ERRORS;
this.warnings = EMPTY_WARNINGS;
this.triggerMetaEvent();
}

Expand All @@ -280,7 +281,7 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
this.dirty = false;
this.validatePromise = undefined;
this.errors = EMPTY_ERRORS;
this.warnings = EMPTY_ERRORS;
this.warnings = EMPTY_WARNINGS;
this.triggerMetaEvent();

onReset?.();
Expand Down Expand Up @@ -320,7 +321,7 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
this.errors = data.errors || EMPTY_ERRORS;
}
if ('warnings' in data) {
this.warnings = data.warnings || EMPTY_ERRORS;
this.warnings = data.warnings || EMPTY_WARNINGS;
}
this.dirty = true;

Expand Down Expand Up @@ -474,7 +475,7 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
this.validatePromise = rootPromise;
this.dirty = true;
this.errors = EMPTY_ERRORS;
this.warnings = EMPTY_ERRORS;
this.warnings = EMPTY_WARNINGS;
this.triggerMetaEvent();

// Force trigger re-render since we need sync renderProps with new meta
Expand Down

0 comments on commit bccc22a

Please sign in to comment.