slint-ui/slint · error

Cannot create component instance

Error message

Cannot create component instance: {err}

What it means

ComponentInstance::create_with_existing_window failed while build_and_show tried to instantiate the compiled preview component into the existing remote-viewer window. The interpreter reports a component-creation error (e.g. the component reference is invalid for this runtime or the window could not be adopted), which is wrapped in anyhow as an unrecoverable failure — unlike compile errors, this one propagates instead of reinstalling the placeholder.

Solutions

  1. Ensure the editor (slint-lsp/preview) and the remote viewer are built from the same slint version; rebuild both.
  2. Retry the preview request: call show_current again so the placeholder is reinstalled and a fresh compile+instantiate cycle runs.
  3. Check that the placeholder window is valid and shown/adoptable on this platform backend before swapping in the user component.
  4. Check the inner interpreter error message for the specific cause (window mismatch, invalid component) and address that backend issue.
Defensive patterns

Strategy: retry

Try / catch

match build_and_show(&preview_component, placeholder, user_instance, preview_session, chrome).await {
    Ok(()) => {},
    Err(e) if e.to_string().starts_with("Cannot create component instance") => {
        // unrecoverable platform/runtime mismatch: reinstall placeholder and reconnect
        tracing::error!("{e:#}");
        // let the run loop tear down and re-run show_current on the next preview request
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: build_and_show receives PreviewCompilation::Ready from preview_session.compile_component, but create_with_existing_window(placeholder.window()) rejects the instantiation: the component's runtime version mismatches the viewer's interpreter, the window is in an invalid state, or the component cannot be instantiated into that window.

Common situations: Editor and remote viewer run different slint versions so the compiled component data is incompatible; the preview window was torn down mid-swap; a hot reload races the instance swap in show_current; platform/window-backend failure on the embedded device.

Related errors


AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16). Data as JSON: /api/errors/14c9d5d7bed89e75. Report an issue: GitHub.

Appendix: source

Thrown at tools/viewer/remote.rs:409

            )?;
            return Ok(());
        }
        PreviewCompilation::ComponentNotFound => {
            swap_to_placeholder(
                placeholder,
                user_instance,
                chrome,
                "Component not found",
                RemoteViewerState::PreviewError,
            )?;
            return Ok(());
        }
        PreviewCompilation::Unavailable => return Ok(()),
    };

    let new_instance = component
        .create_with_existing_window(placeholder.window())
        .map_err(|err| anyhow::anyhow!("Cannot create component instance: {err}"))?;

    new_instance.show().map_err(|err| anyhow::anyhow!("Cannot show component: {err}"))?;
    *user_instance = Some(new_instance);
    // The placeholder is hidden now, but keep its state property truthful.
    placeholder.set_state(RemoteViewerState::Previewing);
    Ok(())
}

/// Everything on the placeholder screen that doesn't depend on what the
/// connection is doing.
///
/// [`swap_to_placeholder`] builds a whole new window each time, so anything
/// missing from [`Chrome::apply`] silently disappears the first time the
/// preview is swapped out.
struct Chrome {
    /// Newline-separated `ip:port` list the editor can be pointed at.
    address: String,
    /// Friendly device name. Bonjour can rename us on iOS resume, so this

View on GitHub (pinned to bb937076de)