@@ -241,21 +241,24 @@ export function useForm<
241241 pathStateExists . multiple = true ;
242242 }
243243
244+ const id = FIELD_ID_COUNTER ++ ;
244245 if ( Array . isArray ( pathStateExists . id ) ) {
245- pathStateExists . id . push ( FIELD_ID_COUNTER ++ ) ;
246+ pathStateExists . id . push ( id ) ;
246247 } else {
247- pathStateExists . id = [ pathStateExists . id , FIELD_ID_COUNTER ++ ] ;
248+ pathStateExists . id = [ pathStateExists . id , id ] ;
248249 }
249250
250251 pathStateExists . fieldsCount ++ ;
252+ pathStateExists . __flags . pendingUnmount [ id ] = false ;
251253
252254 return pathStateExists as PathState < TValue > ;
253255 }
254256
255257 const currentValue = computed ( ( ) => getFromPath ( formValues , unravel ( path ) ) ) ;
256258 const pathValue = unravel ( path ) ;
259+ const id = FIELD_ID_COUNTER ++ ;
257260 const state = reactive ( {
258- id : FIELD_ID_COUNTER ++ ,
261+ id,
259262 path,
260263 touched : false ,
261264 pending : false ,
@@ -268,6 +271,9 @@ export function useForm<
268271 type : config ?. type || 'default' ,
269272 value : currentValue ,
270273 multiple : false ,
274+ __flags : {
275+ pendingUnmount : { [ id ] : false } ,
276+ } ,
271277 fieldsCount : 1 ,
272278 validate : config ?. validate ,
273279 dirty : computed ( ( ) => {
@@ -467,6 +473,16 @@ export function useForm<
467473 }
468474 }
469475
476+ function markForUnmount ( path : string ) {
477+ return mutateAllPathState ( s => {
478+ if ( s . path . startsWith ( path ) ) {
479+ keysOf ( s . __flags . pendingUnmount ) . forEach ( id => {
480+ s . __flags . pendingUnmount [ id ] = true ;
481+ } ) ;
482+ }
483+ } ) ;
484+ }
485+
470486 const formCtx : PrivateFormContext < TValues , TOutput > = {
471487 formId,
472488 values : formValues ,
@@ -501,6 +517,7 @@ export function useForm<
501517 removePathState,
502518 initialValues : initialValues as Ref < TValues > ,
503519 getAllPathStates : ( ) => pathStates . value ,
520+ markForUnmount,
504521 } ;
505522
506523 /**
0 commit comments