Skip to content

Commit 9b50cad

Browse files
committed
fix: delete ids from removed path states
1 parent 31090e0 commit 9b50cad

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/vee-validate/src/types/forms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export interface PrivateFormContext<TValues extends GenericObject = GenericObjec
249249
): PathState<PathValue<TValues, TPath>>;
250250
getPathState<TPath extends Path<TValues>>(path: TPath): PathState<PathValue<TValues, TPath>> | undefined;
251251
getAllPathStates(): PathState[];
252-
removePathState<TPath extends Path<TValues>>(path: TPath): void;
252+
removePathState<TPath extends Path<TValues>>(path: TPath, id: number): void;
253253
unsetPathValue<TPath extends Path<TValues>>(path: TPath): void;
254254
markForUnmount(path: string): void;
255255
}

packages/vee-validate/src/useField.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function _useField<TValue = unknown>(
407407
const shouldKeepValue = unref(field.keepValueOnUnmount) ?? unref(form.keepValuesOnUnmount);
408408
const path = unravel(name);
409409
if (shouldKeepValue || !form || flags.pendingUnmount[field.id]) {
410-
form?.removePathState(path);
410+
form?.removePathState(path, id);
411411

412412
return;
413413
}
@@ -437,7 +437,7 @@ function _useField<TValue = unknown>(
437437
form.unsetPathValue(path);
438438
}
439439

440-
form.removePathState(path);
440+
form.removePathState(path, id);
441441
});
442442

443443
return field;

packages/vee-validate/src/useForm.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export function useForm<
456456
const handleSubmit: typeof handleSubmitImpl & { withControlled: typeof handleSubmitImpl } = handleSubmitImpl as any;
457457
handleSubmit.withControlled = makeSubmissionFactory(true);
458458

459-
function removePathState<TPath extends Path<TValues>>(path: TPath) {
459+
function removePathState<TPath extends Path<TValues>>(path: TPath, id: number) {
460460
const idx = pathStates.value.findIndex(s => s.path === path);
461461
const pathState = pathStates.value[idx];
462462
if (idx === -1 || !pathState) {
@@ -467,6 +467,15 @@ export function useForm<
467467
pathState.fieldsCount--;
468468
}
469469

470+
if (Array.isArray(pathState.id)) {
471+
const idIndex = pathState.id.indexOf(id);
472+
if (idIndex >= 0) {
473+
pathState.id.splice(idIndex, 1);
474+
}
475+
476+
delete pathState.__flags.pendingUnmount[id];
477+
}
478+
470479
if (!pathState.multiple || pathState.fieldsCount <= 0) {
471480
pathStates.value.splice(idx, 1);
472481
unsetInitialValue(path);

0 commit comments

Comments
 (0)