#12403·swc

`@swc/html` parser drops customizable-select markup (`<button>`, `<selectedcontent>`, rich `<option>` content)

Author: oddharshCreated Sep 22, 2026Updated Sep 22, 2026

Describe the bug

The parser predates customizable select, so it treats that markup as stray tags and drops it. The HTML Standard permits <button> and <selectedcontent> inside <select>, and phrasing content inside <option> (selectedcontent is §4.10.17).

Measured on 1.16.2, with a doctype so the only errors reported are the relevant ones:

in : <!DOCTYPE html><select><button><selectedcontent></selectedcontent></button><option><span>Red</span> apple</option></select>
out: <!doctype html><select><option>Red apple</select>
Stray start tag "button"
Stray start tag "selectedcontent"
Stray end tag "selectedcontent"
Stray end tag "button"
Stray start tag "span"
Stray end tag "span"

So <button>, <selectedcontent> and the <span> are all discarded. This is markup loss rather than a formatting difference: <selectedcontent> is what mirrors the selected option's content into the button, so a page minified through this renders differently from its source.

Input code

xml
<!DOCTYPE html><select><button><selectedcontent></selectedcontent></button><option><span>Red</span> apple</option></select>

Config

json
{}

Link to the code that reproduces this issue

@swc/html has no playground, so the repro is inline. Save as repro.mjs, then npm i @swc/[email protected] && node repro.mjs:

javascript
// npm i @swc/[email protected] && node swc-html-customizable-select.mjs
//
// Customizable select is in the HTML Standard: <button> and <selectedcontent>
// are permitted in <select>, and <option> takes phrasing content.
// https://html.spec.whatwg.org/multipage/form-elements.html#the-selectedcontent-element
import { minify } from "@swc/html";

const html = `<!DOCTYPE html><select><button><selectedcontent></selectedcontent></button><option><span>Red</span> apple</option></select>`;
const r = await minify(Buffer.from(html), {});
console.log("in :", html);
console.log("out:", r.code);
console.log("errors:", r.errors.map((e) => e.message));

// Output on 1.16.2:
// out: <!doctype html><select><option>Red apple</select>
// errors: [ 'Stray start tag "button"', 'Stray start tag "selectedcontent"',
//           'Stray end tag "selectedcontent"', 'Stray end tag "button"',
//           'Stray start tag "span"', 'Stray end tag "span"' ]

Expected behavior

The elements survive minification, and no stray-tag errors are reported for markup the standard permits.

Actual behavior

Six stray-tag errors, and the elements are dropped from the output.

Version

@swc/html 1.16.2

Additional context

This needs tree-construction changes rather than a tokenizer tweak, since the in-select insertion mode is what rejects these elements. Filing it as a report rather than a PR for that reason; happy to test a branch.