react-hook-form 7.71.1 → 7.71.2

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.
@@ -1964,11 +1964,24 @@ function createFormControl(props = {}) {
1964
1964
  isTouched: !!get((formState || _formState).touchedFields, name),
1965
1965
  });
1966
1966
  const clearErrors = (name) => {
1967
- name &&
1968
- convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
1969
- _subjects.state.next({
1970
- errors: name ? _formState.errors : {},
1971
- });
1967
+ const names = name ? convertToArrayPayload(name) : undefined;
1968
+ names === null || names === void 0 ? void 0 : names.forEach((inputName) => unset(_formState.errors, inputName));
1969
+ if (names) {
1970
+ // Emit for each cleared field with the field name so that
1971
+ // shouldSubscribeByName can filter and avoid broad re-renders
1972
+ names.forEach((inputName) => {
1973
+ _subjects.state.next({
1974
+ name: inputName,
1975
+ errors: _formState.errors,
1976
+ });
1977
+ });
1978
+ }
1979
+ else {
1980
+ // Clear all errors - emit without name to notify all subscribers
1981
+ _subjects.state.next({
1982
+ errors: {},
1983
+ });
1984
+ }
1972
1985
  };
1973
1986
  const setError = (name, error, options) => {
1974
1987
  const ref = (get(_fields, name, { _f: {} })._f || {}).ref;