react-hook-form 7.83.0 → 7.85.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.
Files changed (44) hide show
  1. package/dist/fieldArray.d.ts +2 -1
  2. package/dist/fieldArray.d.ts.map +1 -1
  3. package/dist/form.d.ts +1 -1
  4. package/dist/form.d.ts.map +1 -1
  5. package/dist/formStateSubscribe.d.ts +8 -3
  6. package/dist/formStateSubscribe.d.ts.map +1 -1
  7. package/dist/index.cjs.js +1 -1
  8. package/dist/index.cjs.js.map +1 -1
  9. package/dist/index.d.ts +2 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.esm.mjs +311 -150
  12. package/dist/index.esm.mjs.map +1 -1
  13. package/dist/index.umd.js +1 -1
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/logic/collectDirtyFieldNames.d.ts +3 -0
  16. package/dist/logic/collectDirtyFieldNames.d.ts.map +1 -0
  17. package/dist/logic/createFormControl.d.ts.map +1 -1
  18. package/dist/logic/getFieldValue.d.ts.map +1 -1
  19. package/dist/logic/iterateFieldsByAction.d.ts.map +1 -1
  20. package/dist/logic/shouldRenderFormState.d.ts.map +1 -1
  21. package/dist/logic/unsetEmptyArray.d.ts +1 -1
  22. package/dist/logic/unsetEmptyArray.d.ts.map +1 -1
  23. package/dist/logic/validateField.d.ts.map +1 -1
  24. package/dist/react-server.esm.mjs +102 -26
  25. package/dist/react-server.esm.mjs.map +1 -1
  26. package/dist/types/errors.d.ts +6 -1
  27. package/dist/types/errors.d.ts.map +1 -1
  28. package/dist/types/form.d.ts +8 -6
  29. package/dist/types/form.d.ts.map +1 -1
  30. package/dist/useFieldArray.d.ts.map +1 -1
  31. package/dist/useForm.d.ts.map +1 -1
  32. package/dist/useFormState.d.ts.map +1 -1
  33. package/dist/useResyncOnReconnect.d.ts +5 -0
  34. package/dist/useResyncOnReconnect.d.ts.map +1 -0
  35. package/dist/useWatch.d.ts.map +1 -1
  36. package/dist/utils/formData.d.ts +3 -0
  37. package/dist/utils/formData.d.ts.map +1 -0
  38. package/dist/utils/json.d.ts +9 -0
  39. package/dist/utils/json.d.ts.map +1 -0
  40. package/package.json +2 -8
  41. package/dist/logic/getNodeParentName.d.ts +0 -3
  42. package/dist/logic/getNodeParentName.d.ts.map +0 -1
  43. package/dist/utils/deepMerge.d.ts +0 -2
  44. package/dist/utils/deepMerge.d.ts.map +0 -1
@@ -0,0 +1,3 @@
1
+ import type { FieldValues } from '../types';
2
+ export default function collectDirtyFieldNames(dirtyTree: FieldValues, cachedDirtyFields: FieldValues, prefix?: string, names?: string[]): string[];
3
+ //# sourceMappingURL=collectDirtyFieldNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectDirtyFieldNames.d.ts","sourceRoot":"","sources":["../../src/logic/collectDirtyFieldNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ5C,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,SAAS,EAAE,WAAW,EACtB,iBAAiB,EAAE,WAAW,EAC9B,MAAM,SAAK,EACX,KAAK,GAAE,MAAM,EAAO,YAiBrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAcV,WAAW,EAkBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuElB,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,CAo3DA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAcV,WAAW,EAkBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAwElB,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,CAm9DA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getFieldValue.d.ts","sourceRoot":"","sources":["../../src/logic/getFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAWtC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,OAoBpD"}
1
+ {"version":3,"file":"getFieldValue.d.ts","sourceRoot":"","sources":["../../src/logic/getFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAUtC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,OAoBpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"iterateFieldsByAction.d.ts","sourceRoot":"","sources":["../../src/logic/iterateFieldsByAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIlE,QAAA,MAAM,qBAAqB,GACzB,QAAQ,SAAS,EACjB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,IAAI,EACxD,cAAc,GAAG,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,EAAE,GAAG,CAAC,EAC9D,aAAa,OAAO,qBA0BrB,CAAC;AACF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"iterateFieldsByAction.d.ts","sourceRoot":"","sources":["../../src/logic/iterateFieldsByAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIlE,QAAA,MAAM,qBAAqB,GACzB,QAAQ,SAAS,EACjB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,IAAI,EACxD,cAAc,GAAG,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,EAAE,GAAG,CAAC,EAC9D,aAAa,OAAO,qBA8BrB,CAAC;AACF,eAAe,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"shouldRenderFormState.d.ts","sourceRoot":"","sources":["../../src/logic/shouldRenderFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACd,MAAM,UAAU,CAAC;yBAEF,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,aAAa,EAC5D,eAAe,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG;IACrC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ,EACD,iBAAiB,CAAC,EAClB,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3D,SAAS,OAAO;AAPlB,wBAsBE"}
1
+ {"version":3,"file":"shouldRenderFormState.d.ts","sourceRoot":"","sources":["../../src/logic/shouldRenderFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACd,MAAM,UAAU,CAAC;yBAEF,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,aAAa,EAC5D,eAAe,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG;IACrC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ,EACD,iBAAiB,CAAC,EAClB,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3D,SAAS,OAAO;AAPlB,wBAqBE"}
@@ -1,3 +1,3 @@
1
- declare const _default: <T>(ref: T, name: string) => any;
1
+ declare const _default: <T>(ref: T, name: string) => void;
2
2
  export default _default;
3
3
  //# sourceMappingURL=unsetEmptyArray.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unsetEmptyArray.d.ts","sourceRoot":"","sources":["../../src/logic/unsetEmptyArray.ts"],"names":[],"mappings":"yBAIgB,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,MAAM;AAAvC,wBACsD"}
1
+ {"version":3,"file":"unsetEmptyArray.d.ts","sourceRoot":"","sources":["../../src/logic/unsetEmptyArray.ts"],"names":[],"mappings":"yBAIgB,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,MAAM;AAAvC,wBAME"}
@@ -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,wBAkQE"}
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;yBAsBI,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,wBAsQE"}
@@ -281,7 +281,7 @@ var set = (object, path, value) => {
281
281
  };
282
282
 
283
283
  function baseGet(object, updatePath) {
284
- const length = updatePath.slice(0, -1).length;
284
+ const length = updatePath.length - 1;
285
285
  let index = 0;
286
286
  while (index < length) {
287
287
  if (isNullOrUndefined(object)) {
@@ -328,6 +328,24 @@ function unset(object, path) {
328
328
  return object;
329
329
  }
330
330
 
331
+ function isDirtyContainer(value) {
332
+ return Array.isArray(value) || isObject(value);
333
+ }
334
+ function collectDirtyFieldNames(dirtyTree, cachedDirtyFields, prefix = '', names = []) {
335
+ for (const key in dirtyTree) {
336
+ const path = prefix ? `${prefix}.${key}` : key;
337
+ const value = dirtyTree[key];
338
+ if (isDirtyContainer(value) &&
339
+ isDirtyContainer(get(cachedDirtyFields, path))) {
340
+ collectDirtyFieldNames(value, cachedDirtyFields, path, names);
341
+ }
342
+ else {
343
+ names.push(path);
344
+ }
345
+ }
346
+ return names;
347
+ }
348
+
331
349
  var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
332
350
  if (isString(names)) {
333
351
  isGlobal && _names.watch.add(names);
@@ -490,7 +508,7 @@ function getFieldValue(_f) {
490
508
  if (isCheckBoxInput(ref)) {
491
509
  return getCheckboxValue(_f.refs).value;
492
510
  }
493
- return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
511
+ return getFieldValueAs(ref.value, _f);
494
512
  }
495
513
 
496
514
  var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
@@ -572,9 +590,12 @@ var isWatched = (name, _names, isBlurEvent) => {
572
590
 
573
591
  const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
574
592
  for (const key of fieldsNames || Object.keys(fields)) {
575
- const field = get(fields, key);
593
+ if (key === '_f') {
594
+ continue;
595
+ }
596
+ const field = fieldsNames ? get(fields, key) : fields[key];
576
597
  if (field) {
577
- const { _f, ...currentField } = field;
598
+ const { _f } = field;
578
599
  if (_f) {
579
600
  if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
580
601
  return true;
@@ -583,13 +604,13 @@ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
583
604
  return true;
584
605
  }
585
606
  else {
586
- if (iterateFieldsByAction(currentField, action)) {
607
+ if (iterateFieldsByAction(field, action)) {
587
608
  break;
588
609
  }
589
610
  }
590
611
  }
591
- else if (isObject(currentField)) {
592
- if (iterateFieldsByAction(currentField, action)) {
612
+ else if (isObject(field) || Array.isArray(field)) {
613
+ if (iterateFieldsByAction(field, action)) {
593
614
  break;
594
615
  }
595
616
  }
@@ -635,8 +656,7 @@ function schemaErrorLookup(errors, _fields, name) {
635
656
 
636
657
  var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
637
658
  updateFormState(formStateData);
638
- const { name, ...formState } = formStateData;
639
- const keys = Object.keys(formState);
659
+ const keys = Object.keys(formStateData).filter((key) => key !== 'name');
640
660
  return (!keys.length ||
641
661
  (isRoot && keys.length >= Object.keys(_proxyFormState).length) ||
642
662
  keys.find((key) => _proxyFormState[key] ===
@@ -668,7 +688,12 @@ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode)
668
688
  return true;
669
689
  };
670
690
 
671
- var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
691
+ var unsetEmptyArray = (ref, name) => {
692
+ const array = get(ref, name);
693
+ !compact(array).length &&
694
+ !(array === null || array === void 0 ? void 0 : array.root) &&
695
+ unset(ref, name);
696
+ };
672
697
 
673
698
  var updateFieldArrayRootError = (errors, error, name) => {
674
699
  const existingErrors = get(errors, name);
@@ -764,7 +789,9 @@ var validateField = async (field, disabledFieldNames, formValues, validateAllFie
764
789
  let exceedMin;
765
790
  const maxOutput = getValueAndMessage(max);
766
791
  const minOutput = getValueAndMessage(min);
767
- if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
792
+ if (!isNullOrUndefined(inputValue) &&
793
+ !isDateObject(inputValue) &&
794
+ !isNaN(inputValue)) {
768
795
  const valueNumber = ref.valueAsNumber ||
769
796
  (inputValue ? +inputValue : inputValue);
770
797
  if (!isNullOrUndefined(maxOutput.value)) {
@@ -929,6 +956,7 @@ function createFormControl(props = {}) {
929
956
  : cloneObject(_defaultValues);
930
957
  let _state = {
931
958
  action: false,
959
+ actionArrayLengths: new Map(),
932
960
  mount: false,
933
961
  watch: false,
934
962
  keepIsValid: false,
@@ -1024,13 +1052,22 @@ function createFormControl(props = {}) {
1024
1052
  const _setFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1025
1053
  if (args && method && !_options.disabled) {
1026
1054
  _state.action = true;
1055
+ if (!_state.actionArrayLengths.has(name)) {
1056
+ const preActionFields = get(_fields, name);
1057
+ _state.actionArrayLengths.set(name, Array.isArray(preActionFields) ? preActionFields.length : 0);
1058
+ }
1027
1059
  if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1028
1060
  const fieldValues = method(get(_fields, name), args.argA, args.argB);
1029
1061
  shouldSetValues && set(_fields, name, fieldValues);
1030
1062
  }
1031
1063
  if (shouldUpdateFieldsAndState &&
1032
1064
  Array.isArray(get(_formState.errors, name))) {
1033
- const errors = method(get(_formState.errors, name), args.argA, args.argB);
1065
+ const fieldArrayErrors = get(_formState.errors, name);
1066
+ const rootError = fieldArrayErrors.root;
1067
+ const errors = method(fieldArrayErrors, args.argA, args.argB) || fieldArrayErrors;
1068
+ if (rootError) {
1069
+ errors.root = rootError;
1070
+ }
1034
1071
  shouldSetValues && set(_formState.errors, name, errors);
1035
1072
  unsetEmptyArray(_formState.errors, name);
1036
1073
  }
@@ -1086,10 +1123,40 @@ function createFormControl(props = {}) {
1086
1123
  }
1087
1124
  return false;
1088
1125
  };
1126
+ const isStaleArrayIndex = (name) => {
1127
+ if (!_state.actionArrayLengths.size) {
1128
+ return false;
1129
+ }
1130
+ const segments = isKey(name) ? [name] : stringToPath(name);
1131
+ let node = _formValues;
1132
+ let path = '';
1133
+ let ownerDepth = -1;
1134
+ let ownerPreActionLength = 0;
1135
+ for (let i = 0; i < segments.length; i++) {
1136
+ if (isNullOrUndefined(node)) {
1137
+ return false;
1138
+ }
1139
+ const key = segments[i];
1140
+ path = path ? `${path}.${key}` : key;
1141
+ if (Array.isArray(node) && +key >= node.length) {
1142
+ return ownerDepth === -1
1143
+ ? false
1144
+ : i === ownerDepth
1145
+ ? +key < ownerPreActionLength
1146
+ : true;
1147
+ }
1148
+ if (_state.actionArrayLengths.has(path)) {
1149
+ ownerDepth = i + 1;
1150
+ ownerPreActionLength = _state.actionArrayLengths.get(path);
1151
+ }
1152
+ node = node[key];
1153
+ }
1154
+ return false;
1155
+ };
1089
1156
  const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
1090
1157
  const field = get(_fields, name);
1091
1158
  if (field) {
1092
- if (hasExplicitNullIntermediate(name)) {
1159
+ if (hasExplicitNullIntermediate(name) || isStaleArrayIndex(name)) {
1093
1160
  return;
1094
1161
  }
1095
1162
  const wasUnsetInFormValues = isUndefined(get(_formValues, name));
@@ -1337,14 +1404,12 @@ function createFormControl(props = {}) {
1337
1404
  const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1338
1405
  ...(_state.mount
1339
1406
  ? _formValues
1340
- : isUndefined(defaultValue)
1407
+ : isUndefined(defaultValue) || isString(names)
1341
1408
  ? _defaultValues
1342
- : isString(names)
1343
- ? { [names]: defaultValue }
1344
- : defaultValue),
1409
+ : defaultValue),
1345
1410
  }, isGlobal, defaultValue);
1346
1411
  const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
1347
- const setFieldValue = (name, value, options = {}, skipClone = false, skipRender = false) => {
1412
+ const setFieldValue = (name, value, options = {}, skipClone = false, skipRender = false, skipValueRender = false) => {
1348
1413
  const field = get(_fields, name);
1349
1414
  let fieldValue = value;
1350
1415
  if (field) {
@@ -1382,7 +1447,7 @@ function createFormControl(props = {}) {
1382
1447
  }
1383
1448
  else {
1384
1449
  fieldReference.ref.value = fieldValue;
1385
- if (!fieldReference.ref.type && !skipRender) {
1450
+ if (!fieldReference.ref.type && !skipRender && !skipValueRender) {
1386
1451
  _subjects.state.next({
1387
1452
  name,
1388
1453
  values: skipClone ? _formValues : cloneObject(_formValues),
@@ -1398,7 +1463,13 @@ function createFormControl(props = {}) {
1398
1463
  delayError: options.delayError,
1399
1464
  });
1400
1465
  };
1401
- const setFieldValues = (name, value, options, skipClone = false, skipRender = false) => {
1466
+ const setFieldValues = (name, value, options, skipClone = false, skipRender = false, skipValueRender = false) => {
1467
+ if (_names.array.has(name)) {
1468
+ _subjects.array.next({
1469
+ name,
1470
+ values: skipClone ? _formValues : cloneObject(_formValues),
1471
+ });
1472
+ }
1402
1473
  for (const fieldKey in value) {
1403
1474
  if (!value.hasOwnProperty(fieldKey)) {
1404
1475
  return;
@@ -1410,8 +1481,8 @@ function createFormControl(props = {}) {
1410
1481
  isObject(fieldValue) ||
1411
1482
  (field && !field._f)) &&
1412
1483
  !isDateObject(fieldValue)
1413
- ? setFieldValues(fieldName, fieldValue, options, skipClone, skipRender)
1414
- : setFieldValue(fieldName, fieldValue, options, skipClone, skipRender);
1484
+ ? setFieldValues(fieldName, fieldValue, options, skipClone, skipRender, skipValueRender)
1485
+ : setFieldValue(fieldName, fieldValue, options, skipClone, skipRender, skipValueRender);
1415
1486
  }
1416
1487
  };
1417
1488
  const _setValue = (name, value, options, skipClone, skipStateEmit = false) => {
@@ -1446,11 +1517,12 @@ function createFormControl(props = {}) {
1446
1517
  else {
1447
1518
  const isEmpty = (Array.isArray(cloneValue) && !cloneValue.length) ||
1448
1519
  isEmptyObject(cloneValue);
1520
+ const skipValueRender = !isValueUnchanged && !skipStateEmit;
1449
1521
  if (!field || field._f || isNullOrUndefined(cloneValue) || isEmpty) {
1450
- setFieldValue(name, cloneValue, options, skipClone, skipStateEmit);
1522
+ setFieldValue(name, cloneValue, options, skipClone, skipStateEmit, skipValueRender);
1451
1523
  }
1452
1524
  else {
1453
- setFieldValues(name, cloneValue, options, skipClone, skipStateEmit);
1525
+ setFieldValues(name, cloneValue, options, skipClone, skipStateEmit, skipValueRender);
1454
1526
  }
1455
1527
  }
1456
1528
  if (!isValueUnchanged && !skipStateEmit) {
@@ -1934,6 +2006,7 @@ function createFormControl(props = {}) {
1934
2006
  }
1935
2007
  };
1936
2008
  const handleSubmit = (onValid, onInvalid) => async (e) => {
2009
+ let result = undefined;
1937
2010
  let onValidError = undefined;
1938
2011
  if (e) {
1939
2012
  e.preventDefault && e.preventDefault();
@@ -1967,7 +2040,7 @@ function createFormControl(props = {}) {
1967
2040
  errors: {},
1968
2041
  });
1969
2042
  try {
1970
- await onValid(fieldValues, e);
2043
+ result = await onValid(fieldValues, e);
1971
2044
  }
1972
2045
  catch (error) {
1973
2046
  onValidError = error;
@@ -1990,6 +2063,7 @@ function createFormControl(props = {}) {
1990
2063
  if (onValidError) {
1991
2064
  throw onValidError;
1992
2065
  }
2066
+ return result;
1993
2067
  };
1994
2068
  const resetField = (name, options = {}) => {
1995
2069
  if (get(_fields, name)) {
@@ -2029,7 +2103,7 @@ function createFormControl(props = {}) {
2029
2103
  if (keepStateOptions.keepDirtyValues) {
2030
2104
  const fieldsToCheck = new Set([
2031
2105
  ..._names.mount,
2032
- ...Object.keys(getDirtyFields(_defaultValues, _formValues, undefined, fieldRefs)),
2106
+ ...collectDirtyFieldNames(getDirtyFields(_defaultValues, _formValues, undefined, fieldRefs), _formState.dirtyFields),
2033
2107
  ]);
2034
2108
  for (const fieldName of Array.from(fieldsToCheck)) {
2035
2109
  const isDirty = get(_formState.dirtyFields, fieldName);
@@ -2110,6 +2184,7 @@ function createFormControl(props = {}) {
2110
2184
  _state.watch = !!_options.shouldUnregister;
2111
2185
  _state.keepIsValid = !!keepStateOptions.keepIsValid;
2112
2186
  _state.action = false;
2187
+ _state.actionArrayLengths.clear();
2113
2188
  if (!keepStateOptions.keepErrors) {
2114
2189
  _formState.errors = {};
2115
2190
  }
@@ -2182,6 +2257,7 @@ function createFormControl(props = {}) {
2182
2257
  ...formState,
2183
2258
  };
2184
2259
  };
2260
+ _subjects.state.subscribe({ next: _setFormState });
2185
2261
  const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
2186
2262
  _options.defaultValues().then((values) => {
2187
2263
  reset(values, _options.resetOptions);