diff --git a/leptos_dom/src/operations.rs b/leptos_dom/src/operations.rs index 0f55f30ed..e9ec72cbd 100644 --- a/leptos_dom/src/operations.rs +++ b/leptos_dom/src/operations.rs @@ -75,17 +75,13 @@ pub fn insert_before( debug_warn!("insert_before: trying to insert on a parent node that is not an element"); new.clone() } else if let Some(existing) = existing { - if existing.parent_node().as_ref() == Some(parent.unchecked_ref()) { - match parent.insert_before(new, Some(existing)) { - Ok(c) => c, - Err(e) => { - debug_warn!("{:?}", e.as_string()); - new.clone() - } + let parent = existing.parent_node().unwrap_throw(); + match parent.insert_before(new, Some(existing)) { + Ok(c) => c, + Err(e) => { + debug_warn!("{:?}", e.as_string()); + new.clone() } - } else { - debug_warn!("insert_before: existing node is not a child of parent node"); - parent.append_child(new).unwrap_throw() } } else { parent.append_child(new).unwrap_throw() diff --git a/leptos_dom/src/render.rs b/leptos_dom/src/render.rs index d4e287a2a..16f5cda2c 100644 --- a/leptos_dom/src/render.rs +++ b/leptos_dom/src/render.rs @@ -233,11 +233,7 @@ pub fn insert_expression( } Child::Null => match before { Marker::BeforeChild(before) => { - if before.is_connected() { - Child::Node(insert_before(&parent, node, Some(before))) - } else { - Child::Node(append_child(&parent, node)) - } + Child::Node(insert_before(&parent, node, Some(before))) } _ => Child::Node(append_child(&parent, node)), }, diff --git a/leptos_macro/src/view.rs b/leptos_macro/src/view.rs index 0437fb258..f2ede523c 100644 --- a/leptos_macro/src/view.rs +++ b/leptos_macro/src/view.rs @@ -154,7 +154,7 @@ fn root_element_to_tokens( #[derive(Clone, Debug)] enum PrevSibChange { Sib(Ident), - //Parent, + Parent, Skip, } @@ -278,7 +278,7 @@ fn element_to_tokens( quote_spanned! { span => let #this_el_ident = #debug_name; let #this_el_ident = #parent.clone().unchecked_into::(); - //log::debug!("=> got {}", #this_el_ident.node_name()); + //debug!("=> got {}", #this_el_ident.node_name()); } } else if let Some(prev_sib) = &prev_sib { quote_spanned! { @@ -353,11 +353,12 @@ fn element_to_tokens( expressions, multi, mode, + idx == 0 ); prev_sib = match curr_id { PrevSibChange::Sib(id) => Some(id), - //PrevSibChange::Parent => None, + PrevSibChange::Parent => None, PrevSibChange::Skip => prev_sib, }; } @@ -604,6 +605,7 @@ fn child_to_tokens( expressions: &mut Vec, multi: bool, mode: Mode, + is_first_child: bool ) -> PrevSibChange { match node.node_type { NodeType::Element => { @@ -621,6 +623,7 @@ fn child_to_tokens( next_co_id, multi, mode, + is_first_child ) } else { PrevSibChange::Sib(element_to_tokens( @@ -777,6 +780,7 @@ fn component_to_tokens( next_co_id: &mut usize, multi: bool, mode: Mode, + is_first_child: bool ) -> PrevSibChange { let create_component = create_component(cx, node, mode); let span = node.name_span().unwrap(); @@ -864,7 +868,11 @@ fn component_to_tokens( match current { Some(el) => PrevSibChange::Sib(el), - None => PrevSibChange::Skip, + None => if is_first_child { + PrevSibChange::Parent + } else { + PrevSibChange::Skip + }, } }