{"record":{"id":"e864ed0ba3f9ad8e","repo":"DioxusLabs/dioxus","slug":"should-have-a-document-on-window","errorCode":null,"errorMessage":"should have a document on window","messagePattern":"should have a document on window","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/web/src/document.rs","lineNumber":173,"sourceCode":"            );\n        });\n    }\n\n    /// Create a new link tag in the head\n    fn create_link(&self, props: LinkProps) {\n        queue_effect(move || {\n            _ = append_element_to_head(\"link\", &props.attributes(), None);\n        });\n    }\n}\n\nfn append_element_to_head(\n    local_name: &str,\n    attributes: &Vec<(&'static str, String)>,\n    text_content: Option<&str>,\n) -> Result<(), JsValue> {\n    let window = web_sys::window().expect(\"no global `window` exists\");\n    let document = window.document().expect(\"should have a document on window\");\n    let head = document.head().expect(\"document should have a head\");\n\n    let element = document.create_element(local_name)?;\n    for (name, value) in attributes {\n        element.set_attribute(name, value)?;\n    }\n    if text_content.is_some() {\n        element.set_text_content(text_content);\n    }\n    head.append_child(&element)?;\n\n    Ok(())\n}\n\n/// Required to avoid blocking the Rust WASM thread.\nconst PROMISE_WRAPPER: &str = r#\"\n    return (async function(){\n        {JS_CODE}","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/web/src/document.rs#L155-L191","documentation":"`append_element_to_head` gets the global window and `expect`s a document to exist on it. This panic fires when running outside a proper browser context where `window.document()` returns None — e.g. a headless/fragmented web context — while trying to add meta/script/style/link elements to the head.","triggerScenarios":"Thrown at packages/web/src/document.rs:173 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the code runs in a browser context where `window.document` is available; guard against non-web targets."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}