Skip to content

Commit 4fa6600

Browse files
author
Erik Rasmussen
committed
fix: preserve validation pause state and forward isEqual in re-registration
- Check form.isValidationPaused() before calling pauseValidation() so we don't inadvertently resume validation that was already paused externally (e.g. by ReactFinalForm during setup). Mirrors the pattern used in ReactFinalForm.tsx. - Pass configRef.current.isEqual through the temporary registerField call so dirty/pristine calculation uses the field's configured equality comparator rather than the default reference equality. Addresses remaining CodeRabbit review comments.
1 parent bcc1ef9 commit 4fa6600

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/useField.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,28 @@ function useField<
236236
// The only public API is form.setConfig('initialValues', ...) but that
237237
// resets ALL values. Instead, we use a workaround:
238238
// Trigger a re-registration which will update initialValues for this field.
239-
form.pauseValidation();
239+
const wasValidationPaused = form.isValidationPaused();
240+
if (!wasValidationPaused) {
241+
form.pauseValidation();
242+
}
240243
try {
241244
// Manually update initialValues via registerField with silent: false
242245
// to force notification
243246
const unsubscribe = form.registerField(
244247
name as keyof FormValues,
245248
() => {},
246249
{},
247-
{ initialValue }
250+
{
251+
initialValue,
252+
isEqual: configRef.current.isEqual,
253+
}
248254
);
249255
// Immediately unsubscribe to avoid orphan subscriber
250256
unsubscribe();
251257
} finally {
252-
form.resumeValidation();
258+
if (!wasValidationPaused) {
259+
form.resumeValidation();
260+
}
253261
}
254262
}
255263
}

0 commit comments

Comments
 (0)