swc-project/swc · error · Error
Unclosed elements on stack
Error message
Unclosed elements on stack
What it means
HTML parse error raised near EOF/table handling (StrayStartTag family path): when processing the token, elements remained unclosed on the stack of open elements where the spec expects them closed, e.g. a caption/table-related start tag seen with no matching scope. The error is recorded and the tree builder recovers by popping/generating implied end tags.
Source
Thrown at crates/swc_html_parser/src/parser/mod.rs:5000
| "tbody"
| "td"
| "tfoot"
| "th"
| "thead"
| "tr"
) =>
{
if !self.open_elements_stack.has_in_table_scope("caption") {
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::StrayStartTag(tag_name.clone()),
));
} else {
self.open_elements_stack.generate_implied_end_tags();
match self.open_elements_stack.items.last() {
Some(node) if !is_html_element!(node, "caption") => {
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::UnclosedElementsOnStack,
));
}
_ => {}
}
self.open_elements_stack
.pop_until_tag_name_popped(&["caption"]);
self.active_formatting_elements.clear_to_last_marker();
self.insertion_mode = InsertionMode::InTable;
self.process_token(token_and_info, None)?;
}
}
Token::EndTag { tag_name, .. } if tag_name == "table" => {
if !self.open_elements_stack.has_in_table_scope("caption") {
self.errors.push(Error::new(
token_and_info.span,View on GitHub (pinned to 5176682b65)
Solutions
- Close all table/caption elements with matching end tags
- Ensure the table structure (table>caption>colgroup/thead/tbody>tr>td) is well formed
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_html_parser/src/parser/mod.rs:5000 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/dafe07942065ecde.
Report an issue: GitHub.