Skip to content

Commit

Permalink
💅 related #11541 improve dirty check when undefined provided with `…
Browse files Browse the repository at this point in the history
…reset` api

* related #11541 improve dirty check when undefined provided with reset api

* early exit when no values provided
  • Loading branch information
bluebill1049 committed Feb 24, 2024
1 parent ebc1f2c commit bba5524
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/logic/createFormControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,10 +1205,8 @@ export function createFormControl<
) => {
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
const cloneUpdatedValues = cloneObject(updatedValues);
const values =
formValues && !isEmptyObject(formValues)
? cloneUpdatedValues
: _defaultValues;
const isEmptyResetValues = isEmptyObject(formValues);
const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;

if (!keepStateOptions.keepDefaultValues) {
_defaultValues = updatedValues;
Expand Down Expand Up @@ -1282,7 +1280,9 @@ export function createFormControl<
submitCount: keepStateOptions.keepSubmitCount
? _formState.submitCount
: 0,
isDirty: keepStateOptions.keepDirty
isDirty: isEmptyResetValues
? false
: keepStateOptions.keepDirty
? _formState.isDirty
: !!(
keepStateOptions.keepDefaultValues &&
Expand All @@ -1291,7 +1291,9 @@ export function createFormControl<
isSubmitted: keepStateOptions.keepIsSubmitted
? _formState.isSubmitted
: false,
dirtyFields: keepStateOptions.keepDirtyValues
dirtyFields: isEmptyResetValues
? []
: keepStateOptions.keepDirtyValues
? keepStateOptions.keepDefaultValues && _formValues
? getDirtyFields(_defaultValues, _formValues)
: _formState.dirtyFields
Expand Down

0 comments on commit bba5524

Please sign in to comment.