Skip to content

fix: watch() returning undefined immediately after reset() - Issue #13088#13091

Merged
bluebill1049 merged 3 commits intoreact-hook-form:masterfrom
scato3:fix/watch-undefined-after-reset
Oct 10, 2025
Merged

fix: watch() returning undefined immediately after reset() - Issue #13088#13091
bluebill1049 merged 3 commits intoreact-hook-form:masterfrom
scato3:fix/watch-undefined-after-reset

Conversation

@scato3
Copy link
Contributor

@scato3 scato3 commented Oct 10, 2025

Set _state.mount to true in _reset function to ensure watch() returns the correct value immediately after reset() is called.

Previously, when reset() was called without any prior field interaction, _state.mount remained false, causing _getWatch to return _defaultValues instead of the updated _formValues.

  • Added _state.mount = true after updating _formValues in _reset
  • Added test case to verify watch() returns updated value after reset()
  • Updated existing test expectation to match new behavior

Fixes #13088

Comment on lines -1413 to -1416
_state.mount =
!_proxyFormState.isValid ||
!!keepStateOptions.keepIsValid ||
!!keepStateOptions.keepDirtyValues;
Copy link
Member

Choose a reason for hiding this comment

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

This would probably lead to some regression on user don't want to run

  • update dirty values
  • valid state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've addressed your feedback and made the changes. Could you please take a look?

The fix now preserves the original 3 conditional mount checks and adds an additional condition specifically for the reset

@scato3 scato3 force-pushed the fix/watch-undefined-after-reset branch from 73e78c8 to d20003e Compare October 10, 2025 06:32
Copy link
Member

@bluebill1049 bluebill1049 left a comment

Choose a reason for hiding this comment

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

LGTM

@bluebill1049 bluebill1049 merged commit af84a5d into react-hook-form:master Oct 10, 2025
6 checks passed
hasnainDevX pushed a commit to hasnainDevX/react-hook-form that referenced this pull request Oct 12, 2025
…eact-hook-form#13088 (react-hook-form#13091)

* fix: watch() returning undefined immediately after reset() - Issue react-hook-form#13088

* fix: restore _state.mount assignment in createFormControl function

---------

Co-authored-by: Bill <bluebill1049@hotmail.com>
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: watch() returns undefined immediately after reset() in v7.63.0+

2 participants