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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ describe('validate html nesting', () => {
})
expect(err).toBeUndefined()
})

// #13608 - Chrome 134+ HTML5 spec updates
it('should not warn with select > button', () => {
let err: CompilerError | undefined
compile(`<select><button>Click me</button></select>`, {
onWarn: e => (err = e),
})
expect(err).toBeUndefined()
})

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

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()
})
})

/**
Expand Down Expand Up @@ -148,6 +173,29 @@ describe('isValidHTMLNesting', () => {
expect(isValidHTMLNesting('h1', 'div')).toBe(true)
})

test('select - Chrome 134+ allows button as child', () => {
// These should be valid according to new HTML5 spec (Chrome 134+)
expect(isValidHTMLNesting('select', 'button')).toBe(true)

// Traditional valid children should still work
expect(isValidHTMLNesting('select', 'option')).toBe(true)
expect(isValidHTMLNesting('select', 'optgroup')).toBe(true)
expect(isValidHTMLNesting('select', 'hr')).toBe(true)
})

test('option - Chrome 134+ allows styled content', () => {
// These should be valid according to new HTML5 spec (Chrome 134+)
expect(isValidHTMLNesting('option', 'span')).toBe(true)
expect(isValidHTMLNesting('option', 'b')).toBe(true)
expect(isValidHTMLNesting('option', 'i')).toBe(true)
expect(isValidHTMLNesting('option', 'strong')).toBe(true)
expect(isValidHTMLNesting('option', 'em')).toBe(true)

// Block-level elements might still be invalid
expect(isValidHTMLNesting('option', 'div')).toBe(false)
expect(isValidHTMLNesting('option', 'p')).toBe(false)
})

describe('SVG', () => {
test('svg', () => {
// invalid non-svg tags as children
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-dom/src/htmlNesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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

// table
table: new Set(['caption', 'colgroup', 'tbody', 'tfoot', 'thead']),
tr: new Set(['td', 'th']),
Expand All @@ -74,7 +74,6 @@ const onlyValidChildren: Record<string, Set<string>> = {
// these elements can not have any children elements
script: emptySet,
iframe: emptySet,
option: emptySet,
textarea: emptySet,
style: emptySet,
title: emptySet,
Expand Down Expand Up @@ -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.

p: new Set([
'address',
'article',
Expand Down