{"record":{"id":"f63480fdc91a65f1","repo":"leptos-rs/leptos","slug":"missing-head-element","errorCode":null,"errorMessage":"missing <head> element","messagePattern":"missing <head> element","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"meta/src/lib.rs","lineNumber":122,"sourceCode":"    pub(crate) cursor: Arc<LazyLock<SendWrapper<Cursor>>>,\n}\n\nimpl MetaContext {\n    /// Creates an empty [`MetaContext`].\n    pub fn new() -> Self {\n        Default::default()\n    }\n}\n\npub(crate) const HEAD_MARKER_COMMENT: &str = \"HEAD\";\n/// Return value of [`Node::node_type`] for a comment.\n/// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#node.comment_node\nconst COMMENT_NODE: u16 = 8;\n\nimpl Default for MetaContext {\n    fn default() -> Self {\n        let build_cursor: fn() -> SendWrapper<Cursor> = || {\n            let head = document().head().expect(\"missing <head> element\");\n            let mut cursor = None;\n            let mut child = head.first_child();\n            while let Some(this_child) = child {\n                if this_child.node_type() == COMMENT_NODE\n                    && this_child.text_content().as_deref()\n                        == Some(HEAD_MARKER_COMMENT)\n                {\n                    cursor = Some(this_child);\n                    break;\n                }\n                child = this_child.next_sibling();\n            }\n            SendWrapper::new(Cursor::new(\n                cursor\n                    .expect(\n                        \"no leptos_meta HEAD marker comment found. Did you \\\n                         include the <MetaTags/> component in the <head> of \\\n                         your server-rendered app?\",","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/meta/src/lib.rs#L104-L140","documentation":"MetaContext::default builds a cursor positioned at the head-marker comment inside <head> so metadata can be injected during hydration. It unwraps document().head(), panicking with \"missing <head> element\" if the current document has no <head>. The library assumes a well-formed HTML document exists when leptos_meta runs on the client.","triggerScenarios":"Constructing MetaContext::default() (directly or via leptos_meta's provider/hydration path) when document().head() returns None — e.g. a document with no <head> section, or running in an environment with an incomplete DOM.","commonSituations":"Custom SSR shells that omit <head>, streaming responses where the head chunk was already consumed/removed, or test DOMs built without head elements.","solutions":["Ensure the document being hydrated contains a <head> element (valid HTML shell).","Create MetaContext only in browser environments where a full document exists.","In tests, build the DOM with a <head> containing the <!--HEAD--> marker comment if you exercise meta hydration.","Do not strip <head> from the served markup before hydration."],"exampleFix":"<!-- before: shell missing head -->\n<body>...</body>\n\n<!-- after -->\n<head><!--HEAD--><title>app</title></head>\n<body>...</body>","handlingStrategy":"validation","validationCode":"if document().head().is_none() {\n    console_error!(\"document has no <head>; leptos_meta unavailable\");\n    return;\n}","typeGuard":"fn has_head() -> bool {\n    document().head().is_some()\n}","tryCatchPattern":null,"preventionTips":["Include <head> (with the <!--HEAD--> marker when hydrating meta) in every served document.","Create MetaContext only after DOM readiness in a real browser.","Don't strip the head chunk from streamed SSR output."],"tags":["leptos","meta","dom","hydration"],"backgroundTag":"missing-head-element","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}