Skip to content

fix(compiler-dom): update HTML nesting validation for Chrome 134+ spec #13720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

amachang
Copy link

@amachang amachang commented Jul 30, 2025

Close #13608

Summary

This PR updates Vue's HTML nesting validation to align with the Chrome 134+ HTML5 specification changes that allow new elements as children of <select> and <option>.

Changes Made:

  1. Allow <button> as a child of <select> - Chrome 134+ now supports buttons inside select elements for customizable dropdowns
  2. Allow inline elements as children of <option> - Elements like <span>, <b>, <i>, etc. can now be used to style option content

Implementation Details:

  • Added 'button' to the list of valid children for select elements in htmlNesting.ts
  • Removed 'option' from the emptySet to allow it to have children
  • Added 'option' to knownInvalidChildren with only block-level elements ('div', 'p') restricted, allowing inline elements by default

Testing:

  • Added comprehensive tests for the new HTML5 nesting rules
  • All existing tests continue to pass, ensuring backward compatibility
  • E2E verification shows no warnings for the reported use case

Compatibility:

  • This change only affects development warnings, not runtime behavior
  • Maintains backward compatibility by still preventing block-level elements in options
  • Aligns with the latest HTML5 specification as implemented in Chrome 134+

Test Plan

The following tests were added to verify the fix:

// Chrome 134+ HTML5 spec updates
it('should not warn with select > button', () => {
  // Test passes without warning
})

it('should not warn with option > span', () => {
  // Test passes without warning
})

it('should not warn with option > b', () => {
  // Test passes without warning
})

Additionally, the isValidHTMLNesting unit tests were updated to cover these cases comprehensively.

Related Links

Summary by CodeRabbit

  • New Features
    • Improved support for updated HTML5 nesting rules: <button> elements are now allowed inside <select>, and inline elements like <span>, <b>, <i>, <strong>, and <em> are now valid children of <option>.
  • Bug Fixes
    • Enhanced validation to prevent block-level elements such as <div> and <p> from being nested inside <option>.
  • Tests
    • Added new test cases to ensure validation aligns with the latest HTML5 specification updates.

amachang added 2 commits July 30, 2025 16:31
Add tests for new HTML5 specifications that allow:
- button as child of select
- inline elements (span, b, i, strong, em) as children of option

ref vuejs#13608
Allow new HTML5 nesting patterns:
- button as child of select
- inline elements (span, b, i, strong, em) as children of option

This aligns with the latest HTML specifications supported in Chrome 134+
while maintaining validation for invalid block-level elements.

close vuejs#13608
Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

The HTML nesting validation logic and its associated tests were updated to reflect recent HTML5 specification changes. <button> is now allowed as a child of <select>, and inline elements such as <span>, <b>, <i>, <strong>, and <em> are permitted as children of <option>. The test suite was expanded accordingly.

Changes

Cohort / File(s) Change Summary
HTML Nesting Rules Update
packages/compiler-dom/src/htmlNesting.ts
Updated valid children for <select> and <option> elements; added <button> as valid under <select>, allowed inline elements under <option>, and specified invalid block-level children for <option>.
Test Coverage Expansion
packages/compiler-dom/__tests__/transforms/validateHtmlNesting.spec.ts
Added and extended unit tests to cover new valid nesting scenarios and confirm updated validation logic for <select> and <option>.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant isValidHTMLNesting
    participant htmlNestingRules

    TestSuite->>isValidHTMLNesting: Validate <button> in <select>
    isValidHTMLNesting->>htmlNestingRules: Check allowed children for <select>
    htmlNestingRules-->>isValidHTMLNesting: Return true for <button>
    isValidHTMLNesting-->>TestSuite: No warning

    TestSuite->>isValidHTMLNesting: Validate <b>, <span> in <option>
    isValidHTMLNesting->>htmlNestingRules: Check allowed children for <option>
    htmlNestingRules-->>isValidHTMLNesting: Return true for inline elements
    isValidHTMLNesting-->>TestSuite: No warning

    TestSuite->>isValidHTMLNesting: Validate <div> in <option>
    isValidHTMLNesting->>htmlNestingRules: Check allowed children for <option>
    htmlNestingRules-->>isValidHTMLNesting: Return false for <div>
    isValidHTMLNesting-->>TestSuite: Emit warning
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Allow <button> as child of <select> and inline elements (<b>, <span>, etc.) as children of <option> ([#13608])
Remove warnings for new valid nesting scenarios ([#13608])
Maintain invalid status for block-level elements inside <option> ([#13608])

Poem

In the garden of tags, where selectors roam,
Now <button> finds a <select> its home.
<b> and <span> in <option> may nest,
No warnings will trouble the Vue coder’s rest.
The rabbits rejoice with a hop and a cheer—
HTML5’s new rules are finally here!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/compiler-dom/__tests__/transforms/validateHtmlNesting.spec.ts (1)

40-54: Consider expanding integration test coverage for styled option content.

While these tests correctly verify that inline elements work within <option>, consider adding tests for other allowed inline elements (<i>, <strong>, <em>) and negative cases (block elements that should still warn) to match the comprehensive coverage in the unit tests below.

Add these additional integration tests for better coverage:

  it('should not warn with option > b', () => {
    let err: CompilerError | undefined
    compile(`<select><option><b>Bold text</b></option></select>`, {
      onWarn: e => (err = e),
    })
    expect(err).toBeUndefined()
  })

+  it('should not warn with option > i', () => {
+    let err: CompilerError | undefined
+    compile(`<select><option><i>Italic text</i></option></select>`, {
+      onWarn: e => (err = e),
+    })
+    expect(err).toBeUndefined()
+  })
+
+  it('should warn with option > div', () => {
+    let err: CompilerError | undefined
+    compile(`<select><option><div>Block content</div></option></select>`, {
+      onWarn: e => (err = e),
+    })
+    expect(err).toBeDefined()
+    expect(err!.message).toMatch(`<div> cannot be child of <option>`)
+  })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c875019 and 22876fe.

📒 Files selected for processing (2)
  • packages/compiler-dom/__tests__/transforms/validateHtmlNesting.spec.ts (2 hunks)
  • packages/compiler-dom/src/htmlNesting.ts (2 hunks)
🔇 Additional comments (5)
packages/compiler-dom/src/htmlNesting.ts (2)

66-66: LGTM! Correctly implements Chrome 134+ spec for customizable dropdowns.

Adding 'button' as a valid child of <select> aligns perfectly with the Chrome 134+ HTML5 specification update that enables customizable dropdown functionality.


110-110: Well-designed approach to enable styled option content.

The implementation correctly allows inline styling elements within <option> while maintaining restrictions on block-level elements ('div', 'p'). This targeted approach enables the Chrome 134+ HTML5 spec features while preserving semantic integrity.

packages/compiler-dom/__tests__/transforms/validateHtmlNesting.spec.ts (3)

32-38: LGTM! Good integration test for Chrome 134+ select enhancement.

This test correctly verifies that <button> inside <select> no longer triggers validation warnings, aligning with the Chrome 134+ specification update.


176-184: Excellent comprehensive unit test coverage for select element.

This test thoroughly validates both the new functionality (button as child) and maintains coverage for existing valid children. The test structure and assertions are well-designed.


186-197: Excellent comprehensive unit test coverage for option element.

This test provides thorough coverage of the Chrome 134+ specification changes, testing both positive cases (inline styling elements) and negative cases (block-level elements that remain invalid). The implementation correctly validates the new HTML5 nesting rules.

@@ -63,7 +63,7 @@ const onlyValidChildren: Record<string, Set<string>> = {
'template',
]),
optgroup: new Set(['option']),
select: new Set(['optgroup', 'option', 'hr']),
select: new Set(['optgroup', 'option', 'hr', 'button']),
Copy link
Member

Choose a reason for hiding this comment

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

Per spec, div is also allowed

@@ -63,7 +63,7 @@ const onlyValidChildren: Record<string, Set<string>> = {
'template',
]),
optgroup: new Set(['option']),
Copy link
Member

Choose a reason for hiding this comment

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

Per spec, div is also allowed.

@@ -108,6 +107,7 @@ const onlyValidParents: Record<string, Set<string>> = {

/** maps element to set of elements that can not be it's children, others can */
const knownInvalidChildren: Record<string, Set<string>> = {
option: new Set(['div', 'p']),
Copy link
Member

@Justineo Justineo Jul 30, 2025

Choose a reason for hiding this comment

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

Per spec, option can have div inside.

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.

New allowed HTML Tags as children for <SELECT> and <OPTION>, and data-allow-mismatch does not remove warning
2 participants