@@ -79,6 +79,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
7979 statusIcon : statusIconFromContext ,
8080 errorMessage,
8181 formMapRef,
82+ mountedFieldsRef,
8283 onFormItemValueChange,
8384 } = useFormContext ( ) ;
8485
@@ -435,15 +436,25 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
435436 shouldValidate . current = false ;
436437 shouldEmitChangeRef . current = false ;
437438
438- // remount 场景
439- // 若 store 中已存在有效值,复用它并同步到本地 state
440- // 避免被 initialData / children 默认值抹回
441- const existingStoreValue = has ( form ?. store , fullPath ) ? get ( form ?. store , fullPath ) : undefined ;
442- if ( typeof existingStoreValue !== 'undefined' ) {
443- setFormValue ( existingStoreValue ) ;
439+ // 区分「首次挂载」与「remount 到已有 form」:
440+ // - 首次挂载:mountedFieldsRef 中不含该 fullPath → 用 initialData 初始化 store
441+ // - remount:mountedFieldsRef 中已含该 fullPath → 保留 store 现值(可能是用户输入 / setFieldsValue 写入),
442+ // 避免 Dialog / Popup 等场景下条件渲染引发 FormItem 卸载 → 重挂载时把已修改的字段恢复成 initialData
443+ // FormItem 卸载不从 mountedFieldsRef 中移除,只有 Form 整体 reset 时才清空
444+ const fieldKey = JSON . stringify ( fullPath ) ;
445+ const isRemount = mountedFieldsRef ?. current ?. has ( fieldKey ) ?? false ;
446+ if ( isRemount ) {
447+ const existingStoreValue = has ( form ?. store , fullPath ) ? get ( form ?. store , fullPath ) : undefined ;
448+ if ( typeof existingStoreValue !== 'undefined' ) {
449+ setFormValue ( existingStoreValue ) ;
450+ } else {
451+ set ( form ?. store , fullPath , defaultInitialData ) ;
452+ setFormValue ( defaultInitialData ) ;
453+ }
444454 } else {
445455 set ( form ?. store , fullPath , defaultInitialData ) ;
446456 setFormValue ( defaultInitialData ) ;
457+ mountedFieldsRef ?. current ?. add ( fieldKey ) ;
447458 }
448459
449460 return ( ) => {
0 commit comments