Without a doubt, this is the stupidest and most frustrating bug I've ever created. Essentially, DOM nodes weren't being replaced or removed correctly because current was stuck on its origins in a DocumentFragment. It looked like some frustrating situation in which returns from appendChild were still referring back to the fragment, etc. No — I just literally wasn't ever using the return value, and instead was using the original value from the function call. Ridiculous, but so satisfying when it suddenly fixed a bunch of issues.

This commit is contained in:
Greg Johnston 2022-08-01 18:42:33 -04:00
parent 4357e3f92b
commit 5f2b92c267
2 changed files with 8 additions and 7 deletions

View file

@ -1,7 +1,5 @@
- [ ] Async
- [x] Resource
- [ ] Render bug: when doing e.g., a `match` and having multiple branches with separate `template`s, all exist as separate document fragment and replace the fragment, not one another -- find a way to make sure that `Child<'a>` returned from `insert` is _actually_ attached to the DOM
- [ ] Render bug with list reconciliation
- [ ] Suspense
- [ ] Docs (and clippy warning to insist on docs)
- [ ] Read through + understand...

View file

@ -98,15 +98,12 @@ pub fn insert<'a>(
value = f();
}
insert_expression(
current = Some(insert_expression(
parent.clone().unchecked_into(),
&f(),
current.clone().unwrap_or(Child::Null),
//current.get_untracked().clone(), // get untracked to avoid infinite loop when we set current, below
before.as_ref(),
);
current = Some(value);
));
});
}
_ => {
@ -132,6 +129,12 @@ pub fn insert_expression<'a>(
parent.node_name(),
current
);
if let Child::Node(node) = &current {
crate::log!(
"current's parent = {}",
node.parent_node().unwrap().node_name()
);
}
if new_value == &current {
current