{"record":{"id":"513fc0c4980bfa4f","repo":"leptos-rs/leptos","slug":"placeholder-parent-should-be-element","errorCode":null,"errorMessage":"placeholder parent should be Element","messagePattern":"placeholder parent should be Element","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tachys/src/renderer/dom.rs","lineNumber":231,"sourceCode":"    }\n\n    #[cfg_attr(feature = \"tracing\", tracing::instrument(level = \"trace\"))]\n    pub fn clear_children(parent: &Element) {\n        parent.set_text_content(Some(\"\"));\n    }\n\n    /// Mounts the new child before the marker as its sibling.\n    ///\n    /// ## Panics\n    /// The default implementation panics if `before` does not have a parent [`crate::renderer::types::Element`].\n    pub fn mount_before<M>(new_child: &mut M, before: &Node)\n    where\n        M: Mountable,\n    {\n        let parent = Element::cast_from(\n            Self::get_parent(before).expect(\"could not find parent element\"),\n        )\n        .expect(\"placeholder parent should be Element\");\n        new_child.mount(&parent, Some(before));\n    }\n\n    /// Tries to mount the new child before the marker as its sibling.\n    ///\n    /// Returns `false` if the child did not have a valid parent.\n    #[track_caller]\n    pub fn try_mount_before<M>(new_child: &mut M, before: &Node) -> bool\n    where\n        M: Mountable,\n    {\n        if let Some(parent) =\n            Self::get_parent(before).and_then(Element::cast_from)\n        {\n            new_child.mount(&parent, Some(before));\n            true\n        } else {\n            false","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/tachys/src/renderer/dom.rs#L213-L249","documentation":"After finding the parent of the `before` node, mount_before casts it to the renderer's Element type; if the parent node is not an Element (e.g. a DocumentFragment, text node, or shadow root), the cast fails and it panics with 'placeholder parent should be Element'.","triggerScenarios":"mount_before called where the anchor's parent is a DocumentFragment (e.g. nodes mounted directly under a fragment), a comment/text container, or any non-element parent node returned by get_parent.","commonSituations":"Mounting views whose root is a fragment into custom containers; using the renderer API on detached fragments; template placeholders placed directly under fragment parents during view reconciliation.","solutions":["Mount relative to an anchor whose parent is a real Element (use an element container)","Add a wrapper element as parent instead of a raw fragment before mounting","Use mount/new APIs that insert into an element directly rather than before a fragment-anchored marker","If writing a custom renderer, override mount_before to handle non-element parents"],"exampleFix":"// before\nrenderer.mount_before(&mut view, &marker_under_fragment); // panics\n// after\nlet holder = document.create_element(\"div\");\nfragment_parent.append_child(&holder);\nview.mount(&holder, None);\n","handlingStrategy":"validation","validationCode":"fn parent_is_element(node: &web_sys::Node) -> bool {\n    node.parent_node()\n        .and_then(|p| p.dyn_into::<web_sys::Element>().ok())\n        .is_some()\n}","typeGuard":"fn parent_as_element(node: &web_sys::Node) -> Option<web_sys::Element> {\n    node.parent_node()?.dyn_into::<web_sys::Element>().ok()\n}","tryCatchPattern":null,"preventionTips":["Mount relative to anchors whose parent is a real element, not a fragment","Insert a wrapper <div> between fragments and mounted children","Use direct-into-element mount APIs when the parent is known","Handle fragment-rooted views by appending instead of insert-before"],"tags":["dom","mounting","panic"],"backgroundTag":"dom-parent-not-element","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}