DioxusLabs/dioxus · error

no global `window` exists

Error message

no global `window` exists

What it means

The web renderer tried to access the global window while appending an element to the head, but none exists. The code is running outside a browser DOM environment (e.g. SSR or a worker without window).

Source

Thrown at packages/web/src/document.rs:172

                props.style_contents().ok().as_deref(),
            );
        });
    }

    /// Create a new link tag in the head
    fn create_link(&self, props: LinkProps) {
        queue_effect(move || {
            _ = append_element_to_head("link", &props.attributes(), None);
        });
    }
}

fn append_element_to_head(
    local_name: &str,
    attributes: &Vec<(&'static str, String)>,
    text_content: Option<&str>,
) -> Result<(), JsValue> {
    let window = web_sys::window().expect("no global `window` exists");
    let document = window.document().expect("should have a document on window");
    let head = document.head().expect("document should have a head");

    let element = document.create_element(local_name)?;
    for (name, value) in attributes {
        element.set_attribute(name, value)?;
    }
    if text_content.is_some() {
        element.set_text_content(text_content);
    }
    head.append_child(&element)?;

    Ok(())
}

/// Required to avoid blocking the Rust WASM thread.
const PROMISE_WRAPPER: &str = r#"
    return (async function(){

View on GitHub (pinned to 24f6a829df)

Solutions

  1. Run this code in a browser/WASM context where a global `window` exists; it cannot run in SSR or non-web targets.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/web/src/document.rs:172 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/84579eb981ab9aa5. Report an issue: GitHub.