Merge pull request #58 from gbj/fix-component-and-element-order

Fix the out-of-order component/element rendering in #53.
This commit is contained in:
Greg Johnston 2022-11-06 22:22:47 -05:00 committed by GitHub
commit 6b82a37dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -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()

View File

@ -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)),
},

View File

@ -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::<web_sys::Node>();
//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<TokenStream>,
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
},
}
}