Skip to content

fix: cancel nested delayError timers when a parent is cleared or unregistered - #13736

Merged
bluebill1049 merged 2 commits into
react-hook-form:masterfrom
soroush5:fix/clear-unregister-cancel-nested-delayed-errors
Sep 11, 2026
Merged

bluebill1049 merged 2 commits into
react-hook-form:masterfrom
soroush5:fix/clear-unregister-cancel-nested-delayed-errors

Conversation

@soroush5

Copy link
Copy Markdown
Contributor

Proposed Changes

Clearing or unregistering a parent field removes the whole nested error subtree from errors, but a pending delayError timer for a nested child (keyed by its full path, e.g. parent.child) survived and put the error back once the delay elapsed. This adds a cancelDelayedErrorTree helper that cancels the exact name plus any nested name.-prefixed timers, and uses it in clearErrors and unregister. The dot boundary keeps sibling fields like test1 untouched when test is cleared.

  • Bug fix
  • New feature
  • Breaking change

Self-review

  • Added regression tests in clearErrors.test.tsx (nested cascade + prefix-boundary guard) and unregister.test.tsx (nested cascade); verified they fail without the fix.
  • Full jest suite passes (122 suites / 1358 tests), tsc and eslint clean.

@bluebill1049
bluebill1049 merged commit b5c210b into react-hook-form:master Sep 11, 2026
6 checks passed
bluebill1049 added a commit that referenced this pull request Sep 20, 2026
…13771)

`executeSchemaAndUpdateState` unsets the whole subtree of each validated
name, but only cancelled that exact name's delayError timer. A timer
already scheduled for a nested field therefore survived the validation
and, when it fired, wrote its stale error back into form state — under a
subtree the resolver had just reported clean.

Use `cancelDelayedErrorTree`, as `clearErrors`, `unregister` and
`resetField` already do for the same reason (#13736, #13769).

Co-authored-by: Bill <[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.

2 participants