Skip to content

⏳ feat: add opt-in delayError option for setValue - #13337

Merged
bluebill1049 merged 6 commits into
react-hook-form:masterfrom
candymask0712:fix-#12992-add-delayError-option-for-setValue-and-trigger
Jul 10, 2026
Merged

⏳ feat: add opt-in delayError option for setValue#13337
bluebill1049 merged 6 commits into
react-hook-form:masterfrom
candymask0712:fix-#12992-add-delayError-option-for-setValue-and-trigger

Conversation

@candymask0712

Copy link
Copy Markdown
Contributor

to resolve#12992

Issue

useForm({ delayError: 2000 }) is ignored when triggering validation via setValue('field', value, { shouldValidate: true }) — errors are displayed immediately instead of after the configured delay.

As @awwwdev reported, there is currently no way to programmatically change an input value and have delayError take effect for showing error messages.

Cause

The setValuesetFieldValuetrigger() path bypasses shouldRenderByError(), which is the only path that applies the delayError logic. trigger() sets errors directly in _formState.errors and
emits them immediately via _subjects.state.next().

Solution

Added an opt-in delayError: boolean option to SetValueConfig. When setValue is called with { shouldValidate: true, delayError: true }, the option is forwarded to trigger(), which removes the
error from _formState.errors and re-applies it after the form-level delayError duration using the existing shared debounce/timer mechanism (consistent with shouldRenderByError).

Note: api-extractor.md.api.md includes additional formatting updates from upstream code changes that were not yet reflected in the report.

@candymask0712
candymask0712force-pushed the fix-#12992-add-delayError-option-for-setValue-and-trigger branch from c2b9aa4 to 5fa275bCompareMarch 26, 2026 17:08
@candymask0712candymask0712 changed the title fix: add opt-in delayError option for setValue🐞 fix: add opt-in delayError option for setValueMar 26, 2026
@bluebill1049bluebill1049 changed the title 🐞 fix: add opt-in delayError option for setValue⏳ feat: add opt-in delayError option for setValueApr 1, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in mechanism for setValue(..., { shouldValidate: true }) to respect the form-level delayError behavior, addressing issue #12992 where validation errors were emitted immediately.

Changes:

  • Added delayError boolean to SetValueConfig and propagated it through setValuesetFieldValuetrigger.
  • Implemented delayed error emission logic inside trigger() when explicitly enabled.
  • Added test coverage for delayed vs immediate error behavior when using setValue validation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

FileDescription
src/types/form.tsExtends SetValueConfig with a new opt-in flag for delayed error handling.
src/logic/createFormControl.tsForwards the new option into trigger() and applies delayed error scheduling there.
src/__tests__/useForm/formState.test.tsxAdds regression tests for delayed/immediate/cancelled error display via setValue.
reports/api-extractor.md.api.mdUpdates API extractor output for the new SetValueConfig field (plus upstream formatting shift).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/types/form.ts
Comment threadsrc/logic/createFormControl.ts
Comment threadsrc/logic/createFormControl.ts
@candymask0712

Copy link
Copy Markdown
ContributorAuthor

@bluebill1049
Hello, Bill.
The delayError logic adds ~20 bytes to the bundle, so I bumped the bundlewatch limit from 12.5 kB to 12.6 kB.
Let me know if you'd prefer a different approach.

@bluebill1049

Copy link
Copy Markdown
Member

yea, no worries. we will get this feature out in the following weeks 🙏 thanks for the patient.

@candymask0712

Copy link
Copy Markdown
ContributorAuthor

@bluebill1049 I got it. Thanks for comment!

@bluebill1049
bluebill1049 merged commit 95da27a into react-hook-form:masterJul 10, 2026
6 checks passed
@candymask0712
candymask0712 deleted the fix-#12992-add-delayError-option-for-setValue-and-trigger branch August 1, 2026 10:23
Sign up for freeto 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: setValue (with shouldValidate) does not respect delayError config

3 participants

@candymask0712@bluebill1049