react-hook-form 7.77.0 → 7.78.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.
@@ -248,6 +248,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
248
248
 
249
249
  var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
250
250
 
251
+ const isEmptyObjectWithCustomPrototype = (object, keys) => keys.length === 0 && !Array.isArray(object) && !isPlainObject(object);
251
252
  function deepEqual(object1, object2, visited = new WeakSet()) {
252
253
  if (object1 === object2) {
253
254
  return true;
@@ -263,6 +264,10 @@ function deepEqual(object1, object2, visited = new WeakSet()) {
263
264
  if (keys1.length !== keys2.length) {
264
265
  return false;
265
266
  }
267
+ if (isEmptyObjectWithCustomPrototype(object1, keys1) ||
268
+ isEmptyObjectWithCustomPrototype(object2, keys2)) {
269
+ return Object.is(object1, object2);
270
+ }
266
271
  if (visited.has(object1) || visited.has(object2)) {
267
272
  return true;
268
273
  }
@@ -442,13 +447,22 @@ function useController(props) {
442
447
  get: () => get(formState.errors, name),
443
448
  },
444
449
  }), [formState, name]);
445
- const onChange = React.useCallback((event) => _registerProps.current.onChange({
446
- target: {
447
- value: getEventValue(event),
448
- name: name,
449
- },
450
- type: EVENTS.CHANGE,
451
- }), [name]);
450
+ const onChange = React.useCallback((event) => {
451
+ const value = getEventValue(event);
452
+ if (!get(control._fields, name)) {
453
+ _registerProps.current = control.register(name, {
454
+ ..._props.current.rules,
455
+ value,
456
+ });
457
+ }
458
+ _registerProps.current.onChange({
459
+ target: {
460
+ value: getEventValue(event),
461
+ name: name,
462
+ },
463
+ type: EVENTS.CHANGE,
464
+ });
465
+ }, [name, control]);
452
466
  const onBlur = React.useCallback(() => _registerProps.current.onBlur({
453
467
  target: {
454
468
  value: get(control._formValues, name),
@@ -493,7 +507,9 @@ function useController(props) {
493
507
  };
494
508
  updateMounted(name, true);
495
509
  if (_shouldUnregisterField) {
496
- const value = cloneObject(get(control._defaultValues, name, get(control._options.defaultValues, name, _props.current.defaultValue)));
510
+ const value = cloneObject(get(shouldUnregister
511
+ ? control._defaultValues
512
+ : control._options.values || control._defaultValues, name, get(control._options.defaultValues, name, _props.current.defaultValue)));
497
513
  set(control._defaultValues, name, value);
498
514
  if (isUndefined(get(control._formValues, name))) {
499
515
  set(control._formValues, name, value);
@@ -2080,13 +2096,15 @@ function createFormControl(props = {}) {
2080
2096
  const { errors } = await _runSchema([name]);
2081
2097
  _updateIsValidating([name]);
2082
2098
  _updateIsFieldValueUpdated(fieldValue);
2083
- if (isFieldValueUpdated) {
2084
- const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
2085
- const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
2086
- error = errorLookupResult.error;
2087
- name = errorLookupResult.name;
2088
- isValid = isEmptyObject(errors);
2099
+ if (!isFieldValueUpdated) {
2100
+ !isEmptyObject(fieldState) && _subjects.state.next(fieldState);
2101
+ return;
2089
2102
  }
2103
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
2104
+ const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
2105
+ error = errorLookupResult.error;
2106
+ name = errorLookupResult.name;
2107
+ isValid = isEmptyObject(errors);
2090
2108
  }
2091
2109
  else {
2092
2110
  _updateIsValidating([name], true);