1- import * as React from 'react' ;
21import warning from 'rc-util/lib/warning' ;
2+ import * as React from 'react' ;
3+ import { HOOK_MARK } from './FieldContext' ;
34import type {
45 Callbacks ,
56 FieldData ,
67 FieldEntity ,
78 FieldError ,
8- InternalNamePath ,
9+ FormInstance ,
10+ InternalFieldData ,
11+ InternalFormInstance ,
912 InternalHooks ,
13+ InternalNamePath ,
14+ InternalValidateFields ,
15+ Meta ,
1016 NamePath ,
1117 NotifyInfo ,
18+ RuleError ,
1219 Store ,
13- ValidateOptions ,
14- FormInstance ,
15- ValidateMessages ,
16- InternalValidateFields ,
17- InternalFormInstance ,
18- ValidateErrorEntity ,
1920 StoreValue ,
20- Meta ,
21- InternalFieldData ,
21+ ValidateErrorEntity ,
22+ ValidateMessages ,
23+ ValidateOptions ,
2224 ValuedNotifyInfo ,
23- RuleError ,
2425 WatchCallBack ,
2526} from './interface' ;
26- import { HOOK_MARK } from './FieldContext' ;
2727import { allPromiseFinish } from './utils/asyncUtil' ;
28- import NameMap from './utils/NameMap ' ;
28+ import cloneDeep from './utils/cloneDeep ' ;
2929import { defaultValidateMessages } from './utils/messages' ;
30+ import NameMap from './utils/NameMap' ;
3031import {
3132 cloneByNamePathList ,
3233 containsNamePath ,
@@ -36,7 +37,6 @@ import {
3637 setValue ,
3738 setValues ,
3839} from './utils/valueUtil' ;
39- import cloneDeep from './utils/cloneDeep' ;
4040
4141type InvalidateFieldEntity = { INVALIDATE_NAME_PATH : InternalNamePath } ;
4242
@@ -157,7 +157,7 @@ export class FormStore {
157157 private destroyForm = ( ) => {
158158 const prevWithoutPreserves = new NameMap < boolean > ( ) ;
159159 this . getFieldEntities ( true ) . forEach ( entity => {
160- if ( ! entity . isPreserve ( ) ) {
160+ if ( ! this . isMergedPreserve ( entity . isPreserve ( ) ) ) {
161161 prevWithoutPreserves . set ( entity . getNamePath ( ) , true ) ;
162162 }
163163 } ) ;
@@ -604,6 +604,11 @@ export class FormStore {
604604 }
605605 } ;
606606
607+ private isMergedPreserve = ( fieldPreserve ?: boolean ) => {
608+ const mergedPreserve = fieldPreserve !== undefined ? fieldPreserve : this . preserve ;
609+ return mergedPreserve ?? true ;
610+ } ;
611+
607612 private registerField = ( entity : FieldEntity ) => {
608613 this . fieldEntities . push ( entity ) ;
609614 const namePath = entity . getNamePath ( ) ;
@@ -622,10 +627,9 @@ export class FormStore {
622627 // un-register field callback
623628 return ( isListField ?: boolean , preserve ?: boolean , subNamePath : InternalNamePath = [ ] ) => {
624629 this . fieldEntities = this . fieldEntities . filter ( item => item !== entity ) ;
625- // Clean up store value if not preserve
626- const mergedPreserve = preserve !== undefined ? preserve : this . preserve ;
627630
628- if ( mergedPreserve === false && ( ! isListField || subNamePath . length > 1 ) ) {
631+ // Clean up store value if not preserve
632+ if ( ! this . isMergedPreserve ( preserve ) && ( ! isListField || subNamePath . length > 1 ) ) {
629633 const defaultValue = isListField ? undefined : this . getInitialValue ( namePath ) ;
630634
631635 if (
0 commit comments