react-hook-form 7.80.0 → 7.81.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.
@@ -605,7 +605,9 @@ const Controller = (props) => props.render(useController(props));
605
605
  const flatten = (obj) => {
606
606
  const output = {};
607
607
  for (const key of Object.keys(obj)) {
608
- if (isObjectType(obj[key]) && obj[key] !== null) {
608
+ if (isObjectType(obj[key]) &&
609
+ obj[key] !== null &&
610
+ !isDateObject(obj[key])) {
609
611
  const nested = flatten(obj[key]);
610
612
  for (const nestedKey of Object.keys(nested)) {
611
613
  output[`${key}.${nestedKey}`] = nested[nestedKey];
@@ -950,6 +952,9 @@ function unset(object, path) {
950
952
  : isKey(path)
951
953
  ? [path]
952
954
  : stringToPath(path);
955
+ if (paths.some((segment) => PROTOTYPE_KEYWORDS.includes(String(segment)))) {
956
+ return object;
957
+ }
953
958
  const childObject = paths.length === 1 ? object : baseGet(object, paths);
954
959
  const index = paths.length - 1;
955
960
  const key = paths[index];
@@ -1254,7 +1259,7 @@ var shouldSubscribeByName = (name, signalName, exact) => !name ||
1254
1259
  name === signalName ||
1255
1260
  convertToArrayPayload(name).some((currentName) => currentName &&
1256
1261
  (exact
1257
- ? currentName === signalName
1262
+ ? currentName === signalName || currentName.startsWith(signalName + '.')
1258
1263
  : currentName.startsWith(signalName) ||
1259
1264
  signalName.startsWith(currentName)));
1260
1265
 
@@ -2065,8 +2070,11 @@ function createFormControl(props = {}) {
2065
2070
  ..._formValues,
2066
2071
  ...updatedFormValues,
2067
2072
  };
2073
+ const flattenedUpdates = flatten(updatedFormValues);
2068
2074
  for (const fieldName of _names.mount) {
2069
- _setValue(fieldName, get(updatedFormValues, fieldName), options, true, true);
2075
+ if (fieldName in flattenedUpdates) {
2076
+ _setValue(fieldName, flattenedUpdates[fieldName], options, true, true);
2077
+ }
2070
2078
  }
2071
2079
  _subjects.state.next({
2072
2080
  ..._formState,
@@ -2658,6 +2666,8 @@ function createFormControl(props = {}) {
2658
2666
  values: { ...values },
2659
2667
  });
2660
2668
  _subjects.state.next({
2669
+ name: undefined,
2670
+ type: undefined,
2661
2671
  values: { ...values },
2662
2672
  });
2663
2673
  }
@@ -2740,9 +2750,15 @@ function createFormControl(props = {}) {
2740
2750
  }
2741
2751
  };
2742
2752
  const _setFormState = (updatedFormState) => {
2753
+ // `name`, `type`, and `values` describe the event that produced this
2754
+ // update, not the form's persisted state (they aren't part of
2755
+ // `FormState`). Merging them in would leak a stale `name`/`type` from
2756
+ // one event into a later, unrelated notification that doesn't specify
2757
+ // its own.
2758
+ const { name, type, values, ...formState } = updatedFormState;
2743
2759
  _formState = {
2744
2760
  ..._formState,
2745
- ...updatedFormState,
2761
+ ...formState,
2746
2762
  };
2747
2763
  };
2748
2764
  const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
@@ -3118,18 +3134,28 @@ function useFieldArray(props) {
3118
3134
  !validationModes.isOnBlur) {
3119
3135
  if (control._options.resolver) {
3120
3136
  control._runSchema([name]).then((result) => {
3137
+ var _a, _b;
3121
3138
  control._updateIsValidating([name]);
3122
3139
  const error = get(result.errors, name);
3123
3140
  const existingError = get(control._formState.errors, name);
3141
+ const existingErrorType = existingError && (existingError.type || ((_a = existingError.root) === null || _a === void 0 ? void 0 : _a.type));
3142
+ const existingErrorMessage = existingError &&
3143
+ (existingError.message || ((_b = existingError.root) === null || _b === void 0 ? void 0 : _b.message));
3124
3144
  if (existingError
3125
- ? (!error && existingError.type) ||
3145
+ ? (!error && existingErrorType) ||
3126
3146
  (error &&
3127
- (existingError.type !== error.type ||
3128
- existingError.message !== error.message))
3147
+ (existingErrorType !== error.type ||
3148
+ existingErrorMessage !== error.message))
3129
3149
  : error && error.type) {
3130
- error
3131
- ? set(control._formState.errors, name, error)
3132
- : unset(control._formState.errors, name);
3150
+ if (error) {
3151
+ isObject(error) &&
3152
+ !Object.keys(error).some((key) => !Number.isNaN(+key))
3153
+ ? updateFieldArrayRootError(control._formState.errors, { [name]: error }, name)
3154
+ : set(control._formState.errors, name, error);
3155
+ }
3156
+ else {
3157
+ unset(control._formState.errors, name);
3158
+ }
3133
3159
  control._subjects.state.next({
3134
3160
  errors: control._formState.errors,
3135
3161
  });
@@ -3149,10 +3175,14 @@ function useFieldArray(props) {
3149
3175
  }
3150
3176
  }
3151
3177
  }
3152
- control._subjects.state.next({
3153
- name,
3154
- values: cloneObject(control._formValues),
3155
- });
3178
+ // External updates that change `fields` (e.g. reset() or setValue() on
3179
+ // the array) already notify subscribers with the up-to-date values
3180
+ // themselves, so only re-broadcast here for genuine array method calls.
3181
+ _actioned.current &&
3182
+ control._subjects.state.next({
3183
+ name,
3184
+ values: cloneObject(control._formValues),
3185
+ });
3156
3186
  control._names.focus &&
3157
3187
  iterateFieldsByAction(control._fields, (ref, key) => {
3158
3188
  if (control._names.focus &&