Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assign distinct initial values to both errors and warnings to prevent isEqual from encountering circular references #650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -264,7 +265,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 @@ -276,7 +277,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 @@ -313,7 +314,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 @@ -467,7 +468,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