{"record":{"id":"af9d6653001b50b8","repo":"slint-ui/slint","slug":"popup-component-is-a-window-item","errorCode":null,"errorMessage":"Popup component is a Window item","messagePattern":"Popup component is a Window item","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/core/window.rs","lineNumber":1752,"sourceCode":"            if let Some(parent) = popup.parent_item.clone().upgrade() {\n                parent.map_to_native_window(\n                    parent.geometry().origin + (popup.position_access)().to_euclid().to_vector(),\n                )\n            } else {\n                LogicalPoint::zero()\n            }\n        };\n        let mut active_popups = self.active_popups.borrow_mut();\n        let Some(popup) = active_popups.iter_mut().find(|p| p.popup_id == popup_id) else { return };\n        match &mut popup.location {\n            PopupWindowLocation::ChildWindow(old_location) => {\n                let (old_popup_region, new_popup_region) =\n                    popup.properties_tracker.as_ref().evaluate_as_dependency_root(|| {\n                        let component = ItemTreeRc::borrow_pin(&popup.component);\n                        let root_item = component.as_ref().get_item_ref(0);\n                        let window_item =\n                            ItemRef::downcast_pin::<crate::items::WindowItem>(root_item)\n                                .expect(\"Popup component is a Window item\");\n                        // Access the properties to set them as dependencies\n                        let old_popup_region = LogicalRect::new(\n                            *old_location,\n                            crate::lengths::LogicalSize::new(\n                                window_item.width().0,\n                                window_item.height().0,\n                            ),\n                        );\n\n                        let width = {\n                            let layout_info_h = component\n                                .as_ref()\n                                .layout_info(crate::layout::Orientation::Horizontal);\n                            let w = layout_info_h\n                                .preferred\n                                .max(layout_info_h.min)\n                                .min(layout_info_h.max);\n                            window_item.width.set(LogicalLength::new(w));","sourceCodeStart":1734,"sourceCodeEnd":1770,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/core/window.rs#L1734-L1770","documentation":"When computing a popup's placement, Slint assumes the popup component's root item is a `WindowItem` and downcasts the root ItemRef with `.expect(\"Popup component is a Window item\")`. The panic means a component used as a popup has a root element that is not a Window — violating the popup contract that popups are declared with `Window { }` as their root.","triggerScenarios":"Calling `show_popup` (directly or via a PopupWindow in .slint) with a component instance whose root item is not a `WindowItem` — e.g. programmatically instantiated popup trees via the interpreter whose root was changed, or backend/window-adapter code passing the wrong component.","commonSituations":"Interpreter/FFI users constructing popup components manually and forgetting the `Window` root; custom code re-rooting popup item trees.","solutions":["Ensure the popup component's root element is `Window { ... }` (for PopupWindow, keep the generated root intact)","When instantiating popups via the interpreter/FFI, instantiate the same component that declares the popup and don't re-parent its root","Inspect `component.as_ref().get_item_ref(0)` and verify the item type before calling show_popup"],"exampleFix":"// before\nlet popup = component_definition.create(...); // component rooted in some non-Window element\nwindow.show_popup(&popup, ...);\n// after\n// in .slint, declare the popup with a Window root and instantiate that component\n// component Win := Window { PopupWindow { ... } }","handlingStrategy":"validation","validationCode":"// verify the popup component's root is a WindowItem before showing\nlet root = component.as_ref().get_item_ref(0);\nassert!(ItemRef::downcast_pin::<slint::items::WindowItem>(root).is_ok(), \"popup root must be a Window\");","typeGuard":"fn is_window_root(comp: &ItemTreeRef) -> bool {\n    ItemRef::downcast_pin::<crate::items::WindowItem>(comp.get_item_ref(0)).is_ok()\n}","tryCatchPattern":"std::panic::catch_unwind(AssertUnwindSafe(|| window.show_popup(&popup, pos, close_on_click))).is_err().then(|| eprintln!(\"popup root is not a Window\"));","preventionTips":["Always declare popups with a `Window` root element in .slint","Never re-parent or re-root popup item trees created by the compiler","In the interpreter, use the component definition that declares the popup"],"tags":["rust","panic","popup","window","downcast"],"backgroundTag":"invalid-argument-value","analyzedSha":"3a7e700487dc74d404cad0726378053ab763d4e0","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}