Skip to content

fix: synchronize useWatch cache when compute is omitted - #13987

Merged
bluebill1049 merged 2 commits into
react-hook-form:masterfrom
wozhenbang2004:fix/watch-compute-cache-after-toggle
Nov 6, 2026
Merged

bluebill1049 merged 2 commits into
react-hook-form:masterfrom
wozhenbang2004:fix/watch-compute-cache-after-toggle

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Proposed Changes

When compute is omitted temporarily, useWatch publishes raw form values but leaves its comparison cache holding the previous computed output. After compute is restored, a subsequent form update can produce that earlier output and incorrectly skip the state update, leaving the raw value visible.

For example, computing "a" as "A", omitting compute while setting "b", then restoring compute and setting "a" leaves "b" instead of "A".

Keep the comparison cache synchronized with the raw value passed to updateValue. Add regressions through Watch for both a string result and a valid undefined result. This changes no subscriptions or effect dependencies.

Validation with Node 22:

  • pnpm test --ci --runInBand: 133 suites, 1,832 tests and 26 snapshots passed. Both new regressions fail without the source fix.
  • pnpm type, pnpm test:type, pnpm lint, and Prettier passed.
  • pnpm e2e --config ../rhf-playwright.config.ts --workers=1 --retries=0: all 90 tests passed. The local config selects Chromium 149 and starts the normal pnpm start server; tests and assertions are unchanged. An initial two-worker run hit the existing asynchronous StrictMode timing case; it passed in isolation and in the complete one-worker run.
  • pnpm build, pnpm api-extractor, and pnpm api-extractor:ci passed.

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

@bluebill1049
bluebill1049 merged commit 1ad12fb into react-hook-form:master Nov 6, 2026
6 checks passed
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