11import toChildrenArray from 'rc-util/lib/Children/toArray' ;
22import warning from 'rc-util/lib/warning' ;
3+ import isEqual from 'rc-util/lib/isEqual' ;
34import * as React from 'react' ;
45import type {
56 FieldEntity ,
@@ -54,6 +55,8 @@ interface ChildProps {
5455 [ name : string ] : any ;
5556}
5657
58+ export type MetaEvent = Meta & { destroy ?: boolean } ;
59+
5760export interface InternalFieldProps < Values = any > {
5861 children ?:
5962 | React . ReactElement
@@ -77,7 +80,7 @@ export interface InternalFieldProps<Values = any> {
7780 messageVariables ?: Record < string , string > ;
7881 initialValue ?: any ;
7982 onReset ?: ( ) => void ;
80- onMetaChange ?: ( meta : Meta & { destroy ?: boolean } ) => void ;
83+ onMetaChange ?: ( meta : MetaEvent ) => void ;
8184 preserve ?: boolean ;
8285
8386 /** @private Passed by Form.List props. Do not use since it will break by path check. */
@@ -221,10 +224,23 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
221224 } ) ) ;
222225 } ;
223226
227+ // Event should only trigger when meta changed
228+ private metaCache : MetaEvent = null ;
229+
224230 public triggerMetaEvent = ( destroy ?: boolean ) => {
225231 const { onMetaChange } = this . props ;
226232
227- onMetaChange ?.( { ...this . getMeta ( ) , destroy } ) ;
233+ if ( onMetaChange ) {
234+ const meta = { ...this . getMeta ( ) , destroy } ;
235+
236+ if ( ! isEqual ( this . metaCache , meta ) ) {
237+ onMetaChange ( meta ) ;
238+ }
239+
240+ this . metaCache = meta ;
241+ } else {
242+ this . metaCache = null ;
243+ }
228244 } ;
229245
230246 // ========================= Field Entity Interfaces =========================
0 commit comments