react-hook-form 7.43.5 → 7.43.6

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.
@@ -420,7 +420,11 @@ function useController(props) {
420
420
  };
421
421
  updateMounted(name, true);
422
422
  if (_shouldUnregisterField) {
423
- set(control._defaultValues, name, cloneObject(get(control._options.defaultValues, name)));
423
+ const value = cloneObject(get(control._options.defaultValues, name));
424
+ set(control._defaultValues, name, value);
425
+ if (isUndefined(get(control._formValues, name))) {
426
+ set(control._formValues, name, value);
427
+ }
424
428
  }
425
429
  return () => {
426
430
  (isArrayField
@@ -1394,7 +1398,7 @@ function createFormControl(props = {}, flushRootRender) {
1394
1398
  let _formState = {
1395
1399
  submitCount: 0,
1396
1400
  isDirty: false,
1397
- isLoading: true,
1401
+ isLoading: isFunction(_options.defaultValues),
1398
1402
  isValidating: false,
1399
1403
  isSubmitted: false,
1400
1404
  isSubmitting: false,
@@ -1608,7 +1612,7 @@ function createFormControl(props = {}, flushRootRender) {
1608
1612
  const { _f, ...fieldValue } = field;
1609
1613
  if (_f) {
1610
1614
  const isFieldArrayRoot = _names.array.has(_f.name);
1611
- const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation, isFieldArrayRoot);
1615
+ const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1612
1616
  if (fieldError[_f.name]) {
1613
1617
  context.valid = false;
1614
1618
  if (shouldOnlyCheckValid) {
@@ -1745,6 +1749,7 @@ function createFormControl(props = {}, flushRootRender) {
1745
1749
  const onChange = async (event) => {
1746
1750
  const target = event.target;
1747
1751
  let name = target.name;
1752
+ let isFieldValueUpdated = true;
1748
1753
  const field = get(_fields, name);
1749
1754
  const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1750
1755
  if (field) {
@@ -1791,16 +1796,21 @@ function createFormControl(props = {}, flushRootRender) {
1791
1796
  }
1792
1797
  else {
1793
1798
  error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1794
- if (error) {
1795
- isValid = false;
1796
- }
1797
- else if (_proxyFormState.isValid) {
1798
- isValid = await executeBuiltInValidation(_fields, true);
1799
+ isFieldValueUpdated = fieldValue === get(_formValues, name, fieldValue);
1800
+ if (isFieldValueUpdated) {
1801
+ if (error) {
1802
+ isValid = false;
1803
+ }
1804
+ else if (_proxyFormState.isValid) {
1805
+ isValid = await executeBuiltInValidation(_fields, true);
1806
+ }
1799
1807
  }
1800
1808
  }
1801
- field._f.deps &&
1802
- trigger(field._f.deps);
1803
- shouldRenderByError(name, isValid, error, fieldState);
1809
+ if (isFieldValueUpdated) {
1810
+ field._f.deps &&
1811
+ trigger(field._f.deps);
1812
+ shouldRenderByError(name, isValid, error, fieldState);
1813
+ }
1804
1814
  }
1805
1815
  };
1806
1816
  const trigger = async (name, options = {}) => {
@@ -2269,7 +2279,7 @@ function useForm(props = {}) {
2269
2279
  const [formState, updateFormState] = React.useState({
2270
2280
  isDirty: false,
2271
2281
  isValidating: false,
2272
- isLoading: true,
2282
+ isLoading: isFunction(props.defaultValues),
2273
2283
  isSubmitted: false,
2274
2284
  isSubmitting: false,
2275
2285
  isSubmitSuccessful: false,