Skip to content

Conversation

@everettbu
Copy link

@everettbu everettbu commented Dec 12, 2025

Mirror of facebook/react#34804
Original author: josepharhar


Summary

The HTML spec was updated to remove most special parsing rules for select elements: whatwg/html#10548

Chrome shipped these parser changes a while ago, and they have been implemented behind a flag in WebKit.

This PR updates the logic in validateDOMNesting to match the new HTML spec so that authors can use the new parsing rules without getting errors in React.

Fixes facebook/react#33609

How did you test this change?

I updated the test cases in validateDOMNesting-test.js

The HTML spec was updated to remove most special parsing rules for
select elements. This PR updates the logic in validateDOMNesting to
match the new HTML spec so that authors can use the new parsing rules
without getting errors in React.

Fixes facebook/react#33609
@greptile-apps
Copy link

greptile-apps bot commented Dec 12, 2025

Greptile Overview

Greptile Summary

Updated React's DOM nesting validation to align with the HTML spec's removal of special parsing rules for <select> elements (per whatwg/html#10548).

Key changes:

  • Removed restrictive parsing mode for select, optgroup, and option elements that previously only allowed specific children like hr, option, optgroup, script, template, and text nodes
  • Added select to inScopeTags array to match HTML spec's scope definition
  • Added validation to prevent <input> elements inside <select> (as input causes select tags to close per the spec)
  • Updated tests to reflect the new behavior, including allowing <div> inside <option> and complex nesting patterns like select > div > optgroup > div > option > span

This change enables developers to use modern HTML parsing behavior without validation warnings, as shipped in Chrome and implemented behind a flag in WebKit.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes correctly implement the HTML spec update by removing obsolete parsing restrictions. All modifications are well-tested with comprehensive test coverage, the logic is straightforward and mirrors the spec changes, and this aligns with browser implementations already shipped in Chrome and WebKit
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/react-dom-bindings/src/client/validateDOMNesting.js 5/5 Removed restrictive select/optgroup/option parsing rules per HTML spec update, added select to inScopeTags, added input validation to prevent it within select
packages/react-dom/src/tests/validateDOMNesting-test.js 5/5 Updated tests to reflect new parsing rules: added test for select>input validation, added value prop for option elements in test helper, added test for complex select nesting
packages/react-dom/src/tests/ReactDOMOption-test.js 5/5 Removed obsolete validation error tests for div children in option elements to align with new HTML spec

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: validateDOMNesting needs to be updated for new customisable form widgets

3 participants