react-hook-form 7.58.1 → 7.60.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.
@@ -39,9 +39,6 @@ function cloneObject(data) {
39
39
  if (data instanceof Date) {
40
40
  copy = new Date(data);
41
41
  }
42
- else if (data instanceof Set) {
43
- copy = new Set(data);
44
- }
45
42
  else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
46
43
  (isArray || isObject(data))) {
47
44
  copy = isArray ? [] : {};
@@ -290,7 +287,8 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
290
287
  return get(formValues, names, defaultValue);
291
288
  }
292
289
  if (Array.isArray(names)) {
293
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
290
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
291
+ get(formValues, fieldName)));
294
292
  }
295
293
  isGlobal && (_names.watchAll = true);
296
294
  return formValues;
@@ -677,7 +675,7 @@ var createSubject = () => {
677
675
 
678
676
  var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
679
677
 
680
- function deepEqual(object1, object2) {
678
+ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
681
679
  if (isPrimitive(object1) || isPrimitive(object2)) {
682
680
  return object1 === object2;
683
681
  }
@@ -689,6 +687,11 @@ function deepEqual(object1, object2) {
689
687
  if (keys1.length !== keys2.length) {
690
688
  return false;
691
689
  }
690
+ if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
691
+ return true;
692
+ }
693
+ _internal_visited.add(object1);
694
+ _internal_visited.add(object2);
692
695
  for (const key of keys1) {
693
696
  const val1 = object1[key];
694
697
  if (!keys2.includes(key)) {
@@ -699,7 +702,7 @@ function deepEqual(object1, object2) {
699
702
  if ((isDateObject(val1) && isDateObject(val2)) ||
700
703
  (isObject(val1) && isObject(val2)) ||
701
704
  (Array.isArray(val1) && Array.isArray(val2))
702
- ? !deepEqual(val1, val2)
705
+ ? !deepEqual(val1, val2, _internal_visited)
703
706
  : val1 !== val2) {
704
707
  return false;
705
708
  }
@@ -1275,7 +1278,7 @@ function createFormControl(props = {}) {
1275
1278
  errors: _options.errors || {},
1276
1279
  disabled: _options.disabled || false,
1277
1280
  };
1278
- const _fields = {};
1281
+ let _fields = {};
1279
1282
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1280
1283
  ? cloneObject(_options.defaultValues || _options.values) || {}
1281
1284
  : {};
@@ -2018,14 +2021,14 @@ function createFormControl(props = {}) {
2018
2021
  if (_options.resolver) {
2019
2022
  const { errors, values } = await _runSchema();
2020
2023
  _formState.errors = errors;
2021
- fieldValues = values;
2024
+ fieldValues = cloneObject(values);
2022
2025
  }
2023
2026
  else {
2024
2027
  await executeBuiltInValidation(_fields);
2025
2028
  }
2026
2029
  if (_names.disabled.size) {
2027
2030
  for (const name of _names.disabled) {
2028
- set(fieldValues, name, undefined);
2031
+ unset(fieldValues, name);
2029
2032
  }
2030
2033
  }
2031
2034
  unset(_formState.errors, 'root');
@@ -2121,11 +2124,20 @@ function createFormControl(props = {}) {
2121
2124
  }
2122
2125
  }
2123
2126
  }
2124
- for (const fieldName of _names.mount) {
2125
- setValue(fieldName, get(values, fieldName));
2127
+ if (keepStateOptions.keepFieldsRef) {
2128
+ for (const fieldName of _names.mount) {
2129
+ setValue(fieldName, get(values, fieldName));
2130
+ }
2131
+ }
2132
+ else {
2133
+ _fields = {};
2126
2134
  }
2127
2135
  }
2128
- _formValues = cloneObject(values);
2136
+ _formValues = _options.shouldUnregister
2137
+ ? keepStateOptions.keepDefaultValues
2138
+ ? cloneObject(_defaultValues)
2139
+ : {}
2140
+ : cloneObject(values);
2129
2141
  _subjects.array.next({
2130
2142
  values: { ...values },
2131
2143
  });
@@ -2716,7 +2728,10 @@ function useForm(props = {}) {
2716
2728
  }, [control, formState.isDirty]);
2717
2729
  React__default.useEffect(() => {
2718
2730
  if (props.values && !deepEqual(props.values, _values.current)) {
2719
- control._reset(props.values, control._options.resetOptions);
2731
+ control._reset(props.values, {
2732
+ keepFieldsRef: true,
2733
+ ...control._options.resetOptions,
2734
+ });
2720
2735
  _values.current = props.values;
2721
2736
  updateFormState((state) => ({ ...state }));
2722
2737
  }