Skip to content

fix: apply defaults to untouched selects with disabled optgroups - #13953

Merged
bluebill1049 merged 2 commits into
react-hook-form:masterfrom
charan-rathore:fix/pre-ready-disabled-optgroup
Oct 28, 2026
Merged

bluebill1049 merged 2 commits into
react-hook-form:masterfrom
charan-rathore:fix/pre-ready-disabled-optgroup

Conversation

@charan-rathore

@charan-rathore charan-rathore commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Proposed Changes

An untouched single select with its first option inside a disabled optgroup is mistaken for a pre-hydration edit. The browser skips that option, but its own disabled property remains false. RHF then retains the browser-selected value instead of applying defaultValues and marks the field dirty. For example, a disabled group containing A followed by B/C retains B despite defaultValues: { choice: 'c' }.

Exclude options whose parent is a disabled optgroup when finding the browser's initial enabled option. Real user edits remain preserved. This is a follow-up to #13872, found while reviewing that path; no issue was filed. It does not change reset's disabled-field registry or add a public API/dependency.

Type of change

  • Bug fix

Checklist

  • Code follows the project style
  • Self-reviewed the focused diff
  • No new warnings in changed files
  • Added tests proving the fix and preserving user edits
  • New and existing tests pass locally

Validation on Node 22.23.2 and pnpm 11.21.0, based on master a8e1103:

  • Source-only revert: one regression fails, four added controls pass. Patched: 129 suites, 1,767 tests, 26 snapshots pass.
  • TypeScript, type tests, build/export checks, API extraction, formatting and lint pass. Full lint reports 570 warnings; changed files have none. API Extractor retains its TS compiler-version advisory.
  • All 90 existing browser tests pass using installed Brave. A separate 12-case scratch browser matrix passes hydration, dirty-state and actual submit-payload checks for disabled/enabled optgroups, directly disabled options, multiple selects, listboxes and explicit server selections, with/without pre-hydration edits.
  • Initial scratch browser run had two invalid-hook failures during lazy React server-renderer optimization. Explicit initial Vite preoptimization resolved the harness issue; all 12 cases then passed. No library changes were made for that harness correction. Browser tests used a dedicated local port and the freshly built package; other browsers were not tested.

AI-assisted implementation and verification with Codex; Jev supplied bounded engineering decisions.

@charan-rathore
charan-rathore marked this pull request as ready for review October 28, 2026 04:22
@bluebill1049
bluebill1049 merged commit ef9e351 into react-hook-form:master Oct 28, 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