@bombillazo/rhf-plus 7.62.0-plus.2 → 7.62.0-plus.3

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.
@@ -81,6 +81,21 @@ var get = (object, path, defaultValue) => {
81
81
 
82
82
  var isBoolean = (value) => typeof value === 'boolean';
83
83
 
84
+ function mergeMissingKeysAsUndefined(oldObject, newObject) {
85
+ if (!newObject) {
86
+ return newObject;
87
+ }
88
+ const result = { ...newObject };
89
+ if (oldObject) {
90
+ for (const key in oldObject) {
91
+ if (!(key in result)) {
92
+ result[key] = undefined;
93
+ }
94
+ }
95
+ }
96
+ return result;
97
+ }
98
+
84
99
  var set = (object, path, value) => {
85
100
  let index = -1;
86
101
  const tempPath = isKey(path) ? [path] : stringToPath(path);
@@ -427,11 +442,22 @@ function useController(props) {
427
442
  exact: true,
428
443
  });
429
444
  const _props = React.useRef(props);
445
+ const _previousRules = React.useRef(props.rules);
430
446
  const _registerProps = React.useRef(control.register(name, {
431
447
  ...props.rules,
432
448
  value,
433
449
  ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
434
450
  }));
451
+ const mergedRules = React.useMemo(() => mergeMissingKeysAsUndefined(_previousRules.current, props.rules), [props.rules]);
452
+ // Update register props when rules change
453
+ React.useEffect(() => {
454
+ _registerProps.current = control.register(name, {
455
+ ...mergedRules,
456
+ value,
457
+ ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
458
+ });
459
+ _previousRules.current = props.rules;
460
+ }, [mergedRules, props.rules, value, props.disabled, control, name]);
435
461
  _props.current = props;
436
462
  const fieldState = React.useMemo(() => Object.defineProperties({}, {
437
463
  invalid: {