DioxusLabs/dioxus · error

Body element to exist

Error message

Body element to exist

What it means

`index_request` injects custom head content into the served index.html by finding the `</head>` tag and `expect`s it to exist. This panic fires when the user-supplied custom index.html has no closing `</head>` tag — the custom index's syntax is at fault.

Solutions

  1. Ensure your index.html contains a <body> element; the desktop renderer mounts the app into <body>.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/desktop/src/protocol.rs:129 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/512cdb657280f25d. Report an issue: GitHub.

Appendix: source

Thrown at packages/desktop/src/protocol.rs:129

    // If the request is for the root, we'll serve the index.html file.
    if request.uri().path() != "/" {
        return None;
    }

    // Load a custom index file if provided
    let mut index = custom_index.unwrap_or_else(|| DEFAULT_INDEX.to_string());

    // Insert a custom head if provided
    // We look just for the closing head tag. If a user provided a custom index with weird syntax, this might fail
    if let Some(head) = custom_head {
        index.insert_str(index.find("</head>").expect("Head element to exist"), &head);
    }

    // Inject our module loader by looking for a body tag
    // A failure mode here, obviously, is if the user provided a custom index without a body tag
    // Might want to document this
    index.insert_str(
        index.find("</body>").expect("Body element to exist"),
        &module_loader(root_name, headless, edit_state),
    );

    Response::builder()
        .header("Content-Type", "text/html")
        .header("Access-Control-Allow-Origin", "*")
        .body(index.into())
        .ok()
}

/// Construct the inline script that boots up the page and bridges the webview with rust code.
///
/// The arguments here:
/// - root_name: the root element (by Id) that we stream edits into
/// - headless: is this page being loaded but invisible? Important because not all windows are visible and the
///   interpreter can't connect until the window is ready.
/// - port: the port that the websocket server is listening on for edits
/// - webview_id: the id of the webview that we're loading this into. This is used to differentiate between

View on GitHub (pinned to 24f6a829df)