fix: debug-mode bugs in <For/> (closes #955, #1075, #1076) (#1078)

This commit is contained in:
Greg Johnston 2023-05-22 06:49:13 -04:00 committed by GitHub
parent 91e0fcdc1b
commit 2d418dae93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -168,7 +168,7 @@ pub(crate) struct EachItem {
#[cfg(all(target_arch = "wasm32", feature = "web"))]
document_fragment: Option<web_sys::DocumentFragment>,
#[cfg(debug_assertions)]
opening: Comment,
opening: Option<Comment>,
pub(crate) child: View,
closing: Option<Comment>,
#[cfg(not(all(target_arch = "wasm32", feature = "web")))]
@ -201,7 +201,11 @@ impl EachItem {
None
},
#[cfg(debug_assertions)]
Comment::new(Cow::Borrowed("<EachItem>"), &id, false),
if needs_closing {
Some(Comment::new(Cow::Borrowed("<EachItem>"), &id, false))
} else {
None
},
);
#[cfg(all(target_arch = "wasm32", feature = "web"))]
@ -215,7 +219,10 @@ impl EachItem {
if !HydrationCtx::is_hydrating() {
#[cfg(debug_assertions)]
fragment
.append_with_node_2(&markers.1.node, &closing.node)
.append_with_node_2(
&markers.1.as_ref().unwrap().node,
&closing.node,
)
.unwrap();
fragment.append_with_node_1(&closing.node).unwrap();
}
@ -260,10 +267,6 @@ impl Mountable for EachItem {
#[inline(always)]
fn get_opening_node(&self) -> web_sys::Node {
#[cfg(debug_assertions)]
return self.opening.node.clone();
#[cfg(not(debug_assertions))]
return self.child.get_opening_node();
}
@ -673,10 +676,20 @@ fn apply_cmds<T, EF, N>(
// 4. Add
if cmds.clear {
cmds.removed.clear();
crate::log!("clearing list");
web_sys::console::log_2(
&wasm_bindgen::JsValue::from_str("open"),
opening,
);
web_sys::console::log_2(
&wasm_bindgen::JsValue::from_str("closing"),
closing,
);
if opening.previous_sibling().is_none()
&& closing.next_sibling().is_none()
{
crate::log!("no siblings");
let parent = closing
.parent_node()
.expect("could not get closing node")
@ -689,6 +702,7 @@ fn apply_cmds<T, EF, N>(
#[cfg(not(debug_assertions))]
parent.append_with_node_1(closing).unwrap();
} else {
crate::log!("yes siblings");
range.set_start_before(opening).unwrap();
range.set_end_before(closing).unwrap();