Fix mount use after removal/Simplify mounts a bit (#2834)

* remove clone mounted; mounted nodes should never leak into components?

* Remove the mount from vnodes after unmounting them

* Fix use after removal in iterator diffing

* remove logs

* Re-fix keyed list diffing

* Use new.len for diffing keyed lens and remove redundant check

* simplify core list diffing logic a bit

* remove println

* add proper asserts for new tests

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-08-13 22:47:12 -07:00
1 parent 959ab67624
commit d649b0c54d
13 files changed
+310 -221

No files matched your search

+65
View File
@@ -47,3 +47,68 @@ fn toggle_option_text() {
]
);
}
// Regression test for https://github.com/DioxusLabs/dioxus/issues/2815
#[test]
fn toggle_template() {
fn app() -> Element {
rsx!(
Comp {
if true {
"{true}"
}
}
)
}
#[component]
fn Comp(children: Element) -> Element {
let show = generation() % 2 == 0;
rsx! {
if show {
{children}
}
}
}
let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations);
// Rendering again should replace the placeholder with an text node
dom.mark_dirty(ScopeId::APP);
assert_eq!(
dom.render_immediate_to_vec().edits,
[
CreatePlaceholder { id: ElementId(2) },
ReplaceWith { id: ElementId(1), m: 1 },
]
);
dom.mark_dirty(ScopeId(ScopeId::APP.0 + 1));
assert_eq!(
dom.render_immediate_to_vec().edits,
[
CreateTextNode { value: "true".to_string(), id: ElementId(1) },
ReplaceWith { id: ElementId(2), m: 1 },
]
);
dom.mark_dirty(ScopeId(ScopeId::APP.0 + 1));
assert_eq!(
dom.render_immediate_to_vec().edits,
[
CreatePlaceholder { id: ElementId(2) },
ReplaceWith { id: ElementId(1), m: 1 },
]
);
dom.mark_dirty(ScopeId(ScopeId::APP.0 + 1));
assert_eq!(
dom.render_immediate_to_vec().edits,
[
CreateTextNode { value: "true".to_string(), id: ElementId(1) },
ReplaceWith { id: ElementId(2), m: 1 },
]
);
}