{"record":{"id":"11bcbc97732fa2ed","repo":"slint-ui/slint","slug":"the-root-item-of-a-systemtrayicon-rooted-component-is-a","errorCode":null,"errorMessage":"the root item of a SystemTrayIcon-rooted component is a SystemTrayIcon","messagePattern":"the root item of a SystemTrayIcon-rooted component is a SystemTrayIcon","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/interpreter/api.rs","lineNumber":1632,"sourceCode":"impl ComponentInstance {\n    /// Return the [`ComponentDefinition`] that was used to create this instance.\n    pub fn definition(&self) -> ComponentDefinition {\n        ComponentDefinition { inner: std::rc::Rc::new(self.inner.definition()) }\n    }\n\n    fn is_system_tray_rooted(&self) -> bool {\n        self.inner.top_level_type() == i_slint_compiler::llr::TopLevelComponentType::SystemTrayIcon\n    }\n\n    /// Set `visible` directly on the root SystemTrayIcon native item, mirroring\n    /// what the Rust/C++ generators emit for tray-rooted public components:\n    /// the change-tracker on the item dispatches the value to the platform handle.\n    fn set_tray_icon_visible(&self, visible: bool) {\n        // The native SystemTrayIcon is item 0 of the root sub-component.\n        let item_rc = ItemRc::new(vtable::VRc::into_dyn(self.inner.vrc().clone()), 0);\n        let tray = item_rc\n            .downcast::<SystemTrayIcon>()\n            .expect(\"the root item of a SystemTrayIcon-rooted component is a SystemTrayIcon\");\n        tray.as_pin_ref().visible.set(visible);\n    }\n\n    /// Return the value for a public property of this component.\n    ///\n    /// ## Examples\n    ///\n    /// ```\n    /// # i_slint_backend_testing::init_no_event_loop();\n    /// use slint_interpreter::{ComponentDefinition, Compiler, Value, SharedString};\n    /// let code = r#\"\n    ///     export component MyWin inherits Window {\n    ///         in-out property <int> my_property: 42;\n    ///     }\n    /// \"#;\n    /// let mut compiler = Compiler::default();\n    /// let result = spin_on::spin_on(\n    ///     compiler.build_from_source(code.into(), Default::default()));","sourceCodeStart":1614,"sourceCodeEnd":1650,"githubUrl":"https://github.com/slint-ui/slint/blob/3a7e700487dc74d404cad0726378053ab763d4e0/internal/interpreter/api.rs#L1614-L1650","documentation":"`set_tray_icon_visible` downcasts the root item (index 0 of the root sub-component) to `SystemTrayIcon` and panics if the cast fails. The invariant holds only when the component's top-level type is actually `SystemTrayIcon`; calling this setter on a component whose root is a `Window` or other type breaks the assumption. This is an internal method guarded by the component's `top_level_type`, so the panic signals an API-surface/state mismatch.","triggerScenarios":"Calling `set_tray_icon_visible` on a `ComponentInstance` whose root component does not inherit `SystemTrayIcon` — e.g. after refactoring removed the `top_level_type()` guard or the method is invoked on a windowed component by mistake.","commonSituations":"Developers using interpreter internals to manipulate tray icons hit this when they attach the wrong `.slint` file (one declaring a `Window` root) or when a wrapper library calls the setter unconditionally.","solutions":["Only call `set_tray_icon_visible` when `component_instance.window_adapter_ref`-style checks or `top_level_type() == TopLevelComponentType::SystemTrayIcon` confirm a tray-icon root","Guard the call site by checking the component's declared root type before invoking","If you support mixed components, route through the public `SystemTrayIcon` element API (`set_visible`) instead of internals","Update the Slint interpreter if a regression removed the internal type check"],"exampleFix":"// before\ninstance.set_tray_icon_visible(true); // panics if root isn't SystemTrayIcon\n// after\nif instance.top_level_type() == i_slint_compiler::llr::TopLevelComponentType::SystemTrayIcon {\n    instance.set_tray_icon_visible(true);\n}","handlingStrategy":"validation","validationCode":"if instance.top_level_type() == i_slint_compiler::llr::TopLevelComponentType::SystemTrayIcon {\n    instance.set_tray_icon_visible(true);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `top_level_type()` before any tray-icon-specific call","Keep a compile-time guarantee that the .slint root is SystemTrayIcon when using tray APIs","Don't call internal setters unconditionally in wrapper libraries"],"tags":["interpreter","rust","panic","tray-icon"],"backgroundTag":"type-mismatch","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"}