react-hook-form 7.77.0 → 7.79.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.
@@ -1 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuDlB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAsvDA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuDlB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAwwDA"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateField.d.ts","sourceRoot":"","sources":["../../src/logic/validateField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EAEL,WAAW,EACX,mBAAmB,EACnB,eAAe,EAKhB,MAAM,UAAU,CAAC;yBAqBI,CAAC,SAAS,WAAW,EACzC,OAAO,KAAK,EACZ,oBAAoB,eAAe,EACnC,YAAY,CAAC,EACb,0BAA0B,OAAO,EACjC,4BAA4B,OAAO,EACnC,eAAe,OAAO,KACrB,OAAO,CAAC,mBAAmB,CAAC;AAP/B,wBA6PE"}
1
+ {"version":3,"file":"validateField.d.ts","sourceRoot":"","sources":["../../src/logic/validateField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EAEL,WAAW,EACX,mBAAmB,EACnB,eAAe,EAKhB,MAAM,UAAU,CAAC;yBAqBI,CAAC,SAAS,WAAW,EACzC,OAAO,KAAK,EACZ,oBAAoB,eAAe,EACnC,YAAY,CAAC,EACb,0BAA0B,OAAO,EACjC,4BAA4B,OAAO,EACnC,eAAe,OAAO,KACrB,OAAO,CAAC,mBAAmB,CAAC;AAP/B,wBAkQE"}
@@ -109,7 +109,8 @@ var createSubject = () => {
109
109
 
110
110
  var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
111
111
 
112
- function deepEqual(object1, object2, visited = new WeakSet()) {
112
+ const isEmptyObjectWithCustomPrototype = (object, keys) => keys.length === 0 && !Array.isArray(object) && !isPlainObject(object);
113
+ function deepEqual(object1, object2, visited = new WeakMap()) {
113
114
  if (object1 === object2) {
114
115
  return true;
115
116
  }
@@ -124,11 +125,20 @@ function deepEqual(object1, object2, visited = new WeakSet()) {
124
125
  if (keys1.length !== keys2.length) {
125
126
  return false;
126
127
  }
127
- if (visited.has(object1) || visited.has(object2)) {
128
+ if (isEmptyObjectWithCustomPrototype(object1, keys1) ||
129
+ isEmptyObjectWithCustomPrototype(object2, keys2)) {
130
+ return Object.is(object1, object2);
131
+ }
132
+ const visitedPairs = visited.get(object1);
133
+ if (visitedPairs && visitedPairs.has(object2)) {
128
134
  return true;
129
135
  }
130
- visited.add(object1);
131
- visited.add(object2);
136
+ if (visitedPairs) {
137
+ visitedPairs.add(object2);
138
+ }
139
+ else {
140
+ visited.set(object1, new WeakSet([object2]));
141
+ }
132
142
  for (const key of keys1) {
133
143
  const val1 = object1[key];
134
144
  if (!(key in object2)) {
@@ -645,7 +655,13 @@ var validateField = async (field, disabledFieldNames, formValues, validateAllFie
645
655
  const inputRef = refs ? refs[0] : ref;
646
656
  const setCustomValidity = (message) => {
647
657
  if (shouldUseNativeValidation && inputRef.reportValidity) {
648
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
658
+ const validityMessage = isBoolean(message) ? '' : message || '';
659
+ if (refs) {
660
+ refs.forEach((ref) => ref.setCustomValidity(validityMessage));
661
+ }
662
+ else {
663
+ inputRef.setCustomValidity(validityMessage);
664
+ }
649
665
  inputRef.reportValidity();
650
666
  }
651
667
  };
@@ -977,6 +993,7 @@ function createFormControl(props = {}) {
977
993
  };
978
994
  const updateErrors = (name, error) => {
979
995
  set(_formState.errors, name, error);
996
+ _formState.errors = { ..._formState.errors };
980
997
  _subjects.state.next({
981
998
  errors: _formState.errors,
982
999
  });
@@ -1034,6 +1051,15 @@ function createFormControl(props = {}) {
1034
1051
  _subjects.state.next({ ..._formState });
1035
1052
  }
1036
1053
  }
1054
+ // When a watched field is re-registered after being unregistered and
1055
+ // its value is restored, trigger a deferred watch broadcast so that
1056
+ // components using watch() re-render with the new value.
1057
+ if (props.shouldUnregister &&
1058
+ wasUnsetInFormValues &&
1059
+ !isUndefined(get(_formValues, name)) &&
1060
+ isWatched(name, _names)) {
1061
+ _state.watch = true;
1062
+ }
1037
1063
  }
1038
1064
  }
1039
1065
  };
@@ -1098,6 +1124,7 @@ function createFormControl(props = {}) {
1098
1124
  error
1099
1125
  ? set(_formState.errors, name, error)
1100
1126
  : unset(_formState.errors, name);
1127
+ _formState.errors = { ..._formState.errors };
1101
1128
  }
1102
1129
  if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
1103
1130
  !isEmptyObject(fieldState) ||
@@ -1133,6 +1160,7 @@ function createFormControl(props = {}) {
1133
1160
  : set(_formState.errors, name, error)
1134
1161
  : unset(_formState.errors, name);
1135
1162
  }
1163
+ _formState.errors = { ..._formState.errors };
1136
1164
  }
1137
1165
  else {
1138
1166
  _formState.errors = errors;
@@ -1467,13 +1495,15 @@ function createFormControl(props = {}) {
1467
1495
  const { errors } = await _runSchema([name]);
1468
1496
  _updateIsValidating([name]);
1469
1497
  _updateIsFieldValueUpdated(fieldValue);
1470
- if (isFieldValueUpdated) {
1471
- const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1472
- const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1473
- error = errorLookupResult.error;
1474
- name = errorLookupResult.name;
1475
- isValid = isEmptyObject(errors);
1498
+ if (!isFieldValueUpdated) {
1499
+ !isEmptyObject(fieldState) && _subjects.state.next(fieldState);
1500
+ return;
1476
1501
  }
1502
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1503
+ const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1504
+ error = errorLookupResult.error;
1505
+ name = errorLookupResult.name;
1506
+ isValid = isEmptyObject(errors);
1477
1507
  }
1478
1508
  else {
1479
1509
  _updateIsValidating([name], true);