zed-industries/zed · error

Missing document body

Error message

Missing document body

What it means

A sentinel error from the Option::ok_or_else guard when document.body() returned None while constructing the safe-area viewport. Browsers always expose a <body> for normal documents, so this fires only in unusual hosting scenarios (synthetic about:blank-like documents, initialization before the body is parsed, or non-HTML documents), and construction of the WebViewport aborts.

Source

Thrown at crates/gpui_web/src/viewport.rs:27

pub(crate) struct WebViewport {
    safe_area_probes: [web_sys::HtmlElement; 4],
    pub(crate) visible_bounds: Bounds<Pixels>,
    pub(crate) insets: WindowInsets,
}

impl WebViewport {
    pub(crate) fn new(document: &web_sys::Document) -> anyhow::Result<Self> {
        let [top, right, bottom, left] =
            ["top", "right", "bottom", "left"].map(|edge| safe_area_probe(document, edge));
        let viewport = Self {
            safe_area_probes: [top?, right?, bottom?, left?],
            visible_bounds: Bounds::default(),
            insets: WindowInsets::default(),
        };
        let body = document
            .body()
            .ok_or_else(|| anyhow::anyhow!("Missing document body"))?;
        for probe in &viewport.safe_area_probes {
            body.append_child(probe)
                .map_err(|error| anyhow::anyhow!("Failed to attach safe-area probe: {error:?}"))?;
        }
        Ok(viewport)
    }

    pub(crate) fn observe_safe_area(&self, observer: &web_sys::ResizeObserver) {
        // Separate boxes detect redistribution between edges even when the
        // total inset, and therefore a single combined probe's size, is unchanged.
        for probe in &self.safe_area_probes {
            observer.observe(probe);
        }
    }

    pub(crate) fn update(
        &mut self,
        window: &web_sys::Window,

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Ensure the app initializes after DOMContentLoaded so document.body exists
  2. If hosting in a synthetic or documentless context, provide or wait for a real HTML document before creating the viewport
  3. Feature-detect document.body and defer viewport creation instead of failing hard
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/gpui_web/src/viewport.rs:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-09-12). Data as JSON: /api/errors/cc36c94dca8a15a8. Report an issue: GitHub.