react-hook-form 7.42.1 → 7.43.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1401,8 +1401,8 @@ function createFormControl(props = {}, flushRootRender) {
1401
1401
  errors: {},
1402
1402
  };
1403
1403
  let _fields = {};
1404
- let _defaultValues = isObject(_options.defaultValues)
1405
- ? cloneObject(_options.defaultValues) || {}
1404
+ let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1405
+ ? cloneObject(_options.defaultValues || _options.values) || {}
1406
1406
  : {};
1407
1407
  let _formValues = _options.shouldUnregister
1408
1408
  ? {}
@@ -1446,7 +1446,6 @@ function createFormControl(props = {}, flushRootRender) {
1446
1446
  ? isEmptyObject((await _executeSchema()).errors)
1447
1447
  : await executeBuiltInValidation(_fields, true);
1448
1448
  if (isValid !== _formState.isValid) {
1449
- _formState.isValid = isValid;
1450
1449
  _subjects.state.next({
1451
1450
  isValid,
1452
1451
  });
@@ -1718,10 +1717,9 @@ function createFormControl(props = {}, flushRootRender) {
1718
1717
  });
1719
1718
  if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
1720
1719
  options.shouldDirty) {
1721
- _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
1722
1720
  _subjects.state.next({
1723
1721
  name,
1724
- dirtyFields: _formState.dirtyFields,
1722
+ dirtyFields: getDirtyFields(_defaultValues, _formValues),
1725
1723
  isDirty: _getDirty(name, cloneValue),
1726
1724
  });
1727
1725
  }
@@ -1851,11 +1849,10 @@ function createFormControl(props = {}, flushRootRender) {
1851
1849
  error: get((formState || _formState).errors, name),
1852
1850
  });
1853
1851
  const clearErrors = (name) => {
1854
- name
1855
- ? convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName))
1856
- : (_formState.errors = {});
1852
+ name &&
1853
+ convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
1857
1854
  _subjects.state.next({
1858
- errors: _formState.errors,
1855
+ errors: name ? _formState.errors : {},
1859
1856
  });
1860
1857
  };
1861
1858
  const setError = (name, error, options) => {
@@ -1998,6 +1995,7 @@ function createFormControl(props = {}, flushRootRender) {
1998
1995
  else {
1999
1996
  await executeBuiltInValidation(_fields);
2000
1997
  }
1998
+ unset(_formState.errors, 'root');
2001
1999
  if (isEmptyObject(_formState.errors)) {
2002
2000
  _subjects.state.next({
2003
2001
  errors: {},