{"record":{"id":"c5e0dfd4ed8f7059","repo":"swc-project/swc","slug":"somethingseenwhensomethingopen","errorCode":"SomethingSeenWhenSomethingOpen","errorMessage":"Start tag \"{tag_name}\" seen but an element of the same type was already open","messagePattern":"Start tag \"(.+?)\" seen but an element of the same type was already open","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"crates/swc_html_parser/src/parser/mod.rs","lineNumber":1955,"sourceCode":"                            }\n\n                            let popped = self\n                                .open_elements_stack\n                                .pop_until_tag_name_popped(&[\"template\"]);\n\n                            self.update_end_tag_span(popped.as_ref(), token_and_info.span);\n                            self.active_formatting_elements.clear_to_last_marker();\n                            self.template_insertion_mode_stack.pop();\n                            self.reset_insertion_mode();\n                        }\n                    }\n                    // A start tag whose tag name is \"head\"\n                    //\n                    // Any other end tag\n                    //\n                    // Parse error. Ignore the token.\n                    Token::StartTag { tag_name, .. } if tag_name == \"head\" => {\n                        self.errors.push(Error::new(\n                            token_and_info.span,\n                            ErrorKind::SomethingSeenWhenSomethingOpen(tag_name.clone()),\n                        ));\n                    }\n                    Token::EndTag { tag_name, .. } => {\n                        self.errors.push(Error::new(\n                            token_and_info.span,\n                            ErrorKind::StrayEndTag(tag_name.clone()),\n                        ));\n                    }\n                    // Anything else\n                    //\n                    // Pop the current node (which will be the head element) off the stack of open\n                    // elements.\n                    //\n                    // Switch the insertion mode to \"after head\".\n                    //\n                    // Reprocess the token.","sourceCodeStart":1937,"sourceCodeEnd":1973,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_html_parser/src/parser/mod.rs#L1937-L1973","documentation":"The in-head insertion mode (crates/swc_html_parser/src/parser/mod.rs:1955) received a start tag named head while the head element is already the open element. The spec's message for this arm maps to SomethingSeenWhenSomethingOpen — 'start tag seen but an element of the same type was already open'. The token is ignored; the existing head continues.","triggerScenarios":"A second `<head>` start tag while still inside head: `<!DOCTYPE html><html><head><meta charset=\"utf-8\"><head><title>t</title>`. Comments/metadata before it do not close head, so the duplicate lands in this arm.","commonSituations":"Two head partials concatenated by the layout system, boilerplate injected twice by CMS plugins, refactors that moved head content without removing the old wrapper tag.","solutions":["Merge the two head sections into one","Make the layout render exactly one <head> wrapper around all metadata","Filter ErrorKind::SomethingSeenWhenSomethingOpen(tag) with tag == \"head\" if duplicates are benign"],"exampleFix":"<!-- before -->\n<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"utf-8\">\n  <head>\n    <title>t</title>\n  </head>\n</html>\n\n<!-- after -->\n<!DOCTYPE html>\n<html>\n  <head>\n    <meta charset=\"utf-8\">\n    <title>t</title>\n  </head>\n</html>","handlingStrategy":"validation","validationCode":"fn head_start_tag_count(html: &str) -> usize {\n    let lower = html.to_ascii_lowercase();\n    lower\n        .match_indices(\"<head\")\n        .filter(|(i, _)| {\n            // exclude <header ...>\n            lower[*i + 5..].starts_with(|c: char| !(c.is_ascii_alphanumeric() || c == '-'))\n        })\n        .count()\n}","typeGuard":null,"tryCatchPattern":"use swc_html_parser::error::ErrorKind;\n\nlet mut errors = Vec::new();\nlet doc = swc_html_parser::parse_file_as_document(&fm, config, &mut errors)?;\n\nfor err in &errors {\n    if let ErrorKind::SomethingSeenWhenSomethingOpen(tag) = err.kind() {\n        if tag == \"head\" {\n            // Second <head> ignored; its attributes did NOT merge.\n            log::warn!(\"duplicate <head> start tag ignored\");\n        }\n    }\n}","preventionTips":["Only the page shell template may open <head>; partials contribute metadata, not wrappers","Guard against double-rendering head boilerplate in plugin pipelines","Note: the ignored duplicate's attributes are dropped — set lang/class on the first <head>"],"tags":["html","parser","head","duplicate-element","insertion-mode","swc"],"backgroundTag":"duplicate-element-open","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}