Skip to content

fix: restore Controller blur validation after reset - #13817

Merged
bluebill1049 merged 2 commits into
react-hook-form:masterfrom
charan-rathore:fix/controller-blur-after-reset
Oct 2, 2026
Merged

bluebill1049 merged 2 commits into
react-hook-form:masterfrom
charan-rathore:fix/controller-blur-after-reset

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Proposed Changes

Calling reset(values) can remove a mounted Controller's field registration without rerendering it when the watched value is unchanged. Its next blur then skips validation in onTouched mode.

Register the field again when handling blur if its registration is missing, preserving its current rules, value and disabled option. This follows the existing change handler behavior. Add a regression test with a memoized Controller that does not subscribe to field state.

Fixes #13816

No new dependencies.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes (see the browser caveat below)

Validation (author's run, I did not re-run it): the regression test fails on unchanged source (no validate calls) and passes patched. Unit suites: 126 suites, 1486 tests, 26 snapshots passed. Root and type-test TypeScript checks, lint (0 errors, none on changed files), format, build and API extraction passed. Affected Controller, basic validation and reset browser flows passed (9 tests).

Browser caveat: the full browser suite passes 89 tests but the existing setValueAsyncStrictMode test fails. The same failure reproduces on unchanged source and when run alone. This PR does not change that behavior. Browser checks used the locally installed Chromium executable.

@bluebill1049
bluebill1049 merged commit 7d1bce1 into react-hook-form:master Oct 2, 2026
6 checks passed
@charan-rathore
charan-rathore deleted the fix/controller-blur-after-reset branch October 2, 2026 08:17
bluebill1049 added a commit that referenced this pull request Oct 21, 2026
…idates them (#13925)

* fix(reset): keep mounted controller fields registered so submit still validates them

reset() without keepFieldsRef empties _fields, and a Controller registers
again only when it renders. A Controller that does not rerender after the
reset (React.memo with an unchanged value, or passed as children) stays on
screen unregistered: handleSubmit, trigger() and setFocus() skip it, so a
required field is submitted empty. onChange and onBlur already register it
again (#13497, #13817); these paths do not go through the Controller.

Keep the fields of mounted Controllers whose name is in the reset values,
and add them back to the mounted and disabled names after the reset.

* test(reset): cover unmount, field arrays and isValid for kept controllers

bluebill1049 asked in review whether keeping the mounted Controller
registrations is enough without calling updateValidAndValue() again, and
for tests on unmounting after reset and on field arrays.

The call is still needed. A kept field makes register() skip
updateValidAndValue() when the Controller rerenders, so without it a
reset that changes the value leaves isValid stale. With shouldUnregister
the reset empties _formValues, and the call puts the value back.

The new tests check isValid after a reset that changes the value, that a
Controller unmounted after reset is not kept by the next reset, and that
a reset which removes field array rows keeps none of their names.

* refactor(reset): simplify kept controller registration

---------

Co-authored-by: maxymlyskov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reset(values) silently unregisters all fields until the next render — blur/change validation dead, if (field) guards skip silently

2 participants