{"record":{"id":"14c9d5d7bed89e75","repo":"slint-ui/slint","slug":"cannot-create-component-instance-err","errorCode":null,"errorMessage":"Cannot create component instance: {err}","messagePattern":"Cannot create component instance: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/viewer/remote.rs","lineNumber":409,"sourceCode":"            )?;\n            return Ok(());\n        }\n        PreviewCompilation::ComponentNotFound => {\n            swap_to_placeholder(\n                placeholder,\n                user_instance,\n                chrome,\n                \"Component not found\",\n                RemoteViewerState::PreviewError,\n            )?;\n            return Ok(());\n        }\n        PreviewCompilation::Unavailable => return Ok(()),\n    };\n\n    let new_instance = component\n        .create_with_existing_window(placeholder.window())\n        .map_err(|err| anyhow::anyhow!(\"Cannot create component instance: {err}\"))?;\n\n    new_instance.show().map_err(|err| anyhow::anyhow!(\"Cannot show component: {err}\"))?;\n    *user_instance = Some(new_instance);\n    // The placeholder is hidden now, but keep its state property truthful.\n    placeholder.set_state(RemoteViewerState::Previewing);\n    Ok(())\n}\n\n/// Everything on the placeholder screen that doesn't depend on what the\n/// connection is doing.\n///\n/// [`swap_to_placeholder`] builds a whole new window each time, so anything\n/// missing from [`Chrome::apply`] silently disappears the first time the\n/// preview is swapped out.\nstruct Chrome {\n    /// Newline-separated `ip:port` list the editor can be pointed at.\n    address: String,\n    /// Friendly device name. Bonjour can rename us on iOS resume, so this","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/tools/viewer/remote.rs#L391-L427","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the editor (slint-lsp/preview) and the remote viewer are built from the same slint version; rebuild both.","Retry the preview request: call show_current again so the placeholder is reinstalled and a fresh compile+instantiate cycle runs.","Check that the placeholder window is valid and shown/adoptable on this platform backend before swapping in the user component.","Check the inner interpreter error message for the specific cause (window mismatch, invalid component) and address that backend issue."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match build_and_show(&preview_component, placeholder, user_instance, preview_session, chrome).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().starts_with(\"Cannot create component instance\") => {\n        // unrecoverable platform/runtime mismatch: reinstall placeholder and reconnect\n        tracing::error!(\"{e:#}\");\n        // let the run loop tear down and re-run show_current on the next preview request\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep the remote viewer and the editor's slint version identical; ship them together.","Never tear down the placeholder window while build_and_show is swapping instances.","Serialize preview updates so hot-reload events cannot race show_current.","Test on the target platform backend before deploying to embedded devices."],"tags":["slint","interpreter","component-instantiation","remote-viewer"],"backgroundTag":"component-instantiation-failed","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}