-
Notifications
You must be signed in to change notification settings - Fork 78
Fix: Support HTML <selectedcontent>
element
#1101
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 1ee2a88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
"link": true, | ||
"meta": true, | ||
"param": true, | ||
"selectedcontent": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just add selectedcontent, then apply formatting
Thank you @jp-knj The new tests that you added should also generate some snapshots. Can you update them? https://github.com/withastro/compiler/blob/main/CONTRIBUTING.md#snapshot-testing |
- handle selectedcontent as void element only with /> syntax - support button closing tags in select context - prevent incorrect nesting of option elements
// Special handling for selectedcontent end tag - just ignore it | ||
// since it's treated as a void element | ||
if p.tok.Data == "selectedcontent" { | ||
return true | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Ignore End Tags
The Problem Flow:
When HTML contains <selectedcontent></selectedcontent>
:
- Tokenizer generates these tokens:
<selectedcontent>
→ StartTagToken</selectedcontent>
→ EndTagToken
- Parser processing:
- Treats as a void element (can't have children)
- Adds it to DOM, then immediately pops it from the stack
- At this point, selectedcontent is no longer on the stack
- When arrives:
- There's no matching opening tag on the stack
- If we don't ignore it: Parser gets confused and misplaces subsequent elements
What Actually Happened:
<!-- Input -->
<select><button><selectedcontent></selectedcontent></button><option>A</option></select>
<!-- Wrong output (without ignoring the end tag) -->
<select><button><selectedcontent><option>A</option></button></select>
<!-- ↑ option becomes a child of selectedcontent (WRONG!) -->
// Handle closing tags for elements that are allowed in customizable select | ||
// (like button for the new HTML select element) | ||
if p.tok.Data == "button" { | ||
// Close the button if it's open | ||
for i := len(p.oe) - 1; i >= 0; i-- { | ||
if p.oe[i].Data == "button" { | ||
p.oe = p.oe[:i] | ||
break | ||
} | ||
} | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why support </button>
tags in select context
- In standard HTML, a
<button>
is not allowed inside a<select>
. - The Customizable Select feature, however, allow interactive content (including
<button>
) inside<select>
.
Supporting</button>
here is forward-compatible with that model.
before
EndTag </button>
Stack before: <html> <select> <button>
Stack after: <html> <select> <button> ← button NOT closed!
StartTag <option>
Stack after: <html> <select> <button> <option> ← option becomes child of button (WRONG!)
After
EndTag </button>
Stack before: <html> <select> <button>
Stack after: <html> <select> ← button correctly closed
StartTag <option>
Stack after: <html> <select> <option> ← option is direct child of select (CORRECT!)
updated |
Closes #1093
Background
The
<selectedcontent>
element is used inside customizable<select>
elements to display the currently selected option within a custom button. It's part of the new web standard for styleable select elements that's been years in the making.Problem
Without this fix, the Astro compiler treats as a regular container element, causing it to incorrectly consume all following elements until the parent's closing tag. This breaks the structure of customizable select elements.
Before: Options incorrectly nested inside selectedcontent
After: Correct structure with selectedcontent as void element
Changes
<selectedcontent>
element:selectedcontent
as self-closing when it has the/>
syntax<selectedcontent></selectedcontent>
selectedcontent
as a void element</selectedcontent>
end tags, Add support for closing</button>
tags within select contextselectedcontent
in the voidElements mapTesting
<selectedcontent></selectedcontent>
and<selectedcontent />
syntaxReferences