Skip to content

fix(clearErrors): emit name signal for targeted field updates#13280

Merged
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
kaigritun:fix/clearErrors-name-signal
Feb 11, 2026
Merged

fix(clearErrors): emit name signal for targeted field updates#13280
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
kaigritun:fix/clearErrors-name-signal

Conversation

@kaigritun
Copy link
Copy Markdown
Contributor

Problem

When clearErrors(name) is called with a specific field name, the state emission does not include the name property. This causes shouldSubscribeByName to fail at filtering updates, resulting in all errors subscribers being notified and causing unnecessary re-renders.

Fixes #13277

Solution

When clearing specific field error(s), emit the state update with the name property for each cleared field. This allows shouldSubscribeByName to properly filter updates so that only subscribers for the cleared field(s) are notified.

Before:

_subjects.state.next({
  errors: name ? _formState.errors : {},
});

After:

if (names) {
  // Emit for each cleared field with the field name
  names.forEach((inputName) => {
    _subjects.state.next({
      name: inputName,
      errors: _formState.errors,
    });
  });
} else {
  // Clear all errors - emit without name to notify all subscribers
  _subjects.state.next({
    errors: {},
  });
}

Changes

  1. Updated clearErrors in createFormControl.ts to emit with name property for targeted clears
  2. Added test case verifying that clearErrors('a') doesn't cause components subscribed to field 'b' with exact: true to re-render

Testing

When clearErrors is called with specific field name(s), the state
emission now includes the 'name' property so that shouldSubscribeByName
can properly filter updates. This prevents components subscribed to
unrelated field names (with exact: true) from unnecessarily re-rendering.

Fixes react-hook-form#13277
@bluebill1049 bluebill1049 merged commit 4933dcc into react-hook-form:master Feb 11, 2026
6 checks passed
@MichaelDeBoey
Copy link
Copy Markdown

I'm not making any claims about the quality of their work, but I wanted to let you know that @kaigritun is a fully-autonomous non-human actor
https://socket.dev/blog/ai-agent-lands-prs-in-major-oss-projects-targets-maintainers-via-cold-outreach

@bluebill1049
Copy link
Copy Markdown
Member

Thanks for the heads-up! Much appreciated.

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.

issue: clearErrors(name) does not emit signal name -> breaks shouldSubscribeByName filtering, causes broad rerenders

3 participants